summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-01-03 20:07:09 +0000
committerGerrit Code Review <review@openstack.org>2019-01-03 20:07:09 +0000
commit7f8f4bf5c957bde10498db10db7cbf42ff794218 (patch)
treef81240fe68783af32eda8662cc51a2d82f85aef4
parent0c177b902a5799dfe2f026b67094d12081f31045 (diff)
parentcb7b8e292a5d34bdfb0d60729b8aa12900fdbcf3 (diff)
Merge "QNAP: driver should not manage snapshot which does not exist"
-rw-r--r--manila/share/drivers/qnap/qnap.py14
-rw-r--r--manila/tests/share/drivers/qnap/test_qnap.py29
-rw-r--r--releasenotes/notes/qnap-fix-manage-snapshot-not-exist-4b111982ddc5fdae.yaml5
3 files changed, 47 insertions, 1 deletions
diff --git a/manila/share/drivers/qnap/qnap.py b/manila/share/drivers/qnap/qnap.py
index 98a4b1b..3d56c31 100644
--- a/manila/share/drivers/qnap/qnap.py
+++ b/manila/share/drivers/qnap/qnap.py
@@ -75,9 +75,11 @@ class QnapShareDriver(driver.ShareDriver):
75 of managed share should not be changed. 75 of managed share should not be changed.
76 1.0.6 - Add support for QES fw 2.1.0. 76 1.0.6 - Add support for QES fw 2.1.0.
77 1.0.7 - Add support for QES fw on TDS series NAS model. 77 1.0.7 - Add support for QES fw on TDS series NAS model.
78 1.0.8 - Fix bug, driver should not manage snapshot which does not
79 exist in NAS.
78 """ 80 """
79 81
80 DRIVER_VERSION = '1.0.7' 82 DRIVER_VERSION = '1.0.8'
81 83
82 def __init__(self, *args, **kwargs): 84 def __init__(self, *args, **kwargs):
83 """Initialize QnapShareDriver.""" 85 """Initialize QnapShareDriver."""
@@ -900,6 +902,7 @@ class QnapShareDriver(driver.ShareDriver):
900 902
901 if len(snapshot_id_info) == 2: 903 if len(snapshot_id_info) == 2:
902 share_name = snapshot_id_info[0] 904 share_name = snapshot_id_info[0]
905 snapshot_name = snapshot_id_info[1]
903 else: 906 else:
904 msg = _("Incorrect provider_location format. It should have the " 907 msg = _("Incorrect provider_location format. It should have the "
905 "following format: share_name@snapshot_name.") 908 "following format: share_name@snapshot_name.")
@@ -914,6 +917,15 @@ class QnapShareDriver(driver.ShareDriver):
914 LOG.error(msg) 917 LOG.error(msg)
915 raise exception.ShareNotFound(reason=msg) 918 raise exception.ShareNotFound(reason=msg)
916 919
920 check_snapshot = self.api_executor.get_snapshot_info(
921 volID=volID, snapshot_name=snapshot_name)
922 if check_snapshot is None:
923 msg = (_("The snapshot %(snapshot_name)s was not "
924 "found on backend.") %
925 {'snapshot_name': snapshot_name})
926 LOG.error(msg)
927 raise exception.InvalidParameterValue(err=msg)
928
917 _metadata = { 929 _metadata = {
918 'snapshot_id': snapshot_id, 930 'snapshot_id': snapshot_id,
919 } 931 }
diff --git a/manila/tests/share/drivers/qnap/test_qnap.py b/manila/tests/share/drivers/qnap/test_qnap.py
index 0f252e3..6c397de 100644
--- a/manila/tests/share/drivers/qnap/test_qnap.py
+++ b/manila/tests/share/drivers/qnap/test_qnap.py
@@ -1147,6 +1147,35 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
1147 mock_private_storage.update.assert_called_once_with( 1147 mock_private_storage.update.assert_called_once_with(
1148 'fakeSnapshotId', fake_metadata) 1148 'fakeSnapshotId', fake_metadata)
1149 1149
1150 @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
1151 def test_manage_existing_snapshot_not_exist(
1152 self,
1153 mock_get_location_path):
1154 """Test manage existing snapshot with snapshot which does not exist."""
1155 fake_snapshot = fakes.SnapshotClass(
1156 10, 'fakeShareName@fakeSnapshotName')
1157
1158 mock_api_executor = qnap.QnapShareDriver._create_api_executor
1159 mock_api_executor.return_value.get_share_info.return_value = (
1160 self.get_share_info_return_value())
1161 mock_api_executor.return_value.get_snapshot_info.return_value = None
1162 mock_private_storage = mock.Mock()
1163 mock_private_storage.get.side_effect = [
1164 'fakeVolId', 'fakeVolName']
1165
1166 self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
1167 'qnapadmin', 'Storage Pool 1',
1168 private_storage=mock_private_storage)
1169
1170 mock_api_return = mock_api_executor.return_value
1171 self.assertRaises(
1172 exception.InvalidParameterValue,
1173 self.driver.manage_existing_snapshot,
1174 snapshot=fake_snapshot,
1175 driver_options='driver_options')
1176 mock_api_return.get_share_info.assert_called_once_with(
1177 'Storage Pool 1', vol_no='fakeVolId')
1178
1150 def test_unmanage_snapshot(self): 1179 def test_unmanage_snapshot(self):
1151 """Test unmanage snapshot.""" 1180 """Test unmanage snapshot."""
1152 fake_snapshot = fakes.SnapshotClass( 1181 fake_snapshot = fakes.SnapshotClass(
diff --git a/releasenotes/notes/qnap-fix-manage-snapshot-not-exist-4b111982ddc5fdae.yaml b/releasenotes/notes/qnap-fix-manage-snapshot-not-exist-4b111982ddc5fdae.yaml
new file mode 100644
index 0000000..488ed2a
--- /dev/null
+++ b/releasenotes/notes/qnap-fix-manage-snapshot-not-exist-4b111982ddc5fdae.yaml
@@ -0,0 +1,5 @@
1---
2fixes:
3 - |
4 Fixed the QNAP driver so that the snapshot which does not exist in NAS
5 will not be managed.