diff --git a/nova/objects/image_meta.py b/nova/objects/image_meta.py index c07b358647..08ee0151fe 100644 --- a/nova/objects/image_meta.py +++ b/nova/objects/image_meta.py @@ -124,6 +124,14 @@ class ImageMeta(base.NovaObject): """ sysmeta = utils.instance_sys_meta(instance) image_meta = utils.get_image_from_system_metadata(sysmeta) + + # NOTE(lyarwood): Provide the id of the image in image_meta if it + # wasn't persisted in the system_metadata of the instance previously. + # This is only provided to allow users of image_meta to avoid the need + # to pass around references to instance.image_ref alongside image_meta. + if image_meta.get('id') is None and instance.image_ref: + image_meta['id'] = instance.image_ref + return cls.from_dict(image_meta) @classmethod diff --git a/nova/tests/unit/api/openstack/compute/test_server_actions.py b/nova/tests/unit/api/openstack/compute/test_server_actions.py index b32d2a9003..924d78234e 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_server_actions.py @@ -267,7 +267,7 @@ class ServerActionsControllerTestV21(test.TestCase): def _test_rebuild_preserve_ephemeral(self, value=None): return_server = fakes.fake_compute_get( project_id=fakes.FAKE_PROJECT_ID, - image_ref='2', + image_ref=uuids.image_ref, vm_state=vm_states.ACTIVE, host='fake_host') self.stub_out('nova.compute.api.API.get', return_server) @@ -302,7 +302,7 @@ class ServerActionsControllerTestV21(test.TestCase): def test_rebuild_accepted_minimum(self): return_server = fakes.fake_compute_get( project_id=fakes.FAKE_PROJECT_ID, - image_ref='2', + image_ref=uuids.image_ref, vm_state=vm_states.ACTIVE, host='fake_host') self.stub_out('nova.compute.api.API.get', return_server) self_href = 'http://localhost/v2/servers/%s' % FAKE_UUID @@ -316,7 +316,7 @@ class ServerActionsControllerTestV21(test.TestCase): robj = self.controller._action_rebuild(self.req, FAKE_UUID, body=body) body = robj.obj - self.assertEqual(body['server']['image']['id'], '2') + self.assertEqual(body['server']['image']['id'], uuids.image_ref) self.assertEqual(len(body['server']['adminPass']), CONF.password_length) @@ -361,7 +361,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_server = fakes.fake_compute_get( project_id=fakes.FAKE_PROJECT_ID, - image_ref='2', + image_ref=uuids.image_ref, vm_state=vm_states.ACTIVE, host='fake_host') self.stub_out('nova.compute.api.API.get', return_server) self_href = 'http://localhost/v2/servers/%s' % FAKE_UUID @@ -375,7 +375,7 @@ class ServerActionsControllerTestV21(test.TestCase): robj = self.controller._action_rebuild(self.req, FAKE_UUID, body=body) body = robj.obj - self.assertEqual(body['server']['image']['id'], '2') + self.assertEqual(body['server']['image']['id'], uuids.image_ref) self.assertNotIn("adminPass", body['server']) self.assertEqual(robj['location'], self_href) @@ -473,7 +473,7 @@ class ServerActionsControllerTestV21(test.TestCase): def test_rebuild_admin_pass(self): return_server = fakes.fake_compute_get( project_id=fakes.FAKE_PROJECT_ID, - image_ref='2', + image_ref=uuids.image_ref, vm_state=vm_states.ACTIVE, host='fake_host') self.stub_out('nova.compute.api.API.get', return_server) @@ -487,7 +487,7 @@ class ServerActionsControllerTestV21(test.TestCase): body = self.controller._action_rebuild(self.req, FAKE_UUID, body=body).obj - self.assertEqual(body['server']['image']['id'], '2') + self.assertEqual(body['server']['image']['id'], uuids.image_ref) self.assertEqual(body['server']['adminPass'], 'asdf') def test_rebuild_admin_pass_pass_disabled(self): @@ -497,7 +497,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_server = fakes.fake_compute_get( project_id=fakes.FAKE_PROJECT_ID, - image_ref='2', + image_ref=FAKE_UUID, vm_state=vm_states.ACTIVE, host='fake_host') self.stub_out('nova.compute.api.API.get', return_server) @@ -511,7 +511,7 @@ class ServerActionsControllerTestV21(test.TestCase): body = self.controller._action_rebuild(self.req, FAKE_UUID, body=body).obj - self.assertEqual(body['server']['image']['id'], '2') + self.assertEqual(body['server']['image']['id'], FAKE_UUID) self.assertNotIn('adminPass', body['server']) def test_rebuild_server_not_found(self): @@ -578,12 +578,20 @@ class ServerActionsControllerTestV21(test.TestCase): def return_image_meta(*args, **kwargs): image_meta_table = { - '2': {'id': uuids.image_id, 'status': 'active', - 'container_format': 'ari'}, - '155d900f-4e14-4e4c-a73d-069cbf4541e6': - {'id': uuids.image_id, 'status': 'active', - 'container_format': 'raw', - 'properties': {'kernel_id': 1, 'ramdisk_id': 2}}, + uuids.image_1_id: { + 'id': uuids.image_1_id, + 'status': 'active', + 'container_format': 'ari' + }, + uuids.image_2_id: { + 'id': uuids.image_2_id, + 'status': 'active', + 'container_format': 'raw', + 'properties': { + 'kernel_id': uuids.kernel_id, + 'ramdisk_id': uuids.ramdisk_id + } + }, } image_id = args[2] try: @@ -597,7 +605,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_image_meta) body = { "rebuild": { - "imageRef": "155d900f-4e14-4e4c-a73d-069cbf4541e6", + "imageRef": uuids.image_2_id, }, } self.assertRaises(webob.exc.HTTPBadRequest, diff --git a/nova/tests/unit/api/openstack/compute/test_servers.py b/nova/tests/unit/api/openstack/compute/test_servers.py index 7e90e2ff0e..ce3ec7eb67 100644 --- a/nova/tests/unit/api/openstack/compute/test_servers.py +++ b/nova/tests/unit/api/openstack/compute/test_servers.py @@ -410,7 +410,7 @@ class ServersControllerTest(ControllerTest): "status": status, "hostId": '', "image": { - "id": "10", + "id": FAKE_UUID, "links": [ { "rel": "bookmark", @@ -474,7 +474,8 @@ class ServersControllerTest(ControllerTest): } def test_get_server_by_id(self): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id uuid = FAKE_UUID @@ -499,7 +500,8 @@ class ServersControllerTest(ControllerTest): self.assertEqual(res_dict['server']['OS-EXT-AZ:availability_zone'], '') def test_get_server_with_active_status_by_id(self): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id res_dict = self.controller.show(self.request, FAKE_UUID) @@ -517,7 +519,8 @@ class ServersControllerTest(ControllerTest): 'numa_topology'], cell_down_support=False) def test_get_server_with_id_image_ref_by_id(self): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id res_dict = self.controller.show(self.request, FAKE_UUID) @@ -1710,12 +1713,12 @@ class ServersControllerTest(ControllerTest): ], } expected_image = { - "id": "10", + "id": FAKE_UUID, "links": [ { "rel": "bookmark", - "href": ('http://localhost/%s/images/10' % - self.project_id), + "href": ('http://localhost/%s/images/%s' % ( + self.project_id, FAKE_UUID)), }, ], } @@ -1838,7 +1841,8 @@ class ServersControllerTestV23(ServersControllerTest): return server_dict def test_show(self): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id res_dict = self.controller.show(self.request, FAKE_UUID) @@ -1880,7 +1884,8 @@ class ServersControllerTestV23(ServersControllerTest): req.environ['nova.context']) servers_list = self.controller.detail(req) - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id expected_server = self._get_server_data_dict(FAKE_UUID, image_bookmark, @@ -1941,7 +1946,8 @@ class ServersControllerTestV29(ServersControllerTest): return server_dict def _test_get_server_with_lock(self, locked_by): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id req = self.req(self.path_with_id % FAKE_UUID) project_id = req.environ['nova.context'].project_id @@ -2121,7 +2127,8 @@ class ServersControllerTestV216(ServersControllerTest): policy.set_rules(orig_rules) def test_show(self): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id res_dict = self.controller.show(self.request, FAKE_UUID) expected_server = self._get_server_data_dict(FAKE_UUID, @@ -2166,7 +2173,8 @@ class ServersControllerTestV216(ServersControllerTest): servers_list = self.controller.detail(req) self.assertEqual(2, len(servers_list['servers'])) - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id expected_server = self._get_server_data_dict(FAKE_UUID, image_bookmark, @@ -2237,7 +2245,8 @@ class ServersControllerTestV219(ServersControllerTest): return server_dict def _test_get_server_with_description(self, description): - image_bookmark = "http://localhost/%s/images/10" % self.project_id + image_bookmark = "http://localhost/%s/images/%s" % ( + self.project_id, FAKE_UUID) flavor_bookmark = "http://localhost/%s/flavors/2" % self.project_id req = self.req(self.path_with_id % FAKE_UUID) project_id = req.environ['nova.context'].project_id diff --git a/nova/tests/unit/api/openstack/fakes.py b/nova/tests/unit/api/openstack/fakes.py index 6c50bbff72..980247d471 100644 --- a/nova/tests/unit/api/openstack/fakes.py +++ b/nova/tests/unit/api/openstack/fakes.py @@ -428,7 +428,7 @@ def fake_compute_get_all(num_servers=5, **kwargs): def stub_instance(id=1, user_id=None, project_id=None, host=None, node=None, vm_state=None, task_state=None, - reservation_id="", uuid=FAKE_UUID, image_ref="10", + reservation_id="", uuid=FAKE_UUID, image_ref=FAKE_UUID, flavor_id="1", name=None, key_name='', access_ipv4=None, access_ipv6=None, progress=0, auto_disk_config=False, display_name=None, diff --git a/nova/tests/unit/compute/test_api.py b/nova/tests/unit/compute/test_api.py index 7f38b48d3a..1bfad6b395 100644 --- a/nova/tests/unit/compute/test_api.py +++ b/nova/tests/unit/compute/test_api.py @@ -69,7 +69,6 @@ from nova.volume import cinder CONF = nova.conf.CONF -FAKE_IMAGE_REF = 'fake-image-ref' NODENAME = 'fakenode1' SHELVED_IMAGE = 'fake-shelved-image' SHELVED_IMAGE_NOT_FOUND = 'fake-shelved-image-notfound' @@ -147,7 +146,7 @@ class _ComputeAPIUnitTestMixIn(object): instance.uuid = uuidutils.generate_uuid() instance.vm_state = vm_states.ACTIVE instance.task_state = None - instance.image_ref = FAKE_IMAGE_REF + instance.image_ref = uuids.image_ref instance.reservation_id = 'r-fakeres' instance.user_id = self.user_id instance.project_id = self.project_id @@ -3762,7 +3761,7 @@ class _ComputeAPIUnitTestMixIn(object): instance = fake_instance.fake_instance_obj( self.context, vm_state=vm_states.ACTIVE, cell_name='fake-cell', launched_at=timeutils.utcnow(), - system_metadata={}, image_ref='foo', + system_metadata={}, image_ref=uuids.image_ref, expected_attrs=['system_metadata']) image_id = self._setup_fake_image_with_invalid_arch() self.assertRaises(exception.InvalidArchitectureName, @@ -3793,7 +3792,7 @@ class _ComputeAPIUnitTestMixIn(object): instance = fake_instance.fake_instance_obj( self.context, vm_state=vm_states.ACTIVE, cell_name='fake-cell', launched_at=timeutils.utcnow(), - system_metadata={}, image_ref='foo', + system_metadata={}, image_ref=uuids.image_ref, expected_attrs=['system_metadata']) bdms = objects.BlockDeviceMappingList(objects=[ @@ -3807,8 +3806,8 @@ class _ComputeAPIUnitTestMixIn(object): get_flavor.return_value = test_flavor.fake_flavor flavor = instance.get_flavor() - image_href = 'foo' image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": { 'architecture': fields_obj.Architecture.X86_64}} @@ -3824,7 +3823,7 @@ class _ComputeAPIUnitTestMixIn(object): self.compute_api.rebuild, self.context, instance, - image_href, + uuids.image_ref, "new password") self.assertIsNone(instance.task_state) mock_get_bdms.assert_called_once_with(self.context, @@ -3854,12 +3853,12 @@ class _ComputeAPIUnitTestMixIn(object): vm_state=vm_states.ACTIVE, cell_name='fake-cell', launched_at=timeutils.utcnow(), system_metadata=orig_system_metadata, - image_ref='foo', + image_ref=uuids.image_ref, expected_attrs=['system_metadata']) get_flavor.return_value = test_flavor.fake_flavor flavor = instance.get_flavor() - image_href = 'foo' image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": { 'architecture': fields_obj.Architecture.X86_64}} @@ -3875,13 +3874,14 @@ class _ComputeAPIUnitTestMixIn(object): with mock.patch.object(self.compute_api.compute_task_api, 'rebuild_instance') as rebuild_instance: - self.compute_api.rebuild(self.context, instance, image_href, - admin_pass, files_to_inject) + self.compute_api.rebuild( + self.context, instance, uuids.image_ref, + admin_pass, files_to_inject) rebuild_instance.assert_called_once_with(self.context, instance=instance, new_pass=admin_pass, - injected_files=files_to_inject, image_ref=image_href, - orig_image_ref=image_href, + injected_files=files_to_inject, image_ref=uuids.image_ref, + orig_image_ref=uuids.image_ref, orig_sys_metadata=orig_system_metadata, bdms=bdms, preserve_ephemeral=False, host=instance.host, request_spec=fake_spec) @@ -3909,13 +3909,13 @@ class _ComputeAPIUnitTestMixIn(object): req_spec_get_by_inst_uuid, req_spec_save): orig_system_metadata = {} get_flavor.return_value = test_flavor.fake_flavor - orig_image_href = 'orig_image' orig_image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": {'architecture': fields_obj.Architecture.X86_64, 'vm_mode': 'hvm'}} - new_image_href = 'new_image' new_image = { + "id": uuids.new_image_ref, "min_ram": 10, "min_disk": 1, "properties": {'architecture': fields_obj.Architecture.X86_64, 'vm_mode': 'xen'}} @@ -3928,15 +3928,15 @@ class _ComputeAPIUnitTestMixIn(object): launched_at=timeutils.utcnow(), system_metadata=orig_system_metadata, expected_attrs=['system_metadata'], - image_ref=orig_image_href, + image_ref=uuids.image_ref, node='node', vm_mode=fields_obj.VMMode.HVM) flavor = instance.get_flavor() def get_image(context, image_href): - if image_href == new_image_href: + if image_href == uuids.new_image_ref: return (None, new_image) - if image_href == orig_image_href: + if image_href == uuids.image_ref: return (None, orig_image) _get_image.side_effect = get_image bdm_get_by_instance_uuid.return_value = bdms @@ -3946,13 +3946,15 @@ class _ComputeAPIUnitTestMixIn(object): with mock.patch.object(self.compute_api.compute_task_api, 'rebuild_instance') as rebuild_instance: - self.compute_api.rebuild(self.context, instance, new_image_href, - admin_pass, files_to_inject) + self.compute_api.rebuild( + self.context, instance, uuids.new_image_ref, admin_pass, + files_to_inject) rebuild_instance.assert_called_once_with(self.context, instance=instance, new_pass=admin_pass, - injected_files=files_to_inject, image_ref=new_image_href, - orig_image_ref=orig_image_href, + injected_files=files_to_inject, + image_ref=uuids.new_image_ref, + orig_image_ref=uuids.image_ref, orig_sys_metadata=orig_system_metadata, bdms=bdms, preserve_ephemeral=False, host=None, request_spec=fake_spec) @@ -3989,14 +3991,14 @@ class _ComputeAPIUnitTestMixIn(object): vm_state=vm_states.ACTIVE, cell_name='fake-cell', launched_at=timeutils.utcnow(), system_metadata=orig_system_metadata, - image_ref='foo', + image_ref=uuids.image_ref, expected_attrs=['system_metadata'], key_name=orig_key_name, key_data=orig_key_data) get_flavor.return_value = test_flavor.fake_flavor flavor = instance.get_flavor() - image_href = 'foo' image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": {'architecture': fields_obj.Architecture.X86_64, 'vm_mode': 'hvm'}} @@ -4014,13 +4016,13 @@ class _ComputeAPIUnitTestMixIn(object): mock_get_keypair.return_value = keypair with mock.patch.object(self.compute_api.compute_task_api, 'rebuild_instance') as rebuild_instance: - self.compute_api.rebuild(self.context, instance, image_href, + self.compute_api.rebuild(self.context, instance, uuids.image_ref, admin_pass, files_to_inject, key_name=keypair.name) rebuild_instance.assert_called_once_with(self.context, instance=instance, new_pass=admin_pass, - injected_files=files_to_inject, image_ref=image_href, - orig_image_ref=image_href, + injected_files=files_to_inject, image_ref=uuids.image_ref, + orig_image_ref=uuids.image_ref, orig_sys_metadata=orig_system_metadata, bdms=bdms, preserve_ephemeral=False, host=instance.host, request_spec=fake_spec) @@ -4050,13 +4052,13 @@ class _ComputeAPIUnitTestMixIn(object): instance = fake_instance.fake_instance_obj( self.context, vm_state=vm_states.ACTIVE, cell_name='fake-cell', launched_at=timeutils.utcnow(), - system_metadata=orig_system_metadata, image_ref='foo', + system_metadata=orig_system_metadata, image_ref=uuids.image_ref, expected_attrs=['system_metadata'], trusted_certs=orig_trusted_certs) get_flavor.return_value = test_flavor.fake_flavor flavor = instance.get_flavor() - image_href = 'foo' image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": {'architecture': fields_obj.Architecture.X86_64, 'vm_mode': 'hvm'}} @@ -4072,14 +4074,14 @@ class _ComputeAPIUnitTestMixIn(object): with mock.patch.object(self.compute_api.compute_task_api, 'rebuild_instance') as rebuild_instance: - self.compute_api.rebuild(self.context, instance, image_href, + self.compute_api.rebuild(self.context, instance, uuids.image_ref, admin_pass, files_to_inject, trusted_certs=new_trusted_certs) rebuild_instance.assert_called_once_with( self.context, instance=instance, new_pass=admin_pass, - injected_files=files_to_inject, image_ref=image_href, - orig_image_ref=image_href, + injected_files=files_to_inject, image_ref=uuids.image_ref, + orig_image_ref=uuids.image_ref, orig_sys_metadata=orig_system_metadata, bdms=bdms, preserve_ephemeral=False, host=instance.host, request_spec=fake_spec) @@ -4114,13 +4116,13 @@ class _ComputeAPIUnitTestMixIn(object): instance = fake_instance.fake_instance_obj( self.context, vm_state=vm_states.ACTIVE, cell_name='fake-cell', launched_at=timeutils.utcnow(), - system_metadata=orig_system_metadata, image_ref='foo', + system_metadata=orig_system_metadata, image_ref=uuids.image_ref, expected_attrs=['system_metadata'], trusted_certs=orig_trusted_certs) get_flavor.return_value = test_flavor.fake_flavor flavor = instance.get_flavor() - image_href = 'foo' image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": {'architecture': fields_obj.Architecture.X86_64, 'vm_mode': 'hvm'}} @@ -4136,14 +4138,14 @@ class _ComputeAPIUnitTestMixIn(object): with mock.patch.object(self.compute_api.compute_task_api, 'rebuild_instance') as rebuild_instance: - self.compute_api.rebuild(self.context, instance, image_href, - admin_pass, files_to_inject, - trusted_certs=new_trusted_certs) + self.compute_api.rebuild( + self.context, instance, uuids.image_ref, admin_pass, + files_to_inject, trusted_certs=new_trusted_certs) rebuild_instance.assert_called_once_with( self.context, instance=instance, new_pass=admin_pass, - injected_files=files_to_inject, image_ref=image_href, - orig_image_ref=image_href, + injected_files=files_to_inject, image_ref=uuids.image_ref, + orig_image_ref=uuids.image_ref, orig_sys_metadata=orig_system_metadata, bdms=bdms, preserve_ephemeral=False, host=instance.host, request_spec=fake_spec) @@ -4172,8 +4174,8 @@ class _ComputeAPIUnitTestMixIn(object): system_metadata=orig_system_metadata, image_ref=None, expected_attrs=['system_metadata'], trusted_certs=None) get_flavor.return_value = test_flavor.fake_flavor - image_href = 'foo' image = { + "id": uuids.image_ref, "min_ram": 10, "min_disk": 1, "properties": {'architecture': fields_obj.Architecture.X86_64, 'vm_mode': 'hvm'}} @@ -4186,7 +4188,7 @@ class _ComputeAPIUnitTestMixIn(object): self.assertRaises(exception.CertificateValidationFailed, self.compute_api.rebuild, self.context, instance, - image_href, admin_pass, files_to_inject, + uuids.image_ref, admin_pass, files_to_inject, trusted_certs=new_trusted_certs) _check_auto_disk_config.assert_called_once_with( diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 8ad1b920d4..d05ab8c714 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -8962,14 +8962,17 @@ class ComputeAPITestCase(BaseTestCase): sys_meta = {k: v for k, v in instance.system_metadata.items() if not k.startswith('instance_type')} self.assertEqual( - {'image_kernel_id': uuids.kernel_id, - 'image_min_disk': '1', - 'image_ramdisk_id': uuids.ramdisk_id, - 'image_something_else': 'meow', - 'preserved': 'preserve this!', - 'image_base_image_ref': image_ref, - 'boot_roles': ''}, - sys_meta) + { + 'image_kernel_id': uuids.kernel_id, + 'image_min_disk': '1', + 'image_ramdisk_id': uuids.ramdisk_id, + 'image_something_else': 'meow', + 'preserved': 'preserve this!', + 'image_base_image_ref': image_ref, + 'boot_roles': '' + }, + sys_meta + ) def test_rebuild(self): self._test_rebuild(vm_state=vm_states.ACTIVE) @@ -10534,7 +10537,7 @@ class ComputeAPITestCase(BaseTestCase): instance = objects.Instance( id=42, uuid=uuids.interface_failed_instance, - image_ref='foo', + image_ref=uuids.image_ref, system_metadata={}, flavor=new_type, host='fake-host') @@ -10598,7 +10601,7 @@ class ComputeAPITestCase(BaseTestCase): instance = objects.Instance( id=42, uuid=uuids.interface_failed_instance, - image_ref='foo', + image_ref=uuids.image_ref, system_metadata={}, flavor=new_type, host='fake-host', diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py index 1129a3a3bf..e9e67ae7b1 100644 --- a/nova/tests/unit/objects/test_instance.py +++ b/nova/tests/unit/objects/test_instance.py @@ -75,8 +75,10 @@ class _TestInstanceObject(object): db_inst['info_cache'] = dict(test_instance_info_cache.fake_info_cache, instance_uuid=db_inst['uuid']) + db_inst['image_ref'] = uuids.image_ref db_inst['system_metadata'] = { + 'image_id': uuids.image_id, 'image_name': 'os2-warp', 'image_min_ram': 100, 'image_hw_disk_bus': 'ide', @@ -962,12 +964,12 @@ class _TestInstanceObject(object): fake_inst = dict(self.fake_instance) mock_get.return_value = fake_inst - inst = instance.Instance.get_by_uuid(self.context, - fake_inst['uuid'], - expected_attrs=['image_meta']) + inst = instance.Instance.get_by_uuid( + self.context, fake_inst['uuid'], expected_attrs=['image_meta']) image_meta = inst.image_meta self.assertIsInstance(image_meta, objects.ImageMeta) + self.assertEqual(uuids.image_ref, image_meta.id) self.assertEqual(100, image_meta.min_ram) self.assertEqual('ide', image_meta.properties.hw_disk_bus) self.assertEqual('ne2k_pci', image_meta.properties.hw_vif_model) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 931154ad6f..9f5e7865db 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -14570,7 +14570,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, def test_spawn_without_image_meta(self): instance_ref = self.test_instance - instance_ref['image_ref'] = 1 + instance_ref['image_ref'] = uuids.image_ref instance = objects.Instance(**instance_ref) drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) @@ -14773,7 +14773,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, nodeDeviceLookupByName=fake_node_device_lookup_by_name) instance_ref = self.test_instance - instance_ref['image_ref'] = 'my_fake_image' + instance_ref['image_ref'] = uuids.image_ref instance = objects.Instance(**instance_ref) instance['pci_devices'] = objects.PciDeviceList( objects=[objects.PciDevice(address='0000:00:00.0')]) @@ -14809,7 +14809,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) instance_ref = self.test_instance - instance_ref['image_ref'] = 'my_fake_image' + instance_ref['image_ref'] = uuids.image_ref instance = objects.Instance(**instance_ref) instance.system_metadata = {} image_meta = objects.ImageMeta.from_dict(self.test_image_meta) @@ -14823,7 +14823,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, gotFiles = [] instance_ref = self.test_instance - instance_ref['image_ref'] = 1 + instance_ref['image_ref'] = uuids.image_ref instance = objects.Instance(**instance_ref) instance['os_type'] = os_type @@ -14854,12 +14854,12 @@ class LibvirtConnTestCase(test.NoDBTestCase, disk_info, image_meta) wantFiles = [ - {'filename': '356a192b7913b04c54574d18c28d46e6395428ab', + {'filename': imagecache.get_cache_fname(uuids.image_ref), 'size': 10 * units.Gi}, {'filename': filename, 'size': 20 * units.Gi}, ] - self.assertEqual(gotFiles, wantFiles) + self.assertEqual(wantFiles, gotFiles) def test_create_image_plain_os_type_blank(self): self._test_create_image_plain(os_type='', @@ -15149,7 +15149,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, block_device_info = { 'ephemerals': ephemerals} instance_ref = self.test_instance - instance_ref['image_ref'] = 1 + instance_ref['image_ref'] = uuids.image_ref instance = objects.Instance(**instance_ref) drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) image_meta = objects.ImageMeta.from_dict({'disk_format': 'raw'}) @@ -16158,7 +16158,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, @mock.patch.object(FakeVirtDomain, 'attachDeviceFlags') @mock.patch.object(FakeVirtDomain, 'ID', return_value=1) @mock.patch.object(utils, 'get_image_from_system_metadata', - return_value=None) + return_value={}) def test_attach_direct_passthrough_ports(self, mock_get_image_metadata, mock_ID, mock_attachDevice): instance = objects.Instance(**self.test_instance) @@ -16177,7 +16177,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, @mock.patch.object(FakeVirtDomain, 'attachDeviceFlags') @mock.patch.object(FakeVirtDomain, 'ID', return_value=1) @mock.patch.object(utils, 'get_image_from_system_metadata', - return_value=None) + return_value={}) def test_attach_direct_physical_passthrough_ports(self, mock_get_image_metadata, mock_ID, mock_attachDevice): instance = objects.Instance(**self.test_instance) @@ -16196,7 +16196,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, @mock.patch.object(FakeVirtDomain, 'attachDeviceFlags') @mock.patch.object(FakeVirtDomain, 'ID', return_value=1) @mock.patch.object(utils, 'get_image_from_system_metadata', - return_value=None) + return_value={}) def test_attach_direct_passthrough_ports_with_info_cache(self, mock_get_image_metadata, mock_ID, mock_attachDevice): instance = objects.Instance(**self.test_instance) @@ -18851,7 +18851,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) instance = objects.Instance(id=1, uuid=uuids.instance, - image_ref='my_fake_image') + image_ref=uuids.image_ref) with test.nested( mock.patch.object(drvr, '_create_domain_setup_lxc'), @@ -22588,8 +22588,8 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): # file, instance is back to nominal state: after unshelve, # instance.image_ref will match current backing file. self._test_qcow2_rebase_image_during_create( - image_ref='snapshot_id_of_shelved_instance', - base_image_ref='original_image_id', + image_ref=uuids.shelved_instance_snapshot_id, + base_image_ref=uuids.original_image_id, vm_state=vm_states.SHELVED_OFFLOADED, rebase_expected=True) @@ -22598,23 +22598,23 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): # will failed (HTTP 404). In that case qemu-img rebase will merge # backing file into disk, removing backing file dependency. self._test_qcow2_rebase_image_during_create( - image_ref='snapshot_id_of_shelved_instance', - base_image_ref='original_image_id', + image_ref=uuids.shelved_instance_snapshot_id, + base_image_ref=uuids.original_image_id, vm_state=vm_states.SHELVED_OFFLOADED, original_image_in_glance=False, rebase_expected=True) def test_cross_cell_resize_qcow2_rebase_image_during_create(self): self._test_qcow2_rebase_image_during_create( - image_ref='snapshot_id_of_resized_instance', - base_image_ref='original_image_id', + image_ref=uuids.resized_instance_snapshot_id, + base_image_ref=uuids.original_image_id, task_state=task_states.RESIZE_FINISH, rebase_expected=True) def test_cross_cell_resize_qcow2_rebase_image_during_create_notfound(self): self._test_qcow2_rebase_image_during_create( - image_ref='snapshot_id_of_resized_instance', - base_image_ref='original_image_id', + image_ref=uuids.resized_instance_snapshot_id, + base_image_ref=uuids.original_image_id, task_state=task_states.RESIZE_FINISH, original_image_in_glance=False, rebase_expected=True) @@ -22624,8 +22624,8 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin): # consequently, instance.image_ref remain the same and we must ensure # that no rebase is done. self._test_qcow2_rebase_image_during_create( - image_ref='original_image_id', - base_image_ref='original_image_id', + image_ref=uuids.original_image_id, + base_image_ref=uuids.original_image_id, task_state=task_states.RESIZE_FINISH, rebase_expected=False) @@ -26318,6 +26318,7 @@ class LibvirtVolumeSnapshotTestCase(test.NoDBTestCase): self.inst = {} self.inst['uuid'] = uuids.fake self.inst['id'] = '1' + self.inst['image_ref'] = '' # system_metadata is needed for objects.Instance.image_meta conversion self.inst['system_metadata'] = {} diff --git a/nova/tests/unit/virt/libvirt/test_machine_type_utils.py b/nova/tests/unit/virt/libvirt/test_machine_type_utils.py index 6ea68e64cc..42043ac495 100644 --- a/nova/tests/unit/virt/libvirt/test_machine_type_utils.py +++ b/nova/tests/unit/virt/libvirt/test_machine_type_utils.py @@ -36,7 +36,8 @@ class TestMachineTypeUtils(test.NoDBTestCase): uuid=uuidsentinel.instance, host='fake', node='fake', task_state=None, flavor=objects.Flavor(), project_id='fake-project', user_id='fake-user', - vm_state=vm_state, system_metadata={} + vm_state=vm_state, system_metadata={}, + image_ref=uuidsentinel.image_ref ) if mtype: instance.system_metadata = { diff --git a/nova/tests/unit/virt/libvirt/test_vif.py b/nova/tests/unit/virt/libvirt/test_vif.py index 1b4928dca5..579a0ed1c6 100644 --- a/nova/tests/unit/virt/libvirt/test_vif.py +++ b/nova/tests/unit/virt/libvirt/test_vif.py @@ -1054,6 +1054,7 @@ class LibvirtVifTestCase(test.NoDBTestCase): d1 = vif.LibvirtGenericVIFDriver() ins = objects.Instance( id=1, uuid='f0000000-0000-0000-0000-000000000001', + image_ref=uuids.image_ref, project_id=723, system_metadata={} ) d1.plug(ins, self.vif_tap) @@ -1065,6 +1066,7 @@ class LibvirtVifTestCase(test.NoDBTestCase): d2 = vif.LibvirtGenericVIFDriver() mq_ins = objects.Instance( id=1, uuid='f0000000-0000-0000-0000-000000000001', + image_ref=uuids.image_ref, project_id=723, system_metadata={ 'image_hw_vif_multiqueue_enabled': 'True' } @@ -1086,6 +1088,7 @@ class LibvirtVifTestCase(test.NoDBTestCase): d1 = vif.LibvirtGenericVIFDriver() ins = objects.Instance( id=1, uuid='f0000000-0000-0000-0000-000000000001', + image_ref=uuids.image_ref, project_id=723, system_metadata={ 'image_hw_vif_multiqueue_enabled': 'True' } @@ -1104,6 +1107,7 @@ class LibvirtVifTestCase(test.NoDBTestCase): d1 = vif.LibvirtGenericVIFDriver() ins = objects.Instance( id=1, uuid='f0000000-0000-0000-0000-000000000001', + image_ref=uuids.image_ref, project_id=723, system_metadata={ 'image_hw_vif_multiqueue_enabled': 'True', 'image_hw_vif_model': 'e1000', diff --git a/nova/tests/unit/virt/test_configdrive.py b/nova/tests/unit/virt/test_configdrive.py index b5946671f1..6481879d15 100644 --- a/nova/tests/unit/virt/test_configdrive.py +++ b/nova/tests/unit/virt/test_configdrive.py @@ -23,6 +23,7 @@ class ConfigDriveTestCase(test.NoDBTestCase): instance = objects.Instance( config_drive="yes", + image_ref='', system_metadata={ "image_img_config_drive": "mandatory", } @@ -34,6 +35,7 @@ class ConfigDriveTestCase(test.NoDBTestCase): self.flags(force_config_drive=False) instance = objects.Instance( + image_ref='', config_drive=None, system_metadata={ "image_img_config_drive": "mandatory", @@ -46,6 +48,7 @@ class ConfigDriveTestCase(test.NoDBTestCase): self.flags(force_config_drive=True) instance = objects.Instance( + image_ref='', config_drive=None, launched_at=None, system_metadata={ @@ -59,6 +62,7 @@ class ConfigDriveTestCase(test.NoDBTestCase): self.flags(force_config_drive=True) instance = objects.Instance( + image_ref='', config_drive=None, launched_at='2019-05-17T00:00:00.000000', system_metadata={ @@ -72,6 +76,7 @@ class ConfigDriveTestCase(test.NoDBTestCase): self.flags(force_config_drive=False) instance = objects.Instance( + image_ref='', config_drive=None, system_metadata={ "image_img_config_drive": "optional", diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index a73b7194c4..a1186d6cb5 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -1688,6 +1688,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase, hypervisor_os='esxi', config_drive=True) instance = objects.Instance(uuid=self.uuid, + image_ref='', config_drive=False, system_metadata={}, node=self.instance_node)