From 12f95b1373dad7b1a9201fb009093051fa2f8755 Mon Sep 17 00:00:00 2001 From: Alyson Rosa Date: Tue, 16 Aug 2016 09:19:42 -0300 Subject: [PATCH] Fix Manila HNAS driver managing a share twice Manila HNAS driver splits the path to manage a share by ':', so when passing a path with two colons the last part is ignored, it causes the possibility to manage a share twice. For example: manila manage --name test1 --share-type hds ubuntu@hnas#Hitachi nfs 172.24.49.26:/shares/f5b21612-9841-42c8-bec4-ca32ba70a9ae and manila manage --name test2 --share-type hds ubuntu@hnas#Hitachi nfs 172.24.49.26:/shares/f5b21612-9841-42c8-bec4-ca32ba70a9ae:1 Changing the split to search for ':/shares/' prevents a share to be managed twice. Change-Id: Ie97f749d7093db69a757db7c04041f6f649c7ce9 Closes-Bug: #1613683 --- manila/share/drivers/hitachi/hnas/driver.py | 8 ++++---- .../share/drivers/hitachi/hnas/test_driver.py | 19 ++++++++++++------- ...-managing-twice-hnas-4956a7653d27e320.yaml | 4 ++++ 3 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/fix-managing-twice-hnas-4956a7653d27e320.yaml diff --git a/manila/share/drivers/hitachi/hnas/driver.py b/manila/share/drivers/hitachi/hnas/driver.py index 0f6b8befda..fd0a9926cc 100644 --- a/manila/share/drivers/hitachi/hnas/driver.py +++ b/manila/share/drivers/hitachi/hnas/driver.py @@ -481,12 +481,12 @@ class HitachiHNASDriver(driver.ShareDriver): {'shr_path': share['export_locations'][0]['path'], 'shr_id': share['id']}) - old_path_info = share['export_locations'][0]['path'].split(':') - old_path = old_path_info[1].split('/') + old_path_info = share['export_locations'][0]['path'].split( + ':/shares/') - if len(old_path) == 3: + if len(old_path_info) == 2: evs_ip = old_path_info[0] - hnas_share_id = old_path[2] + hnas_share_id = old_path_info[1] else: msg = _("Incorrect path. It should have the following format: " "IP:/shares/share_id.") diff --git a/manila/tests/share/drivers/hitachi/hnas/test_driver.py b/manila/tests/share/drivers/hitachi/hnas/test_driver.py index 3ab80f7732..3b5e30abc1 100644 --- a/manila/tests/share/drivers/hitachi/hnas/test_driver.py +++ b/manila/tests/share/drivers/hitachi/hnas/test_driver.py @@ -596,14 +596,19 @@ class HitachiHNASTestCase(test.TestCase): self.assertRaises(exception.HNASBackendException, self._driver.manage_existing, share_nfs, 'option') - @ddt.data(share_nfs, share_cifs) - def test_manage_existing_wrong_path_format(self, share): - share_copy = share.copy() - share_copy['export_locations'] = [{'path': ':/'}] + @ddt.data(':/', '1.1.1.1:/share_id', '1.1.1.1:/shares', + '1.1.1.1:shares/share_id', ':/share_id') + def test_manage_existing_wrong_path_format(self, wrong_location): + expected_exception = ("Share backend error: Incorrect path. It " + "should have the following format: " + "IP:/shares/share_id.") + share_copy = share_nfs.copy() + share_copy['export_locations'] = [{'path': wrong_location}] - self.assertRaises(exception.ShareBackendException, - self._driver.manage_existing, share_copy, - 'option') + ex = self.assertRaises(exception.ShareBackendException, + self._driver.manage_existing, share_copy, + 'option') + self.assertEqual(expected_exception, ex.msg) def test_manage_existing_wrong_evs_ip(self): share_nfs['export_locations'] = [{'path': '172.24.44.189:/shares/' diff --git a/releasenotes/notes/fix-managing-twice-hnas-4956a7653d27e320.yaml b/releasenotes/notes/fix-managing-twice-hnas-4956a7653d27e320.yaml new file mode 100644 index 0000000000..d684e3b64b --- /dev/null +++ b/releasenotes/notes/fix-managing-twice-hnas-4956a7653d27e320.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Fixed Hitachi HNAS driver allowing a share to be managed twice through + a malformed export location parameter.