Browse Source

Merge "Add user message when share shrinking fails at the driver" into stable/ussuri

changes/97/735297/1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
fc26a7555c
4 changed files with 67 additions and 1 deletions
  1. +6
    -1
      manila/message/message_field.py
  2. +10
    -0
      manila/share/manager.py
  3. +46
    -0
      manila/tests/share/test_manager.py
  4. +5
    -0
      releasenotes/notes/bug-1802424-add-user-message-when-shrinking-fails-83d0f60ead6f4a4b.yaml

+ 6
- 1
manila/message/message_field.py View File

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


+ 10
- 0
manila/share/manager.py View File

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



+ 46
- 0
manila/tests/share/test_manager.py View File

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


+ 5
- 0
releasenotes/notes/bug-1802424-add-user-message-when-shrinking-fails-83d0f60ead6f4a4b.yaml View File

@@ -0,0 +1,5 @@

fixes:
- |
Added a new user message when share shrinking fails due to operation not being
supported by the driver.

Loading…
Cancel
Save