From 548975ee2d372f8374697e3d838e0b62cf2c6310 Mon Sep 17 00:00:00 2001 From: zhongjun Date: Tue, 24 May 2016 15:26:01 +0800 Subject: [PATCH] Huawei: Fix exception in update_access not found When share is deleted in the backend, user is unable to delete share because of error thrown in update_access(). Make backend raise ShareResourceNotFound exception in case share not found during "update_access" operation, because share manager expects it for proper handling of share deletion, thus allowing share to be deleted in this case, without having to use force-delete. After add ShareResourceNotFound exception, it will need a parameter named share id(share['id']), so add share id to share info in create_share_from_snapshot function. Change-Id: I9756ff882e6960b07f5f0abac94057c687830ad0 Closes-Bug: #1585035 --- manila/share/drivers/huawei/v3/connection.py | 15 +++++++++------ .../tests/share/drivers/huawei/test_huawei_nas.py | 8 ++++---- .../fix-huawei-exception-a09b73234ksd94kd.yaml | 3 +++ 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/fix-huawei-exception-a09b73234ksd94kd.yaml diff --git a/manila/share/drivers/huawei/v3/connection.py b/manila/share/drivers/huawei/v3/connection.py index dac3f0ce..4195bbb9 100644 --- a/manila/share/drivers/huawei/v3/connection.py +++ b/manila/share/drivers/huawei/v3/connection.py @@ -388,6 +388,7 @@ class V3StorageConnection(driver.HuaweiBase): "mount_path": new_share_path.replace("\\", "/"), "mount_src": tempfile.mkdtemp(prefix=constants.TMP_PATH_DST_PREFIX), + "id": snapshot['share_id'], } old_share_path = self._get_location_path(old_share_name, @@ -399,7 +400,8 @@ class V3StorageConnection(driver.HuaweiBase): "mount_src": tempfile.mkdtemp(prefix=constants.TMP_PATH_SRC_PREFIX), "snapshot_name": ("share_snapshot_" + - snapshot['id'].replace("-", "_")) + snapshot['id'].replace("-", "_")), + "id": snapshot['share_id'], } try: @@ -701,14 +703,15 @@ class V3StorageConnection(driver.HuaweiBase): ' for CIFS shares.') raise exception.InvalidShareAccess(reason=message) - share = self.helper._get_share_by_name(share_name, share_url_type) - if not share: - err_msg = (_("Can not get share ID by share %s.") + share_stor = self.helper._get_share_by_name(share_name, + share_url_type) + if not share_stor: + err_msg = (_("Share %s does not exist on the backend.") % share_name) LOG.error(err_msg) - raise exception.InvalidShareAccess(reason=err_msg) + raise exception.ShareResourceNotFound(share_id=share['id']) - share_id = share['ID'] + share_id = share_stor['ID'] # Check if access already exists access_id = self.helper._get_access_from_share(share_id, diff --git a/manila/tests/share/drivers/huawei/test_huawei_nas.py b/manila/tests/share/drivers/huawei/test_huawei_nas.py index f24fae0b..43d99152 100644 --- a/manila/tests/share/drivers/huawei/test_huawei_nas.py +++ b/manila/tests/share/drivers/huawei/test_huawei_nas.py @@ -1992,7 +1992,7 @@ class HuaweiShareDriverTestCase(test.TestCase): self.driver.plugin.helper.login() self.driver.plugin.helper.snapshot_flag = True - self.assertRaises(exception.InvalidShareAccess, + self.assertRaises(exception.ShareResourceNotFound, self.driver.create_share_from_snapshot, self._context, self.share_nfs, self.nfs_snapshot, self.share_server) @@ -2044,7 +2044,7 @@ class HuaweiShareDriverTestCase(test.TestCase): self.driver.plugin.helper.login() self.driver.plugin.helper.snapshot_flag = True - self.assertRaises(exception.InvalidShareAccess, + self.assertRaises(exception.ShareResourceNotFound, self.driver.create_share_from_snapshot, self._context, self.share_nfs, self.nfs_snapshot, self.share_server) @@ -2318,7 +2318,7 @@ class HuaweiShareDriverTestCase(test.TestCase): self.driver.plugin.helper.login() rules = [self.access_ip] self.driver.plugin.helper.share_exist = False - self.assertRaises(exception.InvalidShareAccess, + self.assertRaises(exception.ShareResourceNotFound, self.driver.update_access, self._context, self.share_nfs, rules, None, None, self.share_server) @@ -2380,7 +2380,7 @@ class HuaweiShareDriverTestCase(test.TestCase): def test_allow_access_ip_share_not_exist(self): self.driver.plugin.helper.login() self.driver.plugin.helper.share_exist = False - self.assertRaises(exception.InvalidShareAccess, + self.assertRaises(exception.ShareResourceNotFound, self.driver.allow_access, self._context, self.share_nfs, self.access_ip, self.share_server) diff --git a/releasenotes/notes/fix-huawei-exception-a09b73234ksd94kd.yaml b/releasenotes/notes/fix-huawei-exception-a09b73234ksd94kd.yaml new file mode 100644 index 00000000..34a9a482 --- /dev/null +++ b/releasenotes/notes/fix-huawei-exception-a09b73234ksd94kd.yaml @@ -0,0 +1,3 @@ +--- +fixes: + - Fix exception in update_access not found in Huawei driver.