From 1aa78d1346b27290367d969be04bf6ef7de40e25 Mon Sep 17 00:00:00 2001 From: Alyson Rosa Date: Tue, 7 Feb 2017 10:13:27 -0200 Subject: [PATCH] HNAS: ensure snapshot before trying to revert HNAS driver does not need to start reverting if ensure_snapshot fails, it prevents trying to revert when snapshot does not exist on backend anymore. Also, an additional check for snapshot path in backend was added in ensure_snapshot. It is needed to ensure path for shares without 'mount_snapshot_support'. Closes-bug: #1662569 Change-Id: Idfb02193f012017cdc87468ee221bfa8f22c3fd2 --- manila/share/drivers/hitachi/hnas/driver.py | 6 ++++-- .../share/drivers/hitachi/hnas/test_driver.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/manila/share/drivers/hitachi/hnas/driver.py b/manila/share/drivers/hitachi/hnas/driver.py index 57246ffff6..7aa54a4e4e 100644 --- a/manila/share/drivers/hitachi/hnas/driver.py +++ b/manila/share/drivers/hitachi/hnas/driver.py @@ -750,12 +750,12 @@ class HitachiHNASDriver(driver.ShareDriver): Not used by this driver. """ - self._check_fs_mounted() - hnas_share_id = self._get_hnas_share_id(snapshot['share_id']) hnas_snapshot_id = self._get_hnas_snapshot_id(snapshot) + self._ensure_snapshot(snapshot, hnas_snapshot_id) + dest_path = os.path.join('/shares', hnas_share_id) src_path = os.path.join('/snapshots', hnas_share_id, hnas_snapshot_id) @@ -1135,6 +1135,8 @@ class HitachiHNASDriver(driver.ShareDriver): snapshot['share']['share_proto']) self._check_fs_mounted() + self.hnas.check_snapshot(snapshot['provider_location']) + export_list = None if snapshot['share'].get('mount_snapshot_support'): if snapshot['share']['share_proto'].lower() == 'nfs': diff --git a/manila/tests/share/drivers/hitachi/hnas/test_driver.py b/manila/tests/share/drivers/hitachi/hnas/test_driver.py index b83e95f61f..19dcc3e3ad 100644 --- a/manila/tests/share/drivers/hitachi/hnas/test_driver.py +++ b/manila/tests/share/drivers/hitachi/hnas/test_driver.py @@ -235,6 +235,7 @@ class HitachiHNASTestCase(test.TestCase): self.mock_object(ssh.HNASSSHBackend, "check_quota", mock.Mock()) self.mock_object(ssh.HNASSSHBackend, "check_cifs", mock.Mock()) self.mock_object(ssh.HNASSSHBackend, "check_export", mock.Mock()) + self.mock_object(ssh.HNASSSHBackend, 'check_snapshot') @ddt.data('hitachi_hnas_driver_helper', 'hitachi_hnas_evs_id', 'hitachi_hnas_evs_ip', 'hitachi_hnas_ip', 'hitachi_hnas_user') @@ -989,6 +990,8 @@ class HitachiHNASTestCase(test.TestCase): else: expected = None + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot['provider_location']) self.assertEqual(expected, result) def test_manage_existing_snapshot(self): @@ -1117,6 +1120,8 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.tree_clone.assert_called_once_with( '/'.join(('/snapshots', snap['share_id'], snap['id'])), '/'.join(('/shares', snap['share_id']))) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snap['provider_location']) if exc: self.assertTrue(self.mock_log.warning.called) @@ -1141,6 +1146,8 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.update_nfs_access_rule.assert_called_once_with( [access1['access_to'] + '(ro)', access2['access_to'] + '(ro)'], snapshot_id=snapshot_nfs['id']) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot_nfs['provider_location']) self.assertTrue(self.mock_log.debug.called) def test_nfs_snapshot_update_access_deny(self): @@ -1156,6 +1163,8 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.update_nfs_access_rule.assert_called_once_with( [], snapshot_id=snapshot_nfs['id']) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot_nfs['provider_location']) self.assertTrue(self.mock_log.debug.called) def test_nfs_snapshot_update_access_invalid_access_type(self): @@ -1167,6 +1176,8 @@ class HitachiHNASTestCase(test.TestCase): self.assertRaises(exception.InvalidSnapshotAccess, self._driver.snapshot_update_access, 'ctxt', snapshot_nfs, [access1], [], []) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot_nfs['provider_location']) def test_cifs_snapshot_update_access_allow(self): access1 = { @@ -1181,6 +1192,8 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.cifs_allow_access.assert_called_with( snapshot_cifs['id'], access1['access_to'], 'ar', is_snapshot=True) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot_cifs['provider_location']) self.assertTrue(self.mock_log.debug.called) def test_cifs_snapshot_update_access_deny(self): @@ -1196,6 +1209,8 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.cifs_deny_access.assert_called_with( snapshot_cifs['id'], access1['access_to'], is_snapshot=True) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot_cifs['provider_location']) self.assertTrue(self.mock_log.debug.called) def test_cifs_snapshot_update_access_recovery_mode(self): @@ -1226,4 +1241,6 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.cifs_allow_access.assert_called_with( snapshot_cifs['id'], access2['access_to'].replace('\\', '\\\\'), 'ar', is_snapshot=True) + ssh.HNASSSHBackend.check_snapshot.assert_called_once_with( + snapshot_cifs['provider_location']) self.assertTrue(self.mock_log.debug.called)