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
This commit is contained in:
Zhang Fan 2022-04-12 16:33:07 +08:00
parent 6d4a6aa978
commit 998a654d7e
4 changed files with 68 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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'},
])

View File

@ -0,0 +1,5 @@
---
fixes:
- |
`Bug #1968170 <https://bugs.launchpad.net/cinder/+bug/1968170>`_: Fixed
the message created when nova fails to reimage the volume.