Merge "[NetApp] Fix share shrink error status"

This commit is contained in:
Zuul 2020-04-23 03:35:11 +00:00 committed by Gerrit Code Review
commit 3effe78ba9
4 changed files with 50 additions and 3 deletions

View File

@ -33,6 +33,7 @@ from manila.share.drivers.netapp import utils
LOG = log.getLogger(__name__)
EONTAPI_EINVAL = '22'
EVOLOPNOTSUPP = '160'
EAPIERROR = '13001'
EAPINOTFOUND = '13005'
ESNAPSHOTNOTALLOWED = '13023'

View File

@ -1653,9 +1653,21 @@ class NetAppCmodeFileStorageLibrary(object):
filesys_size_fixed=False)
LOG.debug('Shrinking share %(name)s to %(size)s GB.',
{'name': share_name, 'size': new_size})
vserver_client.set_volume_size(share_name, new_size)
self._adjust_qos_policy_with_volume_resize(share, new_size,
vserver_client)
try:
vserver_client.set_volume_size(share_name, new_size)
except netapp_api.NaApiError as e:
if e.code == netapp_api.EVOLOPNOTSUPP:
msg = _('Failed to shrink share %(share_id)s. '
'The current used space is larger than the the size'
' requested.')
msg_args = {'share_id': share['id']}
LOG.error(msg, msg_args)
raise exception.ShareShrinkingPossibleDataLoss(
share_id=share['id'])
self._adjust_qos_policy_with_volume_resize(
share, new_size, vserver_client)
@na_utils.trace
def update_access(self, context, share, access_rules, add_rules,

View File

@ -97,6 +97,10 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
mock.Mock(return_value=self.mock_dm_session))
self.mock_object(data_motion, 'get_client_for_backend')
def _mock_api_error(self, code='fake', message='fake'):
return mock.Mock(side_effect=netapp_api.NaApiError(code=code,
message=message))
def test_init(self):
self.assertEqual(fake.DRIVER_NAME, self.library.driver_name)
self.assertEqual(1, na_utils.validate_driver_instantiation.call_count)
@ -2781,6 +2785,29 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
mock_adjust_qos_policy.assert_called_once_with(
fake.SHARE, new_size, vserver_client)
def test_shrinking_possible_data_loss(self):
naapi_error = self._mock_api_error(code=netapp_api.EVOLOPNOTSUPP,
message='Possible data loss')
vserver_client = mock.Mock()
self.mock_object(self.library,
'_get_vserver',
mock.Mock(return_value=(fake.VSERVER1,
vserver_client)))
mock_set_volume_size = self.mock_object(
vserver_client, 'set_volume_size', naapi_error)
new_size = fake.SHARE['size'] - 1
self.assertRaises(exception.ShareShrinkingPossibleDataLoss,
self.library.shrink_share,
fake.SHARE, new_size)
self.library._get_vserver.assert_called_once_with(share_server=None)
mock_set_volume_size.assert_called_once_with(fake.SHARE_NAME, new_size)
def test_update_access(self):
vserver_client = mock.Mock()

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixed an issue in NetApp driver when shrinking shares to a size
smaller than the current used space. Now it will return a more
appropriate error status called
``shrinking_possible_data_loss_error``.