<s> import webob <EOL> from nova . api . openstack . compute import access_ips <EOL> from nova . api . openstack . compute import extension_info <EOL> from nova . api . openstack . compute . legacy_v2 import servers as servers_v20 <EOL> from nova . api . openstack . compute import servers as servers_v21 <EOL> from nova . api . openstack import extensions as extensions_v20 <EOL> from nova . api . openstack import wsgi <EOL> from nova . compute import api as compute_api <EOL> from nova import exception <EOL> from nova . objects import instance as instance_obj <EOL> from nova import test <EOL> from nova . tests . unit . api . openstack import fakes <EOL> from nova . tests . unit . image import fake <EOL> class AccessIPsExtTestV21 ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AccessIPsExtTestV21 , self ) . setUp ( ) <EOL> self . access_ips_ext = access_ips . AccessIPs ( None ) <EOL> def _test ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v4_key : '<STR_LIT>' , <EOL> access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def _test_with_ipv4_only ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def _test_with_ipv6_only ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def _test_without_ipv4_and_ipv6 ( self , func ) : <EOL> server_dict = { } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { } ) <EOL> def _test_with_ipv4_null ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v4_key : None } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : None } ) <EOL> def _test_with_ipv6_null ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v6_key : None } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : None } ) <EOL> def _test_with_ipv4_blank ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : None } ) <EOL> def _test_with_ipv6_blank ( self , func ) : <EOL> server_dict = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> create_kwargs = { } <EOL> func ( server_dict , create_kwargs ) <EOL> self . assertEqual ( create_kwargs , { '<STR_LIT>' : None } ) <EOL> def test_server_create ( self ) : <EOL> self . _test ( self . access_ips_ext . server_create ) <EOL> def test_server_create_with_ipv4_only ( self ) : <EOL> self . _test_with_ipv4_only ( self . access_ips_ext . server_create ) <EOL> def test_server_create_with_ipv6_only ( self ) : <EOL> self . _test_with_ipv6_only ( self . access_ips_ext . server_create ) <EOL> def test_server_create_without_ipv4_and_ipv6 ( self ) : <EOL> self . _test_without_ipv4_and_ipv6 ( self . access_ips_ext . server_create ) <EOL> def test_server_create_with_ipv4_null ( self ) : <EOL> self . _test_with_ipv4_null ( self . access_ips_ext . server_create ) <EOL> def test_server_create_with_ipv6_null ( self ) : <EOL> self . _test_with_ipv6_null ( self . access_ips_ext . server_create ) <EOL> def test_server_create_with_ipv4_blank ( self ) : <EOL> self . _test_with_ipv4_blank ( self . access_ips_ext . server_create ) <EOL> def test_server_create_with_ipv6_blank ( self ) : <EOL> self . _test_with_ipv6_blank ( self . access_ips_ext . server_create ) <EOL> def test_server_update ( self ) : <EOL> self . _test ( self . access_ips_ext . server_update ) <EOL> def test_server_update_with_ipv4_only ( self ) : <EOL> self . _test_with_ipv4_only ( self . access_ips_ext . server_update ) <EOL> def test_server_update_with_ipv6_only ( self ) : <EOL> self . _test_with_ipv6_only ( self . access_ips_ext . server_update ) <EOL> def test_server_update_without_ipv4_and_ipv6 ( self ) : <EOL> self . _test_without_ipv4_and_ipv6 ( self . access_ips_ext . server_update ) <EOL> def test_server_update_with_ipv4_null ( self ) : <EOL> self . _test_with_ipv4_null ( self . access_ips_ext . server_update ) <EOL> def test_server_update_with_ipv6_null ( self ) : <EOL> self . _test_with_ipv6_null ( self . access_ips_ext . server_update ) <EOL> def test_server_update_with_ipv4_blank ( self ) : <EOL> self . _test_with_ipv4_blank ( self . access_ips_ext . server_update ) <EOL> def test_server_update_with_ipv6_blank ( self ) : <EOL> self . _test_with_ipv6_blank ( self . access_ips_ext . server_update ) <EOL> def test_server_rebuild ( self ) : <EOL> self . _test ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_with_ipv4_only ( self ) : <EOL> self . _test_with_ipv4_only ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_with_ipv6_only ( self ) : <EOL> self . _test_with_ipv6_only ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_without_ipv4_and_ipv6 ( self ) : <EOL> self . _test_without_ipv4_and_ipv6 ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_with_ipv4_null ( self ) : <EOL> self . _test_with_ipv4_null ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_with_ipv6_null ( self ) : <EOL> self . _test_with_ipv6_null ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_with_ipv4_blank ( self ) : <EOL> self . _test_with_ipv4_blank ( self . access_ips_ext . server_rebuild ) <EOL> def test_server_rebuild_with_ipv6_blank ( self ) : <EOL> self . _test_with_ipv6_blank ( self . access_ips_ext . server_rebuild ) <EOL> class AccessIPsExtAPIValidationTestV21 ( test . TestCase ) : <EOL> validation_error = exception . ValidationError <EOL> def setUp ( self ) : <EOL> super ( AccessIPsExtAPIValidationTestV21 , self ) . setUp ( ) <EOL> def fake_save ( context , ** kwargs ) : <EOL> pass <EOL> def fake_rebuild ( * args , ** kwargs ) : <EOL> pass <EOL> self . _set_up_controller ( ) <EOL> fake . stub_out_image_service ( self ) <EOL> self . stub_out ( '<STR_LIT>' , <EOL> fakes . fake_instance_get ( ) ) <EOL> self . stubs . Set ( instance_obj . Instance , '<STR_LIT>' , fake_save ) <EOL> self . stubs . Set ( compute_api . API , '<STR_LIT>' , fake_rebuild ) <EOL> self . req = fakes . HTTPRequest . blank ( '<STR_LIT>' ) <EOL> def _set_up_controller ( self ) : <EOL> ext_info = extension_info . LoadedExtensionInfo ( ) <EOL> self . controller = servers_v21 . ServersController ( <EOL> extension_info = ext_info ) <EOL> def _verify_update_access_ip ( self , res_dict , params ) : <EOL> pass <EOL> def _test_create ( self , params ) : <EOL> body = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } <EOL> body [ '<STR_LIT>' ] . update ( params ) <EOL> res_dict = self . controller . create ( self . req , body = body ) . obj <EOL> return res_dict <EOL> def _test_update ( self , params ) : <EOL> body = { <EOL> '<STR_LIT>' : { <EOL> } , <EOL> } <EOL> body [ '<STR_LIT>' ] . update ( params ) <EOL> res_dict = self . controller . update ( self . req , fakes . FAKE_UUID , body = body ) <EOL> self . _verify_update_access_ip ( res_dict , params ) <EOL> def _test_rebuild ( self , params ) : <EOL> body = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } <EOL> body [ '<STR_LIT>' ] . update ( params ) <EOL> self . controller . _action_rebuild ( self . req , fakes . FAKE_UUID , body = body ) <EOL> def test_create_server_with_access_ipv4 ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . _test_create ( params ) <EOL> def test_create_server_with_access_ip_pass_disabled ( self ) : <EOL> self . flags ( enable_instance_password = False ) <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' , <EOL> access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> res = self . _test_create ( params ) <EOL> server = res [ '<STR_LIT>' ] <EOL> self . assertNotIn ( "<STR_LIT>" , server ) <EOL> def test_create_server_with_invalid_access_ipv4 ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . assertRaises ( self . validation_error , self . _test_create , params ) <EOL> def test_create_server_with_access_ipv6 ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . _test_create ( params ) <EOL> def test_create_server_with_invalid_access_ipv6 ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . assertRaises ( self . validation_error , self . _test_create , params ) <EOL> def test_update_server_with_access_ipv4 ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . _test_update ( params ) <EOL> def test_update_server_with_invalid_access_ipv4 ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . assertRaises ( self . validation_error , self . _test_update , params ) <EOL> def test_update_server_with_access_ipv6 ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . _test_update ( params ) <EOL> def test_update_server_with_invalid_access_ipv6 ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . assertRaises ( self . validation_error , self . _test_update , params ) <EOL> def test_rebuild_server_with_access_ipv4 ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . _test_rebuild ( params ) <EOL> def test_rebuild_server_with_invalid_access_ipv4 ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . assertRaises ( self . validation_error , self . _test_rebuild , <EOL> params ) <EOL> def test_rebuild_server_with_access_ipv6 ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . _test_rebuild ( params ) <EOL> def test_rebuild_server_with_invalid_access_ipv6 ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . assertRaises ( self . validation_error , self . _test_rebuild , <EOL> params ) <EOL> class AccessIPsExtAPIValidationTestV2 ( AccessIPsExtAPIValidationTestV21 ) : <EOL> validation_error = webob . exc . HTTPBadRequest <EOL> def _set_up_controller ( self ) : <EOL> self . ext_mgr = extensions_v20 . ExtensionManager ( ) <EOL> self . ext_mgr . extensions = { } <EOL> self . controller = servers_v20 . Controller ( self . ext_mgr ) <EOL> def _verify_update_access_ip ( self , res_dict , params ) : <EOL> for key , value in params . items ( ) : <EOL> value = value or '<STR_LIT>' <EOL> self . assertEqual ( res_dict [ '<STR_LIT>' ] [ key ] , value ) <EOL> def test_update_server_access_ipv4_none ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : None } <EOL> self . _test_update ( params ) <EOL> def test_update_server_access_ipv4_blank ( self ) : <EOL> params = { access_ips . AccessIPs . v4_key : '<STR_LIT>' } <EOL> self . _test_update ( params ) <EOL> def test_update_server_access_ipv6_none ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : None } <EOL> self . _test_update ( params ) <EOL> def test_update_server_access_ipv6_blank ( self ) : <EOL> params = { access_ips . AccessIPs . v6_key : '<STR_LIT>' } <EOL> self . _test_update ( params ) <EOL> class AccessIPsControllerTestV21 ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AccessIPsControllerTestV21 , self ) . setUp ( ) <EOL> self . controller = access_ips . AccessIPsController ( ) <EOL> def _test_with_access_ips ( self , func , kwargs = { '<STR_LIT:id>' : '<STR_LIT>' } ) : <EOL> req = wsgi . Request ( { '<STR_LIT>' : <EOL> fakes . FakeRequestContext ( '<STR_LIT>' , '<STR_LIT>' , <EOL> is_admin = True ) } ) <EOL> instance = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> req . cache_db_instance ( instance ) <EOL> resp_obj = wsgi . ResponseObject ( <EOL> { "<STR_LIT>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> func ( req , resp_obj , ** kwargs ) <EOL> self . assertEqual ( resp_obj . obj [ '<STR_LIT>' ] [ access_ips . AccessIPs . v4_key ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( resp_obj . obj [ '<STR_LIT>' ] [ access_ips . AccessIPs . v6_key ] , <EOL> '<STR_LIT>' ) <EOL> def _test_without_access_ips ( self , func , kwargs = { '<STR_LIT:id>' : '<STR_LIT>' } ) : <EOL> req = wsgi . Request ( { '<STR_LIT>' : <EOL> fakes . FakeRequestContext ( '<STR_LIT>' , '<STR_LIT>' , <EOL> is_admin = True ) } ) <EOL> instance = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> req . cache_db_instance ( instance ) <EOL> resp_obj = wsgi . ResponseObject ( <EOL> { "<STR_LIT>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> func ( req , resp_obj , ** kwargs ) <EOL> self . assertEqual ( resp_obj . obj [ '<STR_LIT>' ] [ access_ips . AccessIPs . v4_key ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( resp_obj . obj [ '<STR_LIT>' ] [ access_ips . AccessIPs . v6_key ] , <EOL> '<STR_LIT>' ) <EOL> def test_show ( self ) : <EOL> self . _test_with_access_ips ( self . controller . show ) <EOL> def test_show_without_access_ips ( self ) : <EOL> self . _test_without_access_ips ( self . controller . show ) <EOL> def test_detail ( self ) : <EOL> req = wsgi . Request ( { '<STR_LIT>' : <EOL> fakes . FakeRequestContext ( '<STR_LIT>' , '<STR_LIT>' , <EOL> is_admin = True ) } ) <EOL> instance1 = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> instance2 = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> req . cache_db_instance ( instance1 ) <EOL> req . cache_db_instance ( instance2 ) <EOL> resp_obj = wsgi . ResponseObject ( <EOL> { "<STR_LIT>" : [ { '<STR_LIT:id>' : '<STR_LIT>' } , { '<STR_LIT:id>' : '<STR_LIT>' } ] } ) <EOL> self . controller . detail ( req , resp_obj ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ access_ips . AccessIPs . v4_key ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ access_ips . AccessIPs . v6_key ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ access_ips . AccessIPs . v4_key ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ access_ips . AccessIPs . v6_key ] , <EOL> '<STR_LIT>' ) <EOL> def test_detail_without_access_ips ( self ) : <EOL> req = wsgi . Request ( { '<STR_LIT>' : <EOL> fakes . FakeRequestContext ( '<STR_LIT>' , '<STR_LIT>' , <EOL> is_admin = True ) } ) <EOL> instance1 = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> instance2 = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> req . cache_db_instance ( instance1 ) <EOL> req . cache_db_instance ( instance2 ) <EOL> resp_obj = wsgi . ResponseObject ( <EOL> { "<STR_LIT>" : [ { '<STR_LIT:id>' : '<STR_LIT>' } , { '<STR_LIT:id>' : '<STR_LIT>' } ] } ) <EOL> self . controller . detail ( req , resp_obj ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ access_ips . AccessIPs . v4_key ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ access_ips . AccessIPs . v6_key ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ access_ips . AccessIPs . v4_key ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> resp_obj . obj [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ access_ips . AccessIPs . v6_key ] , '<STR_LIT>' ) <EOL> def test_update ( self ) : <EOL> self . _test_with_access_ips ( self . controller . update , { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : { } } ) <EOL> def test_update_without_access_ips ( self ) : <EOL> self . _test_without_access_ips ( self . controller . update , { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : { } } ) <EOL> def test_rebuild ( self ) : <EOL> self . _test_with_access_ips ( self . controller . rebuild , { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : { } } ) <EOL> def test_rebuild_without_access_ips ( self ) : <EOL> self . _test_without_access_ips ( self . controller . rebuild , { '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : { } } ) </s>
