Skip to content

Commit 94f01f2

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "nova-manage: modify image properties in request_spec" into unmaintained/zed
2 parents 75497b0 + 44995b4 commit 94f01f2

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
@@ -3258,9 +3258,10 @@ def _validate_image_properties(self, image_properties):
32583258
# Return the dict so we can update the instance system_metadata
32593259
return image_properties
32603260

3261-
def _update_image_properties(self, instance, image_properties):
3261+
def _update_image_properties(self, ctxt, instance, image_properties):
32623262
"""Update instance image properties
32633263
3264+
:param ctxt: nova.context.RequestContext
32643265
:param instance: The instance to update
32653266
:param image_properties: List of image properties and values to update
32663267
"""
@@ -3284,8 +3285,13 @@ def _update_image_properties(self, instance, image_properties):
32843285
for image_property, value in image_properties.items():
32853286
instance.system_metadata[f'image_{image_property}'] = value
32863287

3288+
request_spec = objects.RequestSpec.get_by_instance_uuid(
3289+
ctxt, instance.uuid)
3290+
request_spec.image = instance.image_meta
3291+
32873292
# Save and return 0
32883293
instance.save()
3294+
request_spec.save()
32893295
return 0
32903296

32913297
@action_description(_(
@@ -3320,7 +3326,7 @@ def set(self, instance_uuid=None, image_properties=None):
33203326
instance = objects.Instance.get_by_uuid(
33213327
cctxt, instance_uuid, expected_attrs=['system_metadata'])
33223328
return self._update_image_properties(
3323-
instance, image_properties)
3329+
ctxt, instance, image_properties)
33243330
except ValueError as e:
33253331
print(str(e))
33263332
return 6

nova/tests/unit/cmd/test_manage.py

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

4103+
@mock.patch('nova.objects.RequestSpec.save')
4104+
@mock.patch('nova.objects.RequestSpec.get_by_instance_uuid')
41034105
@mock.patch('nova.objects.Instance.get_by_uuid')
41044106
@mock.patch('nova.context.target_cell')
41054107
@mock.patch('nova.objects.Instance.save')
@@ -4108,7 +4110,8 @@ def test_show_image_properties_unknown_failure(
41084110
@mock.patch('nova.context.get_admin_context',
41094111
new=mock.Mock(return_value=mock.sentinel.ctxt))
41104112
def test_set_image_properties(
4111-
self, mock_instance_save, mock_target_cell, mock_get_instance
4113+
self, mock_instance_save, mock_target_cell, mock_get_instance,
4114+
mock_get_request_spec, mock_request_spec_save
41124115
):
41134116
mock_target_cell.return_value.__enter__.return_value = \
41144117
mock.sentinel.cctxt
@@ -4117,9 +4120,11 @@ def test_set_image_properties(
41174120
vm_state=obj_fields.InstanceState.STOPPED,
41184121
system_metadata={
41194122
'image_hw_disk_bus': 'virtio',
4120-
}
4123+
},
4124+
image_ref=''
41214125
)
41224126
mock_get_instance.return_value = instance
4127+
mock_get_request_spec.return_value = objects.RequestSpec()
41234128
ret = self.commands.set(
41244129
instance_uuid=uuidsentinel.instance,
41254130
image_properties=['hw_cdrom_bus=sata']
@@ -4136,7 +4141,12 @@ def test_set_image_properties(
41364141
instance.system_metadata.get('image_hw_disk_bus'),
41374142
'image_hw_disk_bus'
41384143
)
4144+
image_props = mock_get_request_spec.return_value.image.properties
4145+
self.assertEqual('sata', image_props.get('hw_cdrom_bus'))
4146+
self.assertEqual('virtio', image_props.get('hw_disk_bus'))
4147+
41394148
mock_instance_save.assert_called_once()
4149+
mock_request_spec_save.assert_called_once()
41404150

41414151
@mock.patch('nova.objects.Instance.get_by_uuid')
41424152
@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)