Browse Source

Merge "QNAP: driver should not manage snapshot which does not exist"

Zuul 3 months ago
parent
commit
7f8f4bf5c9

+ 13
- 1
manila/share/drivers/qnap/qnap.py View File

@@ -75,9 +75,11 @@ class QnapShareDriver(driver.ShareDriver):
75 75
                 of managed share should not be changed.
76 76
         1.0.6 - Add support for QES fw 2.1.0.
77 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 84
     def __init__(self, *args, **kwargs):
83 85
         """Initialize QnapShareDriver."""
@@ -900,6 +902,7 @@ class QnapShareDriver(driver.ShareDriver):
900 902
 
901 903
         if len(snapshot_id_info) == 2:
902 904
             share_name = snapshot_id_info[0]
905
+            snapshot_name = snapshot_id_info[1]
903 906
         else:
904 907
             msg = _("Incorrect provider_location format. It should have the "
905 908
                     "following format: share_name@snapshot_name.")
@@ -914,6 +917,15 @@ class QnapShareDriver(driver.ShareDriver):
914 917
             LOG.error(msg)
915 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 929
         _metadata = {
918 930
             'snapshot_id': snapshot_id,
919 931
         }

+ 29
- 0
manila/tests/share/drivers/qnap/test_qnap.py View File

@@ -1147,6 +1147,35 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
1147 1147
         mock_private_storage.update.assert_called_once_with(
1148 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 1179
     def test_unmanage_snapshot(self):
1151 1180
         """Test unmanage snapshot."""
1152 1181
         fake_snapshot = fakes.SnapshotClass(

+ 5
- 0
releasenotes/notes/qnap-fix-manage-snapshot-not-exist-4b111982ddc5fdae.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+fixes:
3
+  - |
4
+    Fixed the QNAP driver so that the snapshot which does not exist in NAS
5
+    will not be managed.

Loading…
Cancel
Save