diff --git a/nova/compute/api.py b/nova/compute/api.py index 0cab6116b87c..797d19a06ac7 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -3495,6 +3495,8 @@ class API(base.Base): new_sys_metadata = utils.get_system_metadata_from_image( image, flavor) + new_sys_metadata.update({'image_base_image_ref': image_id}) + instance.system_metadata.update(new_sys_metadata) instance.save() return orig_sys_metadata @@ -4110,6 +4112,14 @@ class API(base.Base): hypervisor. """ instance.task_state = task_states.SHELVING + + # NOTE(aarents): Ensure image_base_image_ref is present as it will be + # needed during unshelve and instance rebuild done before Bug/1893618 + # Fix dropped it. + instance.system_metadata.update( + {'image_base_image_ref': instance.image_ref} + ) + instance.save(expected_task_state=[None]) self._record_action_start(context, instance, instance_actions.SHELVE) diff --git a/nova/tests/unit/api/openstack/compute/test_shelve.py b/nova/tests/unit/api/openstack/compute/test_shelve.py index 911e8f776cd8..40cb9ac62ee8 100644 --- a/nova/tests/unit/api/openstack/compute/test_shelve.py +++ b/nova/tests/unit/api/openstack/compute/test_shelve.py @@ -52,6 +52,7 @@ class ShelvePolicyTestV21(test.NoDBTestCase): self.req.environ['nova.context'], vm_state=vm_states.ACTIVE, task_state=None) instance.launched_at = instance.created_at + instance.system_metadata = {} get_instance_mock.return_value = instance mock_save.side_effect = exception.UnexpectedTaskStateError( instance_uuid=instance.uuid, expected=None, diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 1dcaa501c355..c12d83ca5500 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -9110,6 +9110,7 @@ class ComputeAPITestCase(BaseTestCase): 'image_ramdisk_id': uuids.ramdisk_id, 'image_something_else': 'meow', 'preserved': 'preserve this!', + 'image_base_image_ref': image_ref, 'boot_roles': ''}, sys_meta)