From e8d2b34dd79558cc3ee76603cde72e414fead1ce Mon Sep 17 00:00:00 2001 From: nidhimittalhada Date: Thu, 28 Jul 2016 12:54:37 +0530 Subject: [PATCH] share-size not set to 1 with 'manage_error' state Currently, when we set share-state to 'manage-error', share-size is set to 1 at all places except this one. Which results in error logged during delete-share, w.r.t quota. This fix sets share-size to 1 when share state is set to 'manage_error'. Change-Id: I96343ffd4f273b01c0376713717cdc89ea9a873a Closes-Bug: #1587636 --- manila/scheduler/manager.py | 5 ++++- manila/tests/scheduler/test_manager.py | 9 ++++++++- .../tests/api/admin/test_share_manage.py | 2 ++ .../notes/error-share-set-size-ff5d4f4ac2d56755.yaml | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/error-share-set-size-ff5d4f4ac2d56755.yaml diff --git a/manila/scheduler/manager.py b/manila/scheduler/manager.py index ac294a8ee5..a825a115ac 100644 --- a/manila/scheduler/manager.py +++ b/manila/scheduler/manager.py @@ -126,9 +126,12 @@ class SchedulerManager(manager.Manager): """Ensure that the host exists and can accept the share.""" def _manage_share_set_error(self, context, ex, request_spec): + # NOTE(nidhimittalhada): set size as 1 because design expects size + # to be set, it also will allow us to handle delete/unmanage + # operations properly with this errored share according to quotas. self._set_share_state_and_notify( 'manage_share', - {'status': constants.STATUS_MANAGE_ERROR}, + {'status': constants.STATUS_MANAGE_ERROR, 'size': 1}, context, ex, request_spec) share_ref = db.share_get(context, share_id) diff --git a/manila/tests/scheduler/test_manager.py b/manila/tests/scheduler/test_manager.py index ce69981e7e..b9181c06ca 100644 --- a/manila/tests/scheduler/test_manager.py +++ b/manila/tests/scheduler/test_manager.py @@ -258,13 +258,20 @@ class SchedulerManagerTestCase(test.TestCase): share = db_utils.create_share() + db_update = self.mock_object(db, 'share_update', mock.Mock()) self.mock_object( base.Scheduler, 'host_passes_filters', mock.Mock(side_effect=exception.NoValidHost('fake'))) + share_id = share['id'] + self.assertRaises( exception.NoValidHost, self.manager.manage_share, - self.context, share['id'], 'driver_options', {}, None) + self.context, share['id'], 'driver_options', + {'share_id': share_id}, None) + db_update.assert_called_once_with( + self.context, share_id, + {'status': constants.STATUS_MANAGE_ERROR, 'size': 1}) def test_create_share_replica_exception_path(self): """Test 'raisable' exceptions for create_share_replica.""" diff --git a/manila_tempest_tests/tests/api/admin/test_share_manage.py b/manila_tempest_tests/tests/api/admin/test_share_manage.py index ee028e90da..d8b3e19c54 100644 --- a/manila_tempest_tests/tests/api/admin/test_share_manage.py +++ b/manila_tempest_tests/tests/api/admin/test_share_manage.py @@ -212,6 +212,8 @@ class ManageNFSShareTest(base.BaseSharesAdminTest): self.shares_v2_client.wait_for_share_status( share['id'], 'manage_error') + share = self.shares_v2_client.get_share(share['id']) + self.assertEqual(1, int(share['size'])) # Delete resource from backend. We need to manage the share properly # so it can be removed. diff --git a/releasenotes/notes/error-share-set-size-ff5d4f4ac2d56755.yaml b/releasenotes/notes/error-share-set-size-ff5d4f4ac2d56755.yaml new file mode 100644 index 0000000000..1806ee66d9 --- /dev/null +++ b/releasenotes/notes/error-share-set-size-ff5d4f4ac2d56755.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Any errors that may occur during 'managing' a share into manila will + result in the share's size being set to 1, aside from transitioning + the status to 'manage_error'.