def test_image_metadata_post(self): # Get api sample to update metadata of an image metadata request. image_id = fake.get_valid_image_id() response = self._do_post( 'images/%s/metadata' % image_id, 'image-metadata-post-req', {}) self._verify_response('image-metadata-post-resp', {}, response, 200)
def test_image_meta_key_put(self): # Get api sample of image metadata key put request. image_id = fake.get_valid_image_id() key = "auto_disk_config" response = self._do_put('images/%s/metadata/%s' % (image_id, key), 'image-meta-key-put-req', {}) self._verify_response('image-meta-key-put-resp', {}, response, 200)
def test_image_meta_key_put(self): # Get api sample of image metadata key put request. image_id = fake.get_valid_image_id() key = "auto_disk_config" response = self._do_put('images/%s/metadata/%s' % (image_id, key), 'image-meta-key-put-req', {}) self._verify_response('image-meta-key-put-resp', {}, response, 200)
def _test_server_rebuild_preserve_ephemeral(self, value, resp_tpl=None): uuid = self._post_server() image = fake.get_valid_image_id() subs = {'host': self._get_host(), 'uuid': image, 'name': 'foobar', 'pass': '******', 'hostid': '[a-f0-9]+', 'preserve_ephemeral': str(value).lower(), 'action': 'rebuild', 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } old_rebuild = compute_api.API.rebuild def fake_rebuild(self_, context, instance, image_href, admin_password, files_to_inject=None, **kwargs): self.assertEqual(kwargs['preserve_ephemeral'], value) if resp_tpl: return old_rebuild(self_, context, instance, image_href, admin_password, files_to_inject=None, **kwargs) self.stub_out('compute.compute.api.API.rebuild', fake_rebuild) response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild-preserve-ephemeral', subs) if resp_tpl: del subs['uuid'] self._verify_response(resp_tpl, subs, response, 202) else: self.assertEqual(202, response.status_code)
def test_scheduler_hints_post(self): # Get api sample of scheduler hint post request. subs = {'image_id': fake.get_valid_image_id(), 'uuid': str(uuid.uuid4())} response = self._do_post('servers', 'scheduler-hints-post-req', subs) del subs['uuid'] self._verify_response('scheduler-hints-post-resp', subs, response, 202)
def test_servers_post(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fe80::' } self._servers_post(subs)
def test_cloud_pipe_create(self): # Get api samples of cloud pipe extension creation. self.flags(vpn_image_id=fake.get_valid_image_id()) subs = {'project_id': str(uuid_lib.uuid4().hex)} response = self._do_post('os-cloudpipe', 'cloud-pipe-create-req', subs) subs['image_id'] = CONF.vpn_image_id self._verify_response('cloud-pipe-create-resp', subs, response, 200) return subs
def test_servers_post(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fe80::' } self._servers_post(subs)
def test_cloud_pipe_create(self): # Get api samples of cloud pipe extension creation. self.flags(vpn_image_id=fake.get_valid_image_id()) subs = {'project_id': str(uuid_lib.uuid4().hex)} response = self._do_post('os-cloudpipe', 'cloud-pipe-create-req', subs) subs['image_id'] = CONF.vpn_image_id self._verify_response('cloud-pipe-create-resp', subs, response, 200) return subs
def test_multiple_create(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'min_count': "2", 'max_count': "3" } response = self._do_post('servers', 'multiple-create-post-req', subs) self._verify_response('multiple-create-post-resp', subs, response, 202)
def test_scheduler_hints_post(self): # Get api sample of scheduler hint post request. subs = { 'image_id': fake.get_valid_image_id(), 'uuid': str(uuid.uuid4()) } response = self._do_post('servers', 'scheduler-hints-post-req', subs) del subs['uuid'] self._verify_response('scheduler-hints-post-resp', subs, response, 202)
def test_servers_put(self): uuid = self.test_servers_post() response = self._do_put('servers/%s' % uuid, 'server-put-req', {}) subs = { 'image_id': fake.get_valid_image_id(), 'hostid': '[a-f0-9]+', 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } self._verify_response('server-put-resp', subs, response, 200)
def test_user_data_post(self): user_data_contents = '#!/bin/bash\n/bin/su\necho "I am in you!"\n' user_data = base64.b64encode(user_data_contents) subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'user_data': user_data } response = self._do_post('servers', 'userdata-post-req', subs) self._verify_response('userdata-post-resp', subs, response, 202)
def test_servers_put(self): uuid = self.test_servers_post() response = self._do_put('servers/%s' % uuid, 'server-put-req', {}) subs = { 'image_id': fake.get_valid_image_id(), 'hostid': '[a-f0-9]+', 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } self._verify_response('server-put-resp', subs, response, 200)
def test_user_data_post(self): user_data_contents = '#!/bin/bash\n/bin/su\necho "I am in you!"\n' user_data = base64.b64encode(user_data_contents) subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'user_data': user_data } response = self._do_post('servers', 'userdata-post-req', subs) self._verify_response('userdata-post-resp', subs, response, 202)
def test_servers_details(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fe80::' } uuid = self._servers_post(subs) response = self._do_get('servers/detail') subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid self._verify_response('servers-details-resp', subs, response, 200)
def test_servers_details(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fe80::' } uuid = self._servers_post(subs) response = self._do_get('servers/detail') subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid self._verify_response('servers-details-resp', subs, response, 200)
def test_rebuild_server(self): uuid = self._post_server(use_common_server_api_samples=False) subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), } response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild-req', subs) subs['hostid'] = '[a-f0-9]+' subs['access_ip_v4'] = '' subs['access_ip_v6'] = '' self._verify_response('server-action-rebuild-resp', subs, response, 202)
def test_rebuild_server(self): uuid = self._post_server(use_common_server_api_samples=False) subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), } response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild-req', subs) subs['hostid'] = '[a-f0-9]+' subs['access_ip_v4'] = '' subs['access_ip_v6'] = '' self._verify_response('server-action-rebuild-resp', subs, response, 202)
def test_servers_rebuild(self): subs = { 'image_id': fake.get_valid_image_id(), 'host': self._get_host(), 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } uuid = self._post_server(use_common_server_api_samples=False) response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild-req', subs) subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid self._verify_response('server-action-rebuild-resp', subs, response, 202)
def test_servers_rebuild(self): subs = { 'image_id': fake.get_valid_image_id(), 'host': self._get_host(), 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } uuid = self._post_server(use_common_server_api_samples=False) response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild-req', subs) subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid self._verify_response('server-action-rebuild-resp', subs, response, 202)
def test_servers_rebuild(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fe80::' } uuid = self._servers_post(subs) subs['access_ip_v4'] = "4.3.2.1" subs['access_ip_v6'] = '80fe::' response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild', subs) subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid self._verify_response('server-action-rebuild-resp', subs, response, 202)
def test_servers_rebuild(self): subs = { 'image_id': fake.get_valid_image_id(), 'compute_endpoint': self._get_compute_endpoint(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fe80::' } uuid = self._servers_post(subs) subs['access_ip_v4'] = "4.3.2.1" subs['access_ip_v6'] = '80fe::' response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild', subs) subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid self._verify_response('server-action-rebuild-resp', subs, response, 202)
def test_server_rebuild(self): uuid = self._post_server() image = fake.get_valid_image_id() params = { 'uuid': image, 'name': 'foobar', 'pass': '******', 'hostid': '[a-f0-9]+', 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::', } resp = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild', params) subs = params.copy() del subs['uuid'] self._verify_response('server-action-rebuild-resp', subs, resp, 202)
def test_server_rebuild(self): uuid = self._post_server() image = fake.get_valid_image_id() params = { 'uuid': image, 'name': 'foobar', 'pass': '******', 'hostid': '[a-f0-9]+', 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::', } resp = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild', params) subs = params.copy() del subs['uuid'] self._verify_response('server-action-rebuild-resp', subs, resp, 202)
def _test_server_rebuild_preserve_ephemeral(self, value, resp_tpl=None): uuid = self._post_server() image = fake.get_valid_image_id() subs = { 'host': self._get_host(), 'uuid': image, 'name': 'foobar', 'pass': '******', 'hostid': '[a-f0-9]+', 'preserve_ephemeral': str(value).lower(), 'action': 'rebuild', 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } old_rebuild = compute_api.API.rebuild def fake_rebuild(self_, context, instance, image_href, admin_password, files_to_inject=None, **kwargs): self.assertEqual(kwargs['preserve_ephemeral'], value) if resp_tpl: return old_rebuild(self_, context, instance, image_href, admin_password, files_to_inject=None, **kwargs) self.stub_out('compute.compute.api.API.rebuild', fake_rebuild) response = self._do_post('servers/%s/action' % uuid, 'server-action-rebuild-preserve-ephemeral', subs) if resp_tpl: del subs['uuid'] self._verify_response(resp_tpl, subs, response, 202) else: self.assertEqual(202, response.status_code)
def setUp(self): super(VMwareVolumeOpsTestCase, self).setUp() vmwareapi_fake.reset() stubs.set_stubs(self) self._session = driver.VMwareAPISession() self._context = context.RequestContext('fake_user', 'fake_project') self._volumeops = volumeops.VMwareVolumeOps(self._session) self._image_id = image_fake.get_valid_image_id() self._instance_values = { 'name': 'fake_name', 'uuid': uuidsentinel.foo, 'vcpus': 1, 'memory_mb': 512, 'image_ref': self._image_id, 'root_gb': 10, 'node': 'respool-1001(MyResPoolName)', 'expected_attrs': ['system_metadata'], } self._instance = fake_instance.fake_instance_obj(self._context, **self._instance_values)
def _post_server(self, use_common_server_api_samples=True): # param use_common_server_api_samples: Boolean to set whether tests use # common sample files for server post request and response. # Default is True which means _get_sample_path method will fetch the # common server sample files from 'servers' directory. # Set False if tests need to use extension specific sample files subs = { 'image_id': fake.get_valid_image_id(), 'host': self._get_host(), 'compute_endpoint': self._get_compute_endpoint(), 'versioned_compute_endpoint': self._get_vers_compute_endpoint(), 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } # TODO(gmann): Remove this hack once all tests using this common # _post_server method are enabled with all extension. # This is added to avoid all tests updates together. post_req_template = 'server-post-req' post_resp_template = 'server-post-resp' if self.all_extensions and use_common_server_api_samples: post_req_template = 'server-create-req' post_resp_template = 'server-create-resp' orig_value = self.__class__._use_common_server_api_samples orig_sample_dir = self.__class__.sample_dir try: self.__class__._use_common_server_api_samples = ( use_common_server_api_samples) response = self._do_post('servers', post_req_template, subs) status = self._verify_response(post_resp_template, subs, response, 202) return status finally: self.__class__._use_common_server_api_samples = orig_value self.__class__.sample_dir = orig_sample_dir
def _post_server(self, use_common_server_api_samples=True): # param use_common_server_api_samples: Boolean to set whether tests use # common sample files for server post request and response. # Default is True which means _get_sample_path method will fetch the # common server sample files from 'servers' directory. # Set False if tests need to use extension specific sample files subs = { 'image_id': fake.get_valid_image_id(), 'host': self._get_host(), 'compute_endpoint': self._get_compute_endpoint(), 'versioned_compute_endpoint': self._get_vers_compute_endpoint(), 'glance_host': self._get_glance_host(), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': '80fe::' } # TODO(gmann): Remove this hack once all tests using this common # _post_server method are enabled with all extension. # This is added to avoid all tests updates together. post_req_template = 'server-post-req' post_resp_template = 'server-post-resp' if self.all_extensions and use_common_server_api_samples: post_req_template = 'server-create-req' post_resp_template = 'server-create-resp' orig_value = self.__class__._use_common_server_api_samples orig_sample_dir = self.__class__.sample_dir try: self.__class__._use_common_server_api_samples = ( use_common_server_api_samples) response = self._do_post('servers', post_req_template, subs) status = self._verify_response(post_resp_template, subs, response, 202) return status finally: self.__class__._use_common_server_api_samples = orig_value self.__class__.sample_dir = orig_sample_dir
def test_image_meta_key_get(self): # Get api sample of an image metadata key request. image_id = fake.get_valid_image_id() key = "kernel_id" response = self._do_get('images/%s/metadata/%s' % (image_id, key)) self._verify_response('image-meta-key-get', {}, response, 200)
def test_image_get(self): # Get api sample of one single image details request. image_id = fake.get_valid_image_id() response = self._do_get('images/%s' % image_id) subs = {'image_id': image_id} self._verify_response('image-get-resp', subs, response, 200)
def test_image_metadata_get(self): # Get api sample of an image metadata request. image_id = fake.get_valid_image_id() response = self._do_get('images/%s/metadata' % image_id) subs = {'image_id': image_id} self._verify_response('image-metadata-get-resp', subs, response, 200)
def test_image_metadata_post(self): # Get api sample to update metadata of an image metadata request. image_id = fake.get_valid_image_id() response = self._do_post('images/%s/metadata' % image_id, 'image-metadata-post-req', {}) self._verify_response('image-metadata-post-resp', {}, response, 200)
def test_image_metadata_put(self): # Get api sample of image metadata put request. image_id = fake.get_valid_image_id() response = self._do_put('images/%s/metadata' % (image_id), 'image-metadata-put-req', {}) self._verify_response('image-metadata-put-resp', {}, response, 200)
def test_image_meta_key_get(self): # Get api sample of an image metadata key request. image_id = fake.get_valid_image_id() key = "kernel_id" response = self._do_get('images/%s/metadata/%s' % (image_id, key)) self._verify_response('image-meta-key-get', {}, response, 200)
def test_image_metadata_get(self): # Get api sample of an image metadata request. image_id = fake.get_valid_image_id() response = self._do_get('images/%s/metadata' % image_id) subs = {'image_id': image_id} self._verify_response('image-metadata-get-resp', subs, response, 200)
def test_image_get(self): # Get api sample of one single image details request. image_id = fake.get_valid_image_id() response = self._do_get('images/%s' % image_id) subs = {'image_id': image_id} self._verify_response('image-get-resp', subs, response, 200)
def test_image_metadata_put(self): # Get api sample of image metadata put request. image_id = fake.get_valid_image_id() response = self._do_put('images/%s/metadata' % (image_id), 'image-metadata-put-req', {}) self._verify_response('image-metadata-put-resp', {}, response, 200)