Browse Source

NetApp ONTAP: Fix revert-to-snapshot

In course of normal operation, the backend snapshot
name is associated with the the ID of the snapshot instance
in manila.

However, when a share is replicated or is being migrated,
the backend snapshot is not renamed. Instead, we simply
store the original name in the "provider_location" field of
the snapshot model.

Fix revert-to-snapshot methods to identify snapshots by
"provider_location"s rather than the instance IDs.

Co-Authored-By: Goutham Pacha Ravi <gouthampravi@gmail.com>

Change-Id: I4900c7aecc3da6640ea9c0d4d08012ff5b68cc58
Closes-Bug: #1694768
(cherry picked from commit bd47f93007)
(cherry picked from commit 038eb7be4f)
(cherry picked from commit c789d64a8a)
tags/4.0.2
Clinton Knight 2 years ago
parent
commit
b1d73fdb86

+ 6
- 3
manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py View File

@@ -798,7 +798,8 @@ class NetAppCmodeFileStorageLibrary(object):
798 798
         """Reverts a share (in place) to the specified snapshot."""
799 799
         vserver, vserver_client = self._get_vserver(share_server=share_server)
800 800
         share_name = self._get_backend_share_name(snapshot['share_id'])
801
-        snapshot_name = self._get_backend_snapshot_name(snapshot['id'])
801
+        snapshot_name = (snapshot.get('provider_location') or
802
+                         self._get_backend_snapshot_name(snapshot['id']))
802 803
         LOG.debug('Restoring snapshot %s', snapshot_name)
803 804
         vserver_client.restore_snapshot(share_name, snapshot_name)
804 805
 
@@ -1651,8 +1652,10 @@ class NetAppCmodeFileStorageLibrary(object):
1651 1652
         vserver, vserver_client = self._get_vserver(share_server=share_server)
1652 1653
         share_name = self._get_backend_share_name(
1653 1654
             active_replica_snapshot['share_id'])
1654
-        snapshot_name = self._get_backend_snapshot_name(
1655
-            active_replica_snapshot['id'])
1655
+        snapshot_name = (
1656
+            active_replica_snapshot.get('provider_location') or
1657
+            self._get_backend_snapshot_name(active_replica_snapshot['id']))
1658
+
1656 1659
         LOG.debug('Restoring snapshot %s', snapshot_name)
1657 1660
 
1658 1661
         dm_session = data_motion.DataMotionSession()

+ 20
- 6
manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py View File

@@ -1203,22 +1203,29 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
1203 1203
                                                                snapshot_name)
1204 1204
         self.assertEqual(snapshot_name, model_update['provider_location'])
1205 1205
 
1206
-    def test_revert_to_snapshot(self):
1206
+    @ddt.data(True, False)
1207
+    def test_revert_to_snapshot(self, use_snap_provider_location):
1207 1208
 
1208 1209
         vserver_client = mock.Mock()
1209 1210
         self.mock_object(self.library,
1210 1211
                          '_get_vserver',
1211 1212
                          mock.Mock(return_value=(fake.VSERVER1,
1212 1213
                                                  vserver_client)))
1214
+        fake_snapshot = copy.deepcopy(fake.SNAPSHOT)
1215
+        if use_snap_provider_location:
1216
+            fake_snapshot['provider_location'] = 'fake-provider-location'
1217
+        else:
1218
+            del fake_snapshot['provider_location']
1213 1219
 
1214 1220
         result = self.library.revert_to_snapshot(
1215
-            self.context, fake.SNAPSHOT, share_server=fake.SHARE_SERVER)
1221
+            self.context, fake_snapshot, share_server=fake.SHARE_SERVER)
1216 1222
 
1217 1223
         self.assertIsNone(result)
1218 1224
         share_name = self.library._get_backend_share_name(
1219
-            fake.SNAPSHOT['share_id'])
1220
-        snapshot_name = self.library._get_backend_snapshot_name(
1221
-            fake.SNAPSHOT['id'])
1225
+            fake_snapshot['share_id'])
1226
+        snapshot_name = (self.library._get_backend_snapshot_name(
1227
+            fake_snapshot['id']) if not use_snap_provider_location
1228
+            else 'fake-provider-location')
1222 1229
         vserver_client.restore_snapshot.assert_called_once_with(share_name,
1223 1230
                                                                 snapshot_name)
1224 1231
 
@@ -3679,11 +3686,18 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
3679 3686
         snapshot_list = [fake_snapshot, fake_snapshot_2, fake_snapshot_3]
3680 3687
         return replica_list, snapshot_list
3681 3688
 
3682
-    def test_revert_to_replicated_snapshot(self):
3689
+    @ddt.data(True, False)
3690
+    def test_revert_to_replicated_snapshot(self, use_snap_provider_location):
3683 3691
 
3684 3692
         replica_list, snapshot_list = self._get_fake_replicas_and_snapshots()
3685 3693
         fake_replica, fake_replica_2, fake_replica_3 = replica_list
3686 3694
         fake_snapshot, fake_snapshot_2, fake_snapshot_3 = snapshot_list
3695
+
3696
+        if not use_snap_provider_location:
3697
+            del fake_snapshot['provider_location']
3698
+            del fake_snapshot_2['provider_location']
3699
+            del fake_snapshot_3['provider_location']
3700
+
3687 3701
         share_name = self.library._get_backend_share_name(
3688 3702
             fake_snapshot['share_id'])
3689 3703
         snapshot_name = self.library._get_backend_snapshot_name(

+ 4
- 0
releasenotes/notes/bug-1694768-fix-netapp-cdot-revert-to-snapshot-5e1be65260454988.yaml View File

@@ -0,0 +1,4 @@
1
+---
2
+fixes:
3
+  - Fixed the NetApp ONTAP driver to handle reverting to replicated
4
+    and migrated snapshots.

Loading…
Cancel
Save