diff --git a/manila/message/message_field.py b/manila/message/message_field.py index 9d96e81274..85f9ac5378 100644 --- a/manila/message/message_field.py +++ b/manila/message/message_field.py @@ -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 = { diff --git a/manila/share/manager.py b/manila/share/manager.py index 34a4705a05..e97a1c72ae 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -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.")} diff --git a/manila/tests/share/test_manager.py b/manila/tests/share/test_manager.py index ccb973d4bf..c0a7bca455 100644 --- a/manila/tests/share/test_manager.py +++ b/manila/tests/share/test_manager.py @@ -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() diff --git a/releasenotes/notes/fix-share-manager-shrinking-data-loss-state-edc87ba2fd7e32d8.yaml b/releasenotes/notes/fix-share-manager-shrinking-data-loss-state-edc87ba2fd7e32d8.yaml new file mode 100644 index 0000000000..16bafdf672 --- /dev/null +++ b/releasenotes/notes/fix-share-manager-shrinking-data-loss-state-edc87ba2fd7e32d8.yaml @@ -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.