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
This commit is contained in:
zhongjun 2016-05-24 15:26:01 +08:00
parent c5b0124541
commit 548975ee2d
3 changed files with 16 additions and 10 deletions

View File

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

View File

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

View File

@ -0,0 +1,3 @@
---
fixes:
- Fix exception in update_access not found in Huawei driver.