<s> from oslo_config import cfg <EOL> from nova . tests . functional . api_sample_tests import api_sample_base <EOL> from nova . tests . unit . image import fake <EOL> CONF = cfg . CONF <EOL> CONF . import_opt ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class ServersSampleBase ( api_sample_base . ApiSampleTestBaseV21 ) : <EOL> extra_extensions_to_load = [ "<STR_LIT>" ] <EOL> microversion = None <EOL> def _post_server ( self , use_common_server_api_samples = True ) : <EOL> subs = { <EOL> '<STR_LIT>' : fake . get_valid_image_id ( ) , <EOL> '<STR_LIT:host>' : self . _get_host ( ) , <EOL> '<STR_LIT>' : self . _get_compute_endpoint ( ) , <EOL> '<STR_LIT>' : self . _get_vers_compute_endpoint ( ) , <EOL> '<STR_LIT>' : self . _get_glance_host ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> post_req_template = '<STR_LIT>' <EOL> post_resp_template = '<STR_LIT>' <EOL> if self . all_extensions and use_common_server_api_samples : <EOL> post_req_template = '<STR_LIT>' <EOL> post_resp_template = '<STR_LIT>' <EOL> orig_value = self . __class__ . _use_common_server_api_samples <EOL> orig_sample_dir = self . __class__ . sample_dir <EOL> try : <EOL> self . __class__ . _use_common_server_api_samples = ( <EOL> use_common_server_api_samples ) <EOL> response = self . _do_post ( '<STR_LIT>' , post_req_template , subs ) <EOL> status = self . _verify_response ( post_resp_template , subs , <EOL> response , <NUM_LIT> ) <EOL> return status <EOL> finally : <EOL> self . __class__ . _use_common_server_api_samples = orig_value <EOL> self . __class__ . sample_dir = orig_sample_dir <EOL> def setUp ( self ) : <EOL> super ( ServersSampleBase , self ) . setUp ( ) <EOL> self . api . microversion = self . microversion <EOL> class ServersSampleJsonTest ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> microversion = None <EOL> def _get_flags ( self ) : <EOL> f = super ( ServersSampleBase , self ) . _get_flags ( ) <EOL> f [ '<STR_LIT>' ] = CONF . osapi_compute_extension [ : ] <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' ) <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' ) <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f <EOL> def test_servers_post ( self ) : <EOL> return self . _post_server ( ) <EOL> def test_servers_get ( self ) : <EOL> uuid = self . test_servers_post ( ) <EOL> response = self . _do_get ( '<STR_LIT>' % uuid ) <EOL> subs = { } <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT:id>' ] = uuid <EOL> subs [ '<STR_LIT>' ] = r'<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> def test_servers_list ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> subs = { '<STR_LIT:id>' : uuid } <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> def test_servers_details ( self ) : <EOL> uuid = self . test_servers_post ( ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> subs = { } <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT:id>' ] = uuid <EOL> subs [ '<STR_LIT>' ] = r'<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> class ServersSampleJson29Test ( ServersSampleJsonTest ) : <EOL> microversion = '<STR_LIT>' <EOL> scenarios = [ ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) ] <EOL> class ServersSampleJson219Test ( ServersSampleJsonTest ) : <EOL> microversion = '<STR_LIT>' <EOL> sample_dir = '<STR_LIT>' <EOL> scenarios = [ ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) ] <EOL> def test_servers_post ( self ) : <EOL> return self . _post_server ( False ) <EOL> def test_servers_put ( self ) : <EOL> uuid = self . test_servers_post ( ) <EOL> response = self . _do_put ( '<STR_LIT>' % uuid , '<STR_LIT>' , { } ) <EOL> subs = { <EOL> '<STR_LIT>' : fake . get_valid_image_id ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . _get_glance_host ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> class ServersUpdateSampleJsonTest ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> all_extensions = True <EOL> def test_update_server ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> subs = { } <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> subs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response = self . _do_put ( '<STR_LIT>' % uuid , <EOL> '<STR_LIT>' , subs ) <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> class ServerSortKeysJsonTests ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> def _get_flags ( self ) : <EOL> f = super ( ServerSortKeysJsonTests , self ) . _get_flags ( ) <EOL> f [ '<STR_LIT>' ] = CONF . osapi_compute_extension [ : ] <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f <EOL> def test_servers_list ( self ) : <EOL> self . _post_server ( ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> self . _verify_response ( '<STR_LIT>' , { } , response , <EOL> <NUM_LIT:200> ) <EOL> class ServersSampleAllExtensionJsonTest ( ServersSampleJsonTest ) : <EOL> all_extensions = True <EOL> sample_dir = None <EOL> class ServersActionsJsonTest ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> def _test_server_action ( self , uuid , action , req_tpl , <EOL> subs = None , resp_tpl = None , code = <NUM_LIT> ) : <EOL> subs = subs or { } <EOL> subs . update ( { '<STR_LIT:action>' : action , <EOL> '<STR_LIT>' : self . _get_glance_host ( ) } ) <EOL> response = self . _do_post ( '<STR_LIT>' % uuid , <EOL> req_tpl , <EOL> subs ) <EOL> if resp_tpl : <EOL> self . _verify_response ( resp_tpl , subs , response , code ) <EOL> else : <EOL> self . assertEqual ( code , response . status_code ) <EOL> self . assertEqual ( "<STR_LIT>" , response . content ) <EOL> def test_server_reboot_hard ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> self . _test_server_action ( uuid , "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> { "<STR_LIT:type>" : "<STR_LIT>" } ) <EOL> def test_server_reboot_soft ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> self . _test_server_action ( uuid , "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> { "<STR_LIT:type>" : "<STR_LIT>" } ) <EOL> def test_server_rebuild ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> image = fake . get_valid_image_id ( ) <EOL> params = { <EOL> '<STR_LIT>' : image , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> resp = self . _do_post ( '<STR_LIT>' % uuid , <EOL> '<STR_LIT>' , params ) <EOL> subs = params . copy ( ) <EOL> del subs [ '<STR_LIT>' ] <EOL> self . _verify_response ( '<STR_LIT>' , subs , resp , <NUM_LIT> ) <EOL> def test_server_resize ( self ) : <EOL> self . flags ( allow_resize_to_same_host = True ) <EOL> uuid = self . _post_server ( ) <EOL> self . _test_server_action ( uuid , "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> { "<STR_LIT:id>" : '<STR_LIT:2>' , <EOL> "<STR_LIT:host>" : self . _get_host ( ) } ) <EOL> return uuid <EOL> def test_server_revert_resize ( self ) : <EOL> uuid = self . test_server_resize ( ) <EOL> self . _test_server_action ( uuid , "<STR_LIT>" , <EOL> '<STR_LIT>' ) <EOL> def test_server_confirm_resize ( self ) : <EOL> uuid = self . test_server_resize ( ) <EOL> self . _test_server_action ( uuid , "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> code = <NUM_LIT> ) <EOL> def test_server_create_image ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> self . _test_server_action ( uuid , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> class ServersActionsJson219Test ( ServersSampleBase ) : <EOL> microversion = '<STR_LIT>' <EOL> sample_dir = '<STR_LIT>' <EOL> scenarios = [ ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) ] <EOL> def test_server_rebuild ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> image = fake . get_valid_image_id ( ) <EOL> params = { <EOL> '<STR_LIT>' : image , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> resp = self . _do_post ( '<STR_LIT>' % uuid , <EOL> '<STR_LIT>' , params ) <EOL> subs = params . copy ( ) <EOL> del subs [ '<STR_LIT>' ] <EOL> self . _verify_response ( '<STR_LIT>' , subs , resp , <NUM_LIT> ) <EOL> class ServersActionsAllJsonTest ( ServersActionsJsonTest ) : <EOL> all_extensions = True <EOL> sample_dir = None <EOL> class ServerStartStopJsonTest ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> def _get_flags ( self ) : <EOL> f = super ( ServerStartStopJsonTest , self ) . _get_flags ( ) <EOL> f [ '<STR_LIT>' ] = CONF . osapi_compute_extension [ : ] <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f <EOL> def _test_server_action ( self , uuid , action , req_tpl ) : <EOL> response = self . _do_post ( '<STR_LIT>' % uuid , <EOL> req_tpl , <EOL> { '<STR_LIT:action>' : action } ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> self . assertEqual ( "<STR_LIT>" , response . content ) <EOL> def test_server_start ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> self . _test_server_action ( uuid , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _test_server_action ( uuid , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_server_stop ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> self . _test_server_action ( uuid , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ServersSampleMultiStatusJsonTest ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> extra_extensions_to_load = [ "<STR_LIT>" ] <EOL> def _get_flags ( self ) : <EOL> f = super ( ServersSampleMultiStatusJsonTest , self ) . _get_flags ( ) <EOL> f [ '<STR_LIT>' ] = CONF . osapi_compute_extension [ : ] <EOL> f [ '<STR_LIT>' ] . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f <EOL> def test_servers_list ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> response = self . _do_get ( '<STR_LIT>' ) <EOL> subs = { '<STR_LIT:id>' : uuid } <EOL> self . _verify_response ( '<STR_LIT>' , subs , response , <NUM_LIT:200> ) <EOL> class ServerTriggerCrashDumpJsonTest ( ServersSampleBase ) : <EOL> sample_dir = '<STR_LIT>' <EOL> microversion = '<STR_LIT>' <EOL> scenarios = [ ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) ] <EOL> def test_trigger_crash_dump ( self ) : <EOL> uuid = self . _post_server ( ) <EOL> response = self . _do_post ( '<STR_LIT>' % uuid , <EOL> '<STR_LIT>' , <EOL> { } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response . content , "<STR_LIT>" ) </s>
