From 998a654d7e46cee94a7747c608ea3dd2465a613d Mon Sep 17 00:00:00 2001 From: Zhang Fan Date: Tue, 12 Apr 2022 16:33:07 +0800 Subject: [PATCH] Add REIMAGE_VOLUME message action message_field.Action.REIMAGE_VOLUME doesn't exist. This patch adds the REIMAGE_VOLUME. The content of message_field.Detail.NOTIFY_COMPUTE_SERVICE_FAILED is "Compute service failed to extend volume". This message should be "Compute service failed to reimage volume". This patch adds the new REIMAGE_VOLUME_FAILED detail parameter for this message. Closes-Bug: #1968170 Change-Id: I3e17c6a2a7f252a9d324a1fea616e22869e55702 --- cinder/compute/nova.py | 2 +- cinder/message/message_field.py | 6 ++ cinder/tests/unit/compute/test_nova.py | 56 +++++++++++++++++++ ...ed-in-reimage-volume-48d5b8008ec82ea6.yaml | 5 ++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-1968170-add-parameters-used-in-reimage-volume-48d5b8008ec82ea6.yaml diff --git a/cinder/compute/nova.py b/cinder/compute/nova.py index aff75d6c00a..17bf3da93fd 100644 --- a/cinder/compute/nova.py +++ b/cinder/compute/nova.py @@ -235,5 +235,5 @@ class API(base.Base): context, message_field.Action.REIMAGE_VOLUME, resource_uuid=volume_id, - detail=message_field.Detail.NOTIFY_COMPUTE_SERVICE_FAILED) + detail=message_field.Detail.REIMAGE_VOLUME_FAILED) return result diff --git a/cinder/message/message_field.py b/cinder/message/message_field.py index d12b63c6ef7..f6c1657f2fc 100644 --- a/cinder/message/message_field.py +++ b/cinder/message/message_field.py @@ -49,6 +49,7 @@ class Action(object): BACKUP_CREATE = ('013', _('create backup')) BACKUP_DELETE = ('014', _('delete backup')) BACKUP_RESTORE = ('015', _('restore backup')) + REIMAGE_VOLUME = ('016', _('reimage volume')) ALL = (SCHEDULE_ALLOCATE_VOLUME, ATTACH_VOLUME, @@ -65,6 +66,7 @@ class Action(object): BACKUP_CREATE, BACKUP_DELETE, BACKUP_RESTORE, + REIMAGE_VOLUME, ) @@ -125,6 +127,9 @@ class Detail(object): BACKUP_RESTORE_ERROR = ( '026', _("Backup driver failed to restore backup.")) VOLUME_INVALID_STATE = ('027', _("Volume status is invalid.")) + REIMAGE_VOLUME_FAILED = ( + '028', + _("Compute service failed to reimage volume.")) ALL = (UNKNOWN_ERROR, DRIVER_NOT_INITIALIZED, @@ -153,6 +158,7 @@ class Detail(object): BACKUP_DELETE_DRIVER_ERROR, BACKUP_RESTORE_ERROR, VOLUME_INVALID_STATE, + REIMAGE_VOLUME_FAILED, ) # Exception and detail mappings diff --git a/cinder/tests/unit/compute/test_nova.py b/cinder/tests/unit/compute/test_nova.py index 1b1b2062aae..cc76469943c 100644 --- a/cinder/tests/unit/compute/test_nova.py +++ b/cinder/tests/unit/compute/test_nova.py @@ -281,3 +281,59 @@ class NovaApiTestCase(test.TestCase): 'server_uuid': 'server-id-2', 'tag': 'volume_id'}, ]) + + def test_reimage_volume(self): + server_ids = ['server-id-1', 'server-id-2'] + with mock.patch.object(nova, 'novaclient') as mock_novaclient, \ + mock.patch.object(self.novaclient.server_external_events, + 'create') as mock_create_event: + mock_novaclient.return_value = self.novaclient + mock_create_event.return_value = [] + + result = self.api.reimage_volume(self.ctx, server_ids, 'volume_id') + self.assertTrue(result) + + mock_novaclient.assert_called_once_with(self.ctx, + privileged_user=True, + api_version='2.91') + mock_create_event.assert_called_once_with([ + {'name': 'volume-reimaged', + 'server_uuid': 'server-id-1', + 'tag': 'volume_id'}, + {'name': 'volume-reimaged', + 'server_uuid': 'server-id-2', + 'tag': 'volume_id'}, + ]) + + @ddt.data(nova_exceptions.NotFound, + Exception, + 'illegal_list', + [{'code': None}]) + @mock.patch('cinder.message.api.API.create') + def test_reimage_volume_failed(self, nova_result, mock_create): + server_ids = ['server-id-1', 'server-id-2'] + with mock.patch.object(nova, 'novaclient') as mock_novaclient, \ + mock.patch.object(self.novaclient.server_external_events, + 'create') as mock_create_event: + mock_novaclient.return_value = self.novaclient + mock_create_event.side_effect = [nova_result] + + result = self.api.reimage_volume(self.ctx, server_ids, 'volume_id') + self.assertFalse(result) + + mock_novaclient.assert_called_once_with(self.ctx, + privileged_user=True, + api_version='2.91') + mock_create.assert_called_once_with( + self.ctx, + message_field.Action.REIMAGE_VOLUME, + resource_uuid='volume_id', + detail=message_field.Detail.REIMAGE_VOLUME_FAILED) + mock_create_event.assert_called_once_with([ + {'name': 'volume-reimaged', + 'server_uuid': 'server-id-1', + 'tag': 'volume_id'}, + {'name': 'volume-reimaged', + 'server_uuid': 'server-id-2', + 'tag': 'volume_id'}, + ]) diff --git a/releasenotes/notes/bug-1968170-add-parameters-used-in-reimage-volume-48d5b8008ec82ea6.yaml b/releasenotes/notes/bug-1968170-add-parameters-used-in-reimage-volume-48d5b8008ec82ea6.yaml new file mode 100644 index 00000000000..fd28db42496 --- /dev/null +++ b/releasenotes/notes/bug-1968170-add-parameters-used-in-reimage-volume-48d5b8008ec82ea6.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + `Bug #1968170 `_: Fixed + the message created when nova fails to reimage the volume.