Skip to content

Commit

Permalink
Update image_base_image_ref during rebuild.
Browse files Browse the repository at this point in the history
In different location we assume system_metadata.image_base_image_ref
exists, because it is set during instance creation in method
_populate_instance_for_create

But once instance is rebuild, all system_metadata image property a dropped
and replace by new image property and without setting back
image_base_image_ref.

This change propose to set image_base_image_ref during rebuild.

In specific case of shelve/unshelve in Qcow2 backend, image_base_image_ref is
used to rebase disk image, so we ensure this property is set as instance may
have been rebuild before the fix was apply.

Related-Bug: #1732428
Closes-Bug: #1893618
Change-Id: Ia3031ea1f7db8b398f02d2080ca603ded8970200
  • Loading branch information
Alexandre Arents committed Sep 1, 2020
1 parent b5d4804 commit fe52b6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3534,6 +3534,8 @@ def _reset_image_metadata():
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
Expand Down Expand Up @@ -4170,6 +4172,14 @@ def shelve(self, context, instance, clean_shutdown=True):
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)
Expand Down
1 change: 1 addition & 0 deletions nova/tests/unit/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9045,6 +9045,7 @@ def fake_rpc_rebuild(context, **kwargs):
'image_ramdisk_id': uuids.ramdisk_id,
'image_something_else': 'meow',
'preserved': 'preserve this!',
'image_base_image_ref': image_ref,
'boot_roles': ''},
sys_meta)

Expand Down

0 comments on commit fe52b6c

Please sign in to comment.