<s> from oslo_serialization import jsonutils <EOL> import six <EOL> import webob <EOL> from nova . api . openstack . compute . legacy_v2 . contrib import extended_ips_mac <EOL> from nova import compute <EOL> from nova import objects <EOL> from nova import test <EOL> from nova . tests . unit . api . openstack import fakes <EOL> UUID1 = '<STR_LIT>' <EOL> UUID2 = '<STR_LIT>' <EOL> UUID3 = '<STR_LIT>' <EOL> NW_CACHE = [ <EOL> { <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:address>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> ] , <EOL> } , <EOL> ] , <EOL> } , <EOL> ] <EOL> } <EOL> } , <EOL> { <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : <NUM_LIT:2> , <EOL> '<STR_LIT:label>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:address>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } , <EOL> ] , <EOL> } <EOL> ] , <EOL> } , <EOL> ] <EOL> } <EOL> } <EOL> ] <EOL> ALL_IPS = [ ] <EOL> for cache in NW_CACHE : <EOL> for subnet in cache [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> for fixed in subnet [ '<STR_LIT>' ] : <EOL> sanitized = dict ( fixed ) <EOL> sanitized [ '<STR_LIT>' ] = cache [ '<STR_LIT:address>' ] <EOL> sanitized . pop ( '<STR_LIT>' ) <EOL> sanitized . pop ( '<STR_LIT:type>' ) <EOL> ALL_IPS . append ( sanitized ) <EOL> for floating in fixed [ '<STR_LIT>' ] : <EOL> sanitized = dict ( floating ) <EOL> sanitized [ '<STR_LIT>' ] = cache [ '<STR_LIT:address>' ] <EOL> sanitized . pop ( '<STR_LIT:type>' ) <EOL> ALL_IPS . append ( sanitized ) <EOL> ALL_IPS . sort ( key = lambda x : '<STR_LIT>' % ( x [ '<STR_LIT:address>' ] , x [ '<STR_LIT>' ] ) ) <EOL> def fake_compute_get ( * args , ** kwargs ) : <EOL> inst = fakes . stub_instance_obj ( None , <NUM_LIT:1> , uuid = UUID3 , nw_cache = NW_CACHE ) <EOL> return inst <EOL> def fake_compute_get_all ( * args , ** kwargs ) : <EOL> inst_list = [ <EOL> fakes . stub_instance_obj ( None , <NUM_LIT:1> , uuid = UUID1 , nw_cache = NW_CACHE ) , <EOL> fakes . stub_instance_obj ( None , <NUM_LIT:2> , uuid = UUID2 , nw_cache = NW_CACHE ) , <EOL> ] <EOL> return objects . InstanceList ( objects = inst_list ) <EOL> class ExtendedIpsMacTestV21 ( test . TestCase ) : <EOL> content_type = '<STR_LIT:application/json>' <EOL> prefix = '<STR_LIT>' % extended_ips_mac . Extended_ips_mac . alias <EOL> def setUp ( self ) : <EOL> super ( ExtendedIpsMacTestV21 , self ) . setUp ( ) <EOL> fakes . stub_out_nw_api ( self ) <EOL> self . stubs . Set ( compute . api . API , '<STR_LIT>' , fake_compute_get ) <EOL> self . stubs . Set ( compute . api . API , '<STR_LIT>' , fake_compute_get_all ) <EOL> def _make_request ( self , url ) : <EOL> req = webob . Request . blank ( url ) <EOL> req . headers [ '<STR_LIT>' ] = self . content_type <EOL> res = req . get_response ( fakes . wsgi_app_v21 ( init_only = ( '<STR_LIT>' , ) ) ) <EOL> return res <EOL> def _get_server ( self , body ) : <EOL> return jsonutils . loads ( body ) . get ( '<STR_LIT>' ) <EOL> def _get_servers ( self , body ) : <EOL> return jsonutils . loads ( body ) . get ( '<STR_LIT>' ) <EOL> def _get_ips ( self , server ) : <EOL> for network in six . itervalues ( server [ '<STR_LIT>' ] ) : <EOL> for ip in network : <EOL> yield ip <EOL> def assertServerStates ( self , server ) : <EOL> results = [ ] <EOL> for ip in self . _get_ips ( server ) : <EOL> results . append ( { '<STR_LIT:address>' : ip . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ip . get ( '<STR_LIT>' % self . prefix ) } ) <EOL> self . assertEqual ( ALL_IPS , sorted ( results ) ) <EOL> def test_show ( self ) : <EOL> url = '<STR_LIT>' % UUID3 <EOL> res = self . _make_request ( url ) <EOL> self . assertEqual ( res . status_int , <NUM_LIT:200> ) <EOL> self . assertServerStates ( self . _get_server ( res . body ) ) <EOL> def test_detail ( self ) : <EOL> url = '<STR_LIT>' <EOL> res = self . _make_request ( url ) <EOL> self . assertEqual ( res . status_int , <NUM_LIT:200> ) <EOL> for _i , server in enumerate ( self . _get_servers ( res . body ) ) : <EOL> self . assertServerStates ( server ) <EOL> class ExtendedIpsMacTestV2 ( ExtendedIpsMacTestV21 ) : <EOL> content_type = '<STR_LIT:application/json>' <EOL> prefix = '<STR_LIT>' % extended_ips_mac . Extended_ips_mac . alias <EOL> def setUp ( self ) : <EOL> super ( ExtendedIpsMacTestV2 , self ) . setUp ( ) <EOL> self . flags ( <EOL> osapi_compute_extension = [ <EOL> '<STR_LIT>' ] , <EOL> osapi_compute_ext_list = [ '<STR_LIT>' ] ) <EOL> def _make_request ( self , url ) : <EOL> req = webob . Request . blank ( url ) <EOL> req . headers [ '<STR_LIT>' ] = self . content_type <EOL> res = req . get_response ( fakes . wsgi_app ( init_only = ( '<STR_LIT>' , ) ) ) <EOL> return res </s>
