Skip to content

Commit 3cce18c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "nova-manage: modify image properties in request_spec" into unmaintained/yoga
2 parents 371892d + e31c2a5 commit 3cce18c

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

nova/cmd/manage.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,9 +3266,10 @@ def _validate_image_properties(self, image_properties):
32663266
# Return the dict so we can update the instance system_metadata
32673267
return image_properties
32683268

3269-
def _update_image_properties(self, instance, image_properties):
3269+
def _update_image_properties(self, ctxt, instance, image_properties):
32703270
"""Update instance image properties
32713271
3272+
:param ctxt: nova.context.RequestContext
32723273
:param instance: The instance to update
32733274
:param image_properties: List of image properties and values to update
32743275
"""
@@ -3292,8 +3293,13 @@ def _update_image_properties(self, instance, image_properties):
32923293
for image_property, value in image_properties.items():
32933294
instance.system_metadata[f'image_{image_property}'] = value
32943295

3296+
request_spec = objects.RequestSpec.get_by_instance_uuid(
3297+
ctxt, instance.uuid)
3298+
request_spec.image = instance.image_meta
3299+
32953300
# Save and return 0
32963301
instance.save()
3302+
request_spec.save()
32973303
return 0
32983304

32993305
@action_description(_(
@@ -3328,7 +3334,7 @@ def set(self, instance_uuid=None, image_properties=None):
33283334
instance = objects.Instance.get_by_uuid(
33293335
cctxt, instance_uuid, expected_attrs=['system_metadata'])
33303336
return self._update_image_properties(
3331-
instance, image_properties)
3337+
ctxt, instance, image_properties)
33323338
except ValueError as e:
33333339
print(str(e))
33343340
return 6

nova/tests/unit/cmd/test_manage.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,6 +4052,8 @@ def test_show_image_properties_unknown_failure(
40524052
image_property='hw_disk_bus')
40534053
self.assertEqual(1, ret, 'return code')
40544054

4055+
@mock.patch('nova.objects.RequestSpec.save')
4056+
@mock.patch('nova.objects.RequestSpec.get_by_instance_uuid')
40554057
@mock.patch('nova.objects.Instance.get_by_uuid')
40564058
@mock.patch('nova.context.target_cell')
40574059
@mock.patch('nova.objects.Instance.save')
@@ -4060,7 +4062,8 @@ def test_show_image_properties_unknown_failure(
40604062
@mock.patch('nova.context.get_admin_context',
40614063
new=mock.Mock(return_value=mock.sentinel.ctxt))
40624064
def test_set_image_properties(
4063-
self, mock_instance_save, mock_target_cell, mock_get_instance
4065+
self, mock_instance_save, mock_target_cell, mock_get_instance,
4066+
mock_get_request_spec, mock_request_spec_save
40644067
):
40654068
mock_target_cell.return_value.__enter__.return_value = \
40664069
mock.sentinel.cctxt
@@ -4069,9 +4072,11 @@ def test_set_image_properties(
40694072
vm_state=obj_fields.InstanceState.STOPPED,
40704073
system_metadata={
40714074
'image_hw_disk_bus': 'virtio',
4072-
}
4075+
},
4076+
image_ref=''
40734077
)
40744078
mock_get_instance.return_value = instance
4079+
mock_get_request_spec.return_value = objects.RequestSpec()
40754080
ret = self.commands.set(
40764081
instance_uuid=uuidsentinel.instance,
40774082
image_properties=['hw_cdrom_bus=sata']
@@ -4088,7 +4093,12 @@ def test_set_image_properties(
40884093
instance.system_metadata.get('image_hw_disk_bus'),
40894094
'image_hw_disk_bus'
40904095
)
4096+
image_props = mock_get_request_spec.return_value.image.properties
4097+
self.assertEqual('sata', image_props.get('hw_cdrom_bus'))
4098+
self.assertEqual('virtio', image_props.get('hw_disk_bus'))
4099+
40914100
mock_instance_save.assert_called_once()
4101+
mock_request_spec_save.assert_called_once()
40924102

40934103
@mock.patch('nova.objects.Instance.get_by_uuid')
40944104
@mock.patch('nova.objects.InstanceMapping.get_by_instance_uuid',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
Before the `Bug 2078999 <https://bugs.launchpad.net/nova/+bug/2078999>`_ was fixed,
5+
the ``nova-manage image_property set`` command would update the image properties
6+
embedded in the instance but would not update the ones in the request specs. This
7+
led to an unexpected rollback of the image properties that were updated by the
8+
command after an instance migration.

0 commit comments

Comments
 (0)