Set user message on volume create failure

This patch is to log user message when volume creation fails.
This is only for _create_raw_volume, and other patches will be
submitted for _create_from_snapshot etc.

Change-Id: I9ba87863623a9c5806e93b69e1992cabce2f13b9
Partial-Bug: #1799159
This commit is contained in:
lixiaoy1 2018-10-23 01:09:04 +08:00
parent 7f7716d584
commit 67b2159f2f
3 changed files with 46 additions and 6 deletions

View File

@ -38,6 +38,8 @@ class Action(object):
COPY_IMAGE_TO_VOLUME = ('005', _('copy image to volume'))
UNMANAGE_VOLUME = ('006', _('unmanage volume'))
EXTEND_VOLUME = ('007', _('extend volume'))
CREATE_VOLUME_FROM_BACKEND = ('008',
_('create volume from backend storage'))
ALL = (SCHEDULE_ALLOCATE_VOLUME,
ATTACH_VOLUME,
@ -45,7 +47,8 @@ class Action(object):
UPDATE_ATTACHMENT,
COPY_IMAGE_TO_VOLUME,
UNMANAGE_VOLUME,
EXTEND_VOLUME
EXTEND_VOLUME,
CREATE_VOLUME_FROM_BACKEND
)
@ -79,6 +82,9 @@ class Detail(object):
SIGNATURE_VERIFICATION_FAILED = (
'011',
_("Image signature verification failed."))
DRIVER_FAILED_CREATE = (
'012',
_('Driver failed to create the volume.'))
ALL = (UNKNOWN_ERROR,
DRIVER_NOT_INITIALIZED,
@ -90,7 +96,8 @@ class Detail(object):
UNMANAGE_ENC_NOT_SUPPORTED,
NOTIFY_COMPUTE_SERVICE_FAILED,
DRIVER_FAILED_EXTEND,
SIGNATURE_VERIFICATION_FAILED)
SIGNATURE_VERIFICATION_FAILED,
DRIVER_FAILED_CREATE)
# Exception and detail mappings
EXCEPTION_DETAIL_MAPPINGS = {

View File

@ -1225,7 +1225,7 @@ class CreateVolumeFlowManagerTestCase(test.TestCase):
fake_driver.create_volume_from_backup.assert_called_once_with(
volume_obj, backup_obj)
if driver_error:
mock_create_volume.assert_called_once_with(volume_obj)
mock_create_volume.assert_called_once_with(self.ctxt, volume_obj)
mock_get_backup_host.assert_called_once_with(
backup_obj.host, backup_obj.availability_zone)
mock_restore_backup.assert_called_once_with(self.ctxt,
@ -1236,6 +1236,29 @@ class CreateVolumeFlowManagerTestCase(test.TestCase):
fake_driver.create_volume_from_backup.assert_called_once_with(
volume_obj, backup_obj)
@mock.patch('cinder.message.api.API.create')
def test_create_drive_error(self, mock_message_create):
fake_db = mock.MagicMock()
fake_driver = mock.MagicMock()
fake_volume_manager = mock.MagicMock()
fake_manager = create_volume_manager.CreateVolumeFromSpecTask(
fake_volume_manager, fake_db, fake_driver)
volume_obj = fake_volume.fake_volume_obj(self.ctxt)
err = NotImplementedError()
fake_driver.create_volume.side_effect = [err]
self.assertRaises(
NotImplementedError,
fake_manager._create_raw_volume,
self.ctxt,
volume_obj)
mock_message_create.assert_called_once_with(
self.ctxt,
message_field.Action.CREATE_VOLUME_FROM_BACKEND,
resource_uuid=volume_obj.id,
detail=message_field.Detail.DRIVER_FAILED_CREATE,
exception=err)
class CreateVolumeFlowManagerGlanceCinderBackendCase(test.TestCase):

View File

@ -971,7 +971,8 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
"at the backend and then schedule the request to the "
"backup service to restore the volume with backup.",
{'id': backup_id})
model_update = self._create_raw_volume(volume, **kwargs) or {}
model_update = self._create_raw_volume(
context, volume, **kwargs) or {}
volume.update(model_update)
volume.save()
@ -993,9 +994,17 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
'backup_id': backup_id})
return ret, need_update_volume
def _create_raw_volume(self, volume, **kwargs):
def _create_raw_volume(self, context, volume, **kwargs):
try:
ret = self.driver.create_volume(volume)
except Exception as ex:
with excutils.save_and_reraise_exception():
self.message.create(
context,
message_field.Action.CREATE_VOLUME_FROM_BACKEND,
resource_uuid=volume.id,
detail=message_field.Detail.DRIVER_FAILED_CREATE,
exception=ex)
finally:
self._cleanup_cg_in_volume(volume)
return ret
@ -1028,7 +1037,8 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
{'volume_spec': volume_spec, 'volume_id': volume_id,
'create_type': create_type})
if create_type == 'raw':
model_update = self._create_raw_volume(volume, **volume_spec)
model_update = self._create_raw_volume(
context, volume, **volume_spec)
elif create_type == 'snap':
model_update = self._create_from_snapshot(context, volume,
**volume_spec)