<s> import errno <EOL> import platform <EOL> import socket <EOL> import sys <EOL> from oslo_config import cfg <EOL> from six . moves import range <EOL> from nova . compute import flavors <EOL> import nova . context <EOL> import nova . db <EOL> from nova import exception <EOL> from nova . image import glance <EOL> from nova . network import minidns <EOL> from nova . network import model as network_model <EOL> from nova import objects <EOL> import nova . utils <EOL> CONF = cfg . CONF <EOL> CONF . import_opt ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_test_admin_context ( ) : <EOL> return nova . context . get_admin_context ( ) <EOL> def get_test_image_object ( context , instance_ref ) : <EOL> if not context : <EOL> context = get_test_admin_context ( ) <EOL> image_ref = instance_ref [ '<STR_LIT>' ] <EOL> image_service , image_id = glance . get_remote_image_service ( context , <EOL> image_ref ) <EOL> return objects . ImageMeta . from_dict ( <EOL> image_service . show ( context , image_id ) ) <EOL> def get_test_flavor ( context = None , options = None ) : <EOL> options = options or { } <EOL> if not context : <EOL> context = get_test_admin_context ( ) <EOL> test_flavor = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> test_flavor . update ( options ) <EOL> try : <EOL> flavor_ref = nova . db . flavor_create ( context , test_flavor ) <EOL> except ( exception . FlavorExists , exception . FlavorIdExists ) : <EOL> flavor_ref = nova . db . flavor_get_by_name ( context , '<STR_LIT>' ) <EOL> return flavor_ref <EOL> def get_test_instance ( context = None , flavor = None , obj = False ) : <EOL> if not context : <EOL> context = get_test_admin_context ( ) <EOL> if not flavor : <EOL> flavor = get_test_flavor ( context ) <EOL> test_instance = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : flavor [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : context . user_id , <EOL> '<STR_LIT>' : context . project_id , <EOL> } <EOL> if obj : <EOL> instance = objects . Instance ( context , ** test_instance ) <EOL> instance . flavor = objects . Flavor . get_by_id ( context , flavor [ '<STR_LIT:id>' ] ) <EOL> instance . create ( ) <EOL> else : <EOL> flavors . save_flavor_info ( test_instance [ '<STR_LIT>' ] , flavor , '<STR_LIT>' ) <EOL> instance = nova . db . instance_create ( context , test_instance ) <EOL> return instance <EOL> def get_test_network_info ( count = <NUM_LIT:1> ) : <EOL> ipv6 = CONF . use_ipv6 <EOL> fake = '<STR_LIT>' <EOL> fake_ip = '<STR_LIT>' <EOL> fake_vlan = <NUM_LIT:100> <EOL> fake_bridge_interface = '<STR_LIT>' <EOL> def current ( ) : <EOL> subnet_4 = network_model . Subnet ( cidr = fake_ip , <EOL> dns = [ network_model . IP ( fake_ip ) , <EOL> network_model . IP ( fake_ip ) ] , <EOL> gateway = network_model . IP ( fake_ip ) , <EOL> ips = [ network_model . IP ( fake_ip ) , <EOL> network_model . IP ( fake_ip ) ] , <EOL> routes = None , <EOL> dhcp_server = fake_ip ) <EOL> subnet_6 = network_model . Subnet ( cidr = fake_ip , <EOL> gateway = network_model . IP ( fake_ip ) , <EOL> ips = [ network_model . IP ( fake_ip ) , <EOL> network_model . IP ( fake_ip ) , <EOL> network_model . IP ( fake_ip ) ] , <EOL> routes = None , <EOL> version = <NUM_LIT:6> ) <EOL> subnets = [ subnet_4 ] <EOL> if ipv6 : <EOL> subnets . append ( subnet_6 ) <EOL> network = network_model . Network ( id = None , <EOL> bridge = fake , <EOL> label = None , <EOL> subnets = subnets , <EOL> vlan = fake_vlan , <EOL> bridge_interface = fake_bridge_interface , <EOL> injected = False ) <EOL> vif = network_model . VIF ( id = '<STR_LIT>' , <EOL> address = fake , <EOL> network = network , <EOL> type = network_model . VIF_TYPE_BRIDGE , <EOL> devname = None , <EOL> ovs_interfaceid = None ) <EOL> return vif <EOL> return network_model . NetworkInfo ( [ current ( ) for x in range ( <NUM_LIT:0> , count ) ] ) <EOL> def is_osx ( ) : <EOL> return platform . mac_ver ( ) [ <NUM_LIT:0> ] != '<STR_LIT>' <EOL> def is_linux ( ) : <EOL> return platform . system ( ) == '<STR_LIT>' <EOL> def coreutils_readlink_available ( ) : <EOL> _out , err = nova . utils . trycmd ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:/>' ) <EOL> return err == '<STR_LIT>' <EOL> test_dns_managers = [ ] <EOL> def dns_manager ( ) : <EOL> global test_dns_managers <EOL> manager = minidns . MiniDNS ( ) <EOL> test_dns_managers . append ( manager ) <EOL> return manager <EOL> def cleanup_dns_managers ( ) : <EOL> global test_dns_managers <EOL> for manager in test_dns_managers : <EOL> manager . delete_dns_file ( ) <EOL> test_dns_managers = [ ] <EOL> def killer_xml_body ( ) : <EOL> return ( ( """<STR_LIT>""" ) % { <EOL> '<STR_LIT:a>' : '<STR_LIT:A>' * <NUM_LIT:10> , <EOL> '<STR_LIT:b>' : '<STR_LIT>' * <NUM_LIT:10> , <EOL> '<STR_LIT:c>' : '<STR_LIT>' * <NUM_LIT:10> , <EOL> '<STR_LIT:d>' : '<STR_LIT>' * <NUM_LIT> , <EOL> } ) . strip ( ) <EOL> def is_ipv6_supported ( ) : <EOL> has_ipv6_support = socket . has_ipv6 <EOL> try : <EOL> s = socket . socket ( socket . AF_INET6 , socket . SOCK_STREAM ) <EOL> s . close ( ) <EOL> except socket . error as e : <EOL> if e . errno == errno . EAFNOSUPPORT : <EOL> has_ipv6_support = False <EOL> else : <EOL> raise <EOL> if has_ipv6_support and sys . platform . startswith ( '<STR_LIT>' ) : <EOL> try : <EOL> with open ( '<STR_LIT>' ) as f : <EOL> if not f . read ( ) : <EOL> has_ipv6_support = False <EOL> except IOError : <EOL> has_ipv6_support = False <EOL> return has_ipv6_support <EOL> def get_api_version ( request ) : <EOL> if request . path [ <NUM_LIT:2> : <NUM_LIT:3> ] . isdigit ( ) : <EOL> return int ( request . path [ <NUM_LIT:2> : <NUM_LIT:3> ] ) </s>
