Add user message when share shrinking fails at the driver
Not all drivers support share shrinking. This patch adds a user message when shrinking fails due to operation not being supported. Change-Id: I5137cd972ec7737d70865038d7b82cfe13b9566c Closes-Bug: #1802424
This commit is contained in:
parent
82f01bd17f
commit
853d4fbceb
@ -94,6 +94,10 @@ class Detail(object):
|
||||
" smaller than the current used space. The share status has been"
|
||||
" set to available. Please select a size greater than the current"
|
||||
" used space."))
|
||||
DRIVER_FAILED_SHRINK = (
|
||||
'019',
|
||||
_("Share Driver does not support shrinking shares."
|
||||
" Shrinking share operation failed."))
|
||||
|
||||
ALL = (UNKNOWN_ERROR,
|
||||
NO_VALID_HOST,
|
||||
@ -112,7 +116,8 @@ class Detail(object):
|
||||
DRIVER_FAILED_EXTEND,
|
||||
FILTER_CREATE_FROM_SNAPSHOT,
|
||||
DRIVER_FAILED_CREATING_FROM_SNAP,
|
||||
DRIVER_REFUSED_SHRINK)
|
||||
DRIVER_REFUSED_SHRINK,
|
||||
DRIVER_FAILED_SHRINK)
|
||||
|
||||
# Exception and detail mappings
|
||||
EXCEPTION_DETAIL_MAPPINGS = {
|
||||
|
@ -3945,6 +3945,16 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
share_instance, "shrink.start")
|
||||
|
||||
def error_occurred(exc, msg, status=constants.STATUS_SHRINKING_ERROR):
|
||||
if isinstance(exc, NotImplementedError):
|
||||
msg = _("Shrink share operation not supported.")
|
||||
status = constants.STATUS_AVAILABLE
|
||||
self.message_api.create(
|
||||
context,
|
||||
message_field.Action.SHRINK,
|
||||
share['project_id'],
|
||||
resource_type=message_field.Resource.SHARE,
|
||||
resource_id=share['id'],
|
||||
detail=message_field.Detail.DRIVER_FAILED_SHRINK)
|
||||
LOG.exception(msg, resource=share)
|
||||
self.db.share_update(context, share['id'], {'status': status})
|
||||
|
||||
|
@ -3681,6 +3681,52 @@ class ShareManagerTestCase(test.TestCase):
|
||||
(['INFO', 'share.extend.start'],
|
||||
['INFO', 'share.extend.end']))
|
||||
|
||||
def test_shrink_share_not_supported(self):
|
||||
share = db_utils.create_share(size=2)
|
||||
new_size = 1
|
||||
share_id = share['id']
|
||||
|
||||
self.mock_object(self.share_manager.db, 'share_get',
|
||||
mock.Mock(return_value=share))
|
||||
self.mock_object(self.share_manager, 'driver')
|
||||
self.mock_object(self.share_manager.db, 'share_update')
|
||||
|
||||
self.mock_object(quota.QUOTAS, 'reserve')
|
||||
self.mock_object(quota.QUOTAS, 'rollback')
|
||||
self.mock_object(self.share_manager.driver, 'shrink_share',
|
||||
mock.Mock(side_effect=NotImplementedError))
|
||||
|
||||
self.assertRaises(
|
||||
exception.ShareShrinkingError,
|
||||
self.share_manager.shrink_share, self.context, share_id, new_size)
|
||||
|
||||
self.share_manager.driver.shrink_share.assert_called_once_with(
|
||||
utils.IsAMatcher(models.ShareInstance),
|
||||
new_size, share_server=None
|
||||
)
|
||||
|
||||
self.share_manager.db.share_update.assert_called_once_with(
|
||||
mock.ANY, share_id, {'status': constants.STATUS_AVAILABLE}
|
||||
)
|
||||
|
||||
quota.QUOTAS.reserve.assert_called_once_with(
|
||||
mock.ANY, gigabytes=-1, project_id=share['project_id'],
|
||||
share_type_id=None, user_id=share['user_id'],
|
||||
)
|
||||
quota.QUOTAS.rollback.assert_called_once_with(
|
||||
mock.ANY, mock.ANY, project_id=share['project_id'],
|
||||
share_type_id=None, user_id=share['user_id'],
|
||||
)
|
||||
self.assertTrue(self.share_manager.db.share_get.called)
|
||||
|
||||
self.share_manager.message_api.create.assert_called_once_with(
|
||||
utils.IsAMatcher(context.RequestContext),
|
||||
message_field.Action.SHRINK,
|
||||
share['project_id'],
|
||||
resource_type=message_field.Resource.SHARE,
|
||||
resource_id=share_id,
|
||||
detail=message_field.Detail.DRIVER_FAILED_SHRINK)
|
||||
|
||||
@ddt.data((True, [{'id': 'fake'}]), (False, []))
|
||||
@ddt.unpack
|
||||
def test_shrink_share_quota_error(self, supports_replication,
|
||||
|
@ -0,0 +1,5 @@
|
||||
|
||||
fixes:
|
||||
- |
|
||||
Added a new user message when share shrinking fails due to operation not being
|
||||
supported by the driver.
|
Loading…
Reference in New Issue
Block a user