diff --git a/manila/share/api.py b/manila/share/api.py index fa6369b236..30983e0abd 100644 --- a/manila/share/api.py +++ b/manila/share/api.py @@ -1348,20 +1348,7 @@ class API(base.Base): policy.check_policy(ctx, 'share', 'allow_access') share = self.db.share_get(ctx, share['id']) if share['status'] != constants.STATUS_AVAILABLE: - if not (share['status'] in (constants.STATUS_MIGRATING, - constants.STATUS_MIGRATING_TO) and - share['task_state'] in ( - constants.TASK_STATE_DATA_COPYING_ERROR, - constants.TASK_STATE_MIGRATION_ERROR, - constants.TASK_STATE_MIGRATION_DRIVER_PHASE1_DONE, - constants.TASK_STATE_DATA_COPYING_COMPLETED)): - msg = _("Share status must be %(available)s, or %(migrating)s " - "while first phase of migration is completed.") % { - 'available': constants.STATUS_AVAILABLE, - 'migrating': constants.STATUS_MIGRATING - } - else: - msg = _("Share status must be %s") % constants.STATUS_AVAILABLE + msg = _("Share status must be %s") % constants.STATUS_AVAILABLE raise exception.InvalidShare(reason=msg) values = { 'share_id': share['id'], @@ -1433,20 +1420,7 @@ class API(base.Base): msg = _("Share doesn't have any instances") raise exception.InvalidShare(reason=msg) if share['status'] != constants.STATUS_AVAILABLE: - if not (share['status'] in (constants.STATUS_MIGRATING, - constants.STATUS_MIGRATING_TO) and - share['task_state'] in ( - constants.TASK_STATE_DATA_COPYING_ERROR, - constants.TASK_STATE_MIGRATION_ERROR, - constants.TASK_STATE_MIGRATION_DRIVER_PHASE1_DONE, - constants.TASK_STATE_DATA_COPYING_COMPLETED)): - msg = _("Share status must be %(available)s, or %(migrating)s " - "while first phase of migration is completed.") % { - 'available': constants.STATUS_AVAILABLE, - 'migrating': constants.STATUS_MIGRATING - } - else: - msg = _("Share status must be %s") % constants.STATUS_AVAILABLE + msg = _("Share status must be %s") % constants.STATUS_AVAILABLE raise exception.InvalidShare(reason=msg) for share_instance in share.instances: diff --git a/manila/share/migration.py b/manila/share/migration.py index e3b7d04ae6..333f8fadb6 100644 --- a/manila/share/migration.py +++ b/manila/share/migration.py @@ -195,6 +195,10 @@ class ShareMigrationHelper(object): LOG.debug("Restoring all of share %s access rules according to " "DB.", self.share['id']) + # refresh share instance + new_share_instance = self.db.share_instance_get( + self.context, new_share_instance['id'], with_share_data=True) + self.api.allow_access_to_instance(self.context, new_share_instance, rules) utils.wait_for_access_update( diff --git a/manila/tests/share/test_migration.py b/manila/tests/share/test_migration.py index 695e300bfa..e82353b52b 100644 --- a/manila/tests/share/test_migration.py +++ b/manila/tests/share/test_migration.py @@ -345,6 +345,8 @@ class ShareMigrationHelperTestCase(test.TestCase): access_level='rw') # mocks + self.mock_object(db, 'share_instance_get', + mock.Mock(return_value=new_share_instance)) self.mock_object(db, 'share_instance_access_copy') self.mock_object(db, 'share_access_get_all_for_instance', mock.Mock(return_value=[access])) @@ -355,6 +357,8 @@ class ShareMigrationHelperTestCase(test.TestCase): self.helper.apply_new_access_rules(new_share_instance) # asserts + db.share_instance_get.assert_called_once_with( + self.context, new_share_instance['id'], with_share_data=True) db.share_instance_access_copy(self.context, self.share['id'], new_share_instance['id']) db.share_access_get_all_for_instance.assert_called_once_with( diff --git a/releasenotes/notes/migration-access-fix-71a0f52ea7a152a3.yaml b/releasenotes/notes/migration-access-fix-71a0f52ea7a152a3.yaml new file mode 100644 index 0000000000..b214c449a2 --- /dev/null +++ b/releasenotes/notes/migration-access-fix-71a0f52ea7a152a3.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - Fixed access_allow and access_deny displaying incorrect error + message during migration of a share. + - Fixed access rule concurrency in migration that was preventing + new rules from being added to the migrated share. +