Browse Source

[Unity] Revert to snapshot support

Implement revert to snapshot support for Dell EMC Unity driver.

Change-Id: I3a4da4a506ae4c2dbcd97207121ce19ecfb98043
Implements: unity-revert-to-snapshot
Yong Huang 3 months ago
parent
commit
e4156ddb08

+ 17
- 1
manila/share/drivers/dell_emc/driver.py View File

@@ -81,6 +81,11 @@ class EMCShareDriver(driver.ShareDriver):
81 81
         if hasattr(self.plugin, 'ipv6_implemented'):
82 82
             self.ipv6_implemented = self.plugin.ipv6_implemented
83 83
 
84
+        if hasattr(self.plugin, 'revert_to_snap_support'):
85
+            self.revert_to_snap_support = self.plugin.revert_to_snap_support
86
+        else:
87
+            self.revert_to_snap_support = False
88
+
84 89
     def create_share(self, context, share, share_server=None):
85 90
         """Is called to create share."""
86 91
         location = self.plugin.create_share(context, share, share_server)
@@ -147,7 +152,8 @@ class EMCShareDriver(driver.ShareDriver):
147 152
             vendor_name='Dell EMC',
148 153
             storage_protocol='NFS_CIFS',
149 154
             snapshot_support=True,
150
-            create_share_from_snapshot_support=True)
155
+            create_share_from_snapshot_support=True,
156
+            revert_to_snapshot_support=self.revert_to_snap_support)
151 157
         self.plugin.update_share_stats(data)
152 158
         super(EMCShareDriver, self)._update_share_stats(data)
153 159
 
@@ -168,3 +174,13 @@ class EMCShareDriver(driver.ShareDriver):
168 174
             return [4, 6]
169 175
         else:
170 176
             return [4]
177
+
178
+    def revert_to_snapshot(self, context, snapshot, share_access_rules,
179
+                           snapshot_access_rules, share_server=None):
180
+        if self.revert_to_snap_support:
181
+            return self.plugin.revert_to_snapshot(context, snapshot,
182
+                                                  share_access_rules,
183
+                                                  snapshot_access_rules,
184
+                                                  share_server)
185
+        else:
186
+            raise NotImplementedError()

+ 4
- 0
manila/share/drivers/dell_emc/plugins/unity/client.py View File

@@ -330,3 +330,7 @@ class UnityClient(object):
330 330
             LOG.info("This system doesn't support tenant.")
331 331
 
332 332
         return tenant
333
+
334
+    def restore_snapshot(self, snap_name):
335
+        snap = self.get_snapshot(snap_name)
336
+        return snap.restore(delete_backup=True)

+ 7
- 1
manila/share/drivers/dell_emc/plugins/unity/connection.py View File

@@ -36,7 +36,7 @@ from manila.share.drivers.dell_emc.plugins.unity import utils as unity_utils
36 36
 from manila.share import utils as share_utils
37 37
 from manila import utils
38 38
 
39
-VERSION = "4.0.0"
39
+VERSION = "6.0.0"
40 40
 
41 41
 LOG = log.getLogger(__name__)
42 42
 SUPPORTED_NETWORK_TYPES = (None, 'flat', 'vlan')
@@ -86,6 +86,7 @@ class UnityStorageConnection(driver.StorageConnection):
86 86
         self.max_over_subscription_ratio = None
87 87
         self.port_ids_conf = None
88 88
         self.ipv6_implemented = True
89
+        self.revert_to_snap_support = True
89 90
 
90 91
         # props from super class.
91 92
         self.driver_handles_share_servers = True
@@ -678,3 +679,8 @@ class UnityStorageConnection(driver.StorageConnection):
678 679
             raise exception.InvalidShare(
679 680
                 reason=(_('Invalid NAS protocol supplied: %s.') %
680 681
                         share_proto))
682
+
683
+    def revert_to_snapshot(self, context, snapshot, share_access_rules,
684
+                           snapshot_access_rules, share_server=None):
685
+        """Reverts a share (in place) to the specified snapshot."""
686
+        return self.client.restore_snapshot(snapshot['id'])

+ 24
- 0
manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml View File

@@ -173,6 +173,13 @@ tenant_1: &tenant_1
173 173
     uuid: "173ca6c3-5952-427d-82a6-df88f49e3926"
174 174
     vlans: [2]
175 175
 
176
+snapshot_1: &snapshot_1
177
+  _properties:
178
+    id: "snapshot_1"
179
+    name: "Snapshot_1"
180
+  _methods:
181
+    restore: True
182
+
176 183
 unity_base: &unity_base
177 184
   _methods: &unity_base_method
178 185
       get_sp: *sp_a
@@ -1102,3 +1109,20 @@ test_create_file_interface_ipv6:
1102 1109
   nas_server:
1103 1110
     _methods:
1104 1111
       create_file_interface:
1112
+
1113
+test_get_snapshot:
1114
+  unity:
1115
+    _methods:
1116
+      get_snap: *snapshot_1
1117
+
1118
+test_get_snapshot_nonexistent_expt:
1119
+  unity:
1120
+    _methods:
1121
+      get_snap:
1122
+        _raise:
1123
+          UnityResourceNotFoundError:
1124
+
1125
+test_restore_snapshot:
1126
+  unity:
1127
+    _methods:
1128
+      get_snap: *snapshot_1

+ 12
- 0
manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py View File

@@ -231,3 +231,15 @@ class TestClient(test.TestCase):
231 231
             v6_prefix_length=mock_file_interface.prefix_length,
232 232
             gateway=mock_file_interface.gateway,
233 233
             vlan_id=mock_file_interface.vlan_id)
234
+
235
+    @res_mock.patch_client
236
+    def test_get_snapshot(self, client):
237
+        snapshot = client.get_snapshot('Snapshot_1')
238
+        self.assertEqual('snapshot_1', snapshot.id)
239
+
240
+    @res_mock.patch_client
241
+    def test_restore_snapshot(self, client):
242
+        snapshot = client.get_snapshot('Snapshot_1')
243
+        rst = client.restore_snapshot(snapshot.name)
244
+        self.assertIs(True, rst)
245
+        snapshot.restore.assert_called_once_with(delete_backup=True)

+ 11
- 1
manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py View File

@@ -414,7 +414,6 @@ class TestConnection(test.TestCase):
414 414
 
415 415
     @res_mock.patch_connection
416 416
     def test_validate_port_configuration_exception(self, connection):
417
-
418 417
         self.assertRaises(exception.BadConfigurationException,
419 418
                           connection.validate_port_configuration,
420 419
                           ['xxxx*'])
@@ -653,3 +652,14 @@ class TestConnection(test.TestCase):
653 652
                     'vlan_id': '201'}
654 653
         connection.client.create_interface.assert_called_once_with(nas_server,
655 654
                                                                    **expected)
655
+
656
+    @res_mock.mock_manila_input
657
+    @res_mock.patch_connection
658
+    def test_revert_to_snapshot(self, connection, mocked_input):
659
+        context = mock.Mock()
660
+        snapshot = mocked_input['snapshot']
661
+        share_access_rules = [mocked_input['nfs_rw_access'], ]
662
+        snapshot_access_rules = [mocked_input['nfs_rw_access'], ]
663
+
664
+        connection.revert_to_snapshot(context, snapshot, share_access_rules,
665
+                                      snapshot_access_rules)

+ 3
- 0
releasenotes/notes/unity-revert-to-snapshot-support-1cffc3914982003d.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+features:
3
+  - Revert to snapshot support for Dell EMC Unity Manila driver.

Loading…
Cancel
Save