Update share-manager behavior for shrink share operation
This patch updates the share-manager to handle with the "ShareShrinkingPossibleDataLoss" driver exception in an appropriate way by setting the status to "available", and sending to the user an error message warning that the shrink operation was not completed. Change-Id: Ie1e7fcbf116d3fd831e550aa70f02a3aa60291b8 Related-Bug: #1858328 Depends-On: Idf34a149e5a975d5fbced0ec78d102c5d90b87c6
This commit is contained in:
parent
9555e181f9
commit
7aeed39ba9
@ -32,6 +32,7 @@ class Action(object):
|
||||
REVERT_TO_SNAPSHOT = ('006', _('revert to snapshot'))
|
||||
DELETE = ('007', _('delete'))
|
||||
EXTEND = ('008', _('extend'))
|
||||
SHRINK = ('009', _('shrink'))
|
||||
ALL = (ALLOCATE_HOST,
|
||||
CREATE,
|
||||
DELETE_ACCESS_RULES,
|
||||
@ -39,7 +40,8 @@ class Action(object):
|
||||
UPDATE,
|
||||
REVERT_TO_SNAPSHOT,
|
||||
DELETE,
|
||||
EXTEND)
|
||||
EXTEND,
|
||||
SHRINK)
|
||||
|
||||
|
||||
class Detail(object):
|
||||
@ -86,6 +88,12 @@ class Detail(object):
|
||||
_("Share Driver has failed to create the share from snapshot. This "
|
||||
"operation can be re-attempted by creating a new share. Contact "
|
||||
"your administrator to determine the cause of this failure."))
|
||||
DRIVER_REFUSED_SHRINK = (
|
||||
'018',
|
||||
_("Share Driver refused to shrink the share. The size to be shrunk is"
|
||||
" smaller than the current used space. The share status has been"
|
||||
" set to available. Please select a size greater than the current"
|
||||
" used space."))
|
||||
|
||||
ALL = (UNKNOWN_ERROR,
|
||||
NO_VALID_HOST,
|
||||
@ -103,7 +111,8 @@ class Detail(object):
|
||||
FILTER_REPLICATION,
|
||||
DRIVER_FAILED_EXTEND,
|
||||
FILTER_CREATE_FROM_SNAPSHOT,
|
||||
DRIVER_FAILED_CREATING_FROM_SNAP)
|
||||
DRIVER_FAILED_CREATING_FROM_SNAP,
|
||||
DRIVER_REFUSED_SHRINK)
|
||||
|
||||
# Exception and detail mappings
|
||||
EXCEPTION_DETAIL_MAPPINGS = {
|
||||
|
@ -3985,8 +3985,15 @@ class ShareManager(manager.SchedulerDependentManager):
|
||||
except Exception as e:
|
||||
if isinstance(e, exception.ShareShrinkingPossibleDataLoss):
|
||||
msg = ("Shrink share failed due to possible data loss.")
|
||||
status = constants.STATUS_SHRINKING_POSSIBLE_DATA_LOSS_ERROR
|
||||
status = constants.STATUS_AVAILABLE
|
||||
error_params = {'msg': msg, 'status': status}
|
||||
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_REFUSED_SHRINK)
|
||||
else:
|
||||
error_params = {'msg': ("Shrink share failed.")}
|
||||
|
||||
|
@ -3717,10 +3717,10 @@ class ShareManagerTestCase(test.TestCase):
|
||||
(self.share_manager.db.share_replicas_get_all_by_share
|
||||
.assert_called_once_with(mock.ANY, share['id']))
|
||||
|
||||
@ddt.data({'exc': exception.InvalidShare('fake'),
|
||||
@ddt.data({'exc': exception.InvalidShare("fake"),
|
||||
'status': constants.STATUS_SHRINKING_ERROR},
|
||||
{'exc': exception.ShareShrinkingPossibleDataLoss("fake"),
|
||||
'status': constants.STATUS_SHRINKING_POSSIBLE_DATA_LOSS_ERROR})
|
||||
'status': constants.STATUS_AVAILABLE})
|
||||
@ddt.unpack
|
||||
def test_shrink_share_invalid(self, exc, status):
|
||||
share = db_utils.create_share()
|
||||
@ -3758,6 +3758,15 @@ class ShareManagerTestCase(test.TestCase):
|
||||
)
|
||||
self.assertTrue(self.share_manager.db.share_get.called)
|
||||
|
||||
if isinstance(exc, exception.ShareShrinkingPossibleDataLoss):
|
||||
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_REFUSED_SHRINK)
|
||||
|
||||
@ddt.data(True, False)
|
||||
def test_shrink_share(self, supports_replication):
|
||||
share = db_utils.create_share()
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
When attempting to shrink a share to a size smaller than the current used
|
||||
space, the share status will remain as ``available`` instead of
|
||||
``shrinking_possible_data_loss_error``. The user will receive warning
|
||||
message saying that the shrink operation was not completed.
|
Loading…
Reference in New Issue
Block a user