diff --git a/manila/share/drivers/dell_emc/driver.py b/manila/share/drivers/dell_emc/driver.py index 46d684e225..a149c08d1c 100644 --- a/manila/share/drivers/dell_emc/driver.py +++ b/manila/share/drivers/dell_emc/driver.py @@ -81,6 +81,11 @@ class EMCShareDriver(driver.ShareDriver): if hasattr(self.plugin, 'ipv6_implemented'): self.ipv6_implemented = self.plugin.ipv6_implemented + if hasattr(self.plugin, 'revert_to_snap_support'): + self.revert_to_snap_support = self.plugin.revert_to_snap_support + else: + self.revert_to_snap_support = False + def create_share(self, context, share, share_server=None): """Is called to create share.""" location = self.plugin.create_share(context, share, share_server) @@ -147,7 +152,8 @@ class EMCShareDriver(driver.ShareDriver): vendor_name='Dell EMC', storage_protocol='NFS_CIFS', snapshot_support=True, - create_share_from_snapshot_support=True) + create_share_from_snapshot_support=True, + revert_to_snapshot_support=self.revert_to_snap_support) self.plugin.update_share_stats(data) super(EMCShareDriver, self)._update_share_stats(data) @@ -168,3 +174,13 @@ class EMCShareDriver(driver.ShareDriver): return [4, 6] else: return [4] + + def revert_to_snapshot(self, context, snapshot, share_access_rules, + snapshot_access_rules, share_server=None): + if self.revert_to_snap_support: + return self.plugin.revert_to_snapshot(context, snapshot, + share_access_rules, + snapshot_access_rules, + share_server) + else: + raise NotImplementedError() diff --git a/manila/share/drivers/dell_emc/plugins/unity/client.py b/manila/share/drivers/dell_emc/plugins/unity/client.py index 753d9a4aa5..8613505bce 100644 --- a/manila/share/drivers/dell_emc/plugins/unity/client.py +++ b/manila/share/drivers/dell_emc/plugins/unity/client.py @@ -330,3 +330,7 @@ class UnityClient(object): LOG.info("This system doesn't support tenant.") return tenant + + def restore_snapshot(self, snap_name): + snap = self.get_snapshot(snap_name) + return snap.restore(delete_backup=True) diff --git a/manila/share/drivers/dell_emc/plugins/unity/connection.py b/manila/share/drivers/dell_emc/plugins/unity/connection.py index 2dd93dfaa1..b7b53ec84a 100644 --- a/manila/share/drivers/dell_emc/plugins/unity/connection.py +++ b/manila/share/drivers/dell_emc/plugins/unity/connection.py @@ -36,7 +36,7 @@ from manila.share.drivers.dell_emc.plugins.unity import utils as unity_utils from manila.share import utils as share_utils from manila import utils -VERSION = "4.0.0" +VERSION = "6.0.0" LOG = log.getLogger(__name__) SUPPORTED_NETWORK_TYPES = (None, 'flat', 'vlan') @@ -86,6 +86,7 @@ class UnityStorageConnection(driver.StorageConnection): self.max_over_subscription_ratio = None self.port_ids_conf = None self.ipv6_implemented = True + self.revert_to_snap_support = True # props from super class. self.driver_handles_share_servers = True @@ -678,3 +679,8 @@ class UnityStorageConnection(driver.StorageConnection): raise exception.InvalidShare( reason=(_('Invalid NAS protocol supplied: %s.') % share_proto)) + + def revert_to_snapshot(self, context, snapshot, share_access_rules, + snapshot_access_rules, share_server=None): + """Reverts a share (in place) to the specified snapshot.""" + return self.client.restore_snapshot(snapshot['id']) diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml b/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml index 69ef556409..d156ff518e 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/mocked_unity.yaml @@ -173,6 +173,13 @@ tenant_1: &tenant_1 uuid: "173ca6c3-5952-427d-82a6-df88f49e3926" vlans: [2] +snapshot_1: &snapshot_1 + _properties: + id: "snapshot_1" + name: "Snapshot_1" + _methods: + restore: True + unity_base: &unity_base _methods: &unity_base_method get_sp: *sp_a @@ -1102,3 +1109,20 @@ test_create_file_interface_ipv6: nas_server: _methods: create_file_interface: + +test_get_snapshot: + unity: + _methods: + get_snap: *snapshot_1 + +test_get_snapshot_nonexistent_expt: + unity: + _methods: + get_snap: + _raise: + UnityResourceNotFoundError: + +test_restore_snapshot: + unity: + _methods: + get_snap: *snapshot_1 diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py b/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py index 3603db1569..251e976e85 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py @@ -231,3 +231,15 @@ class TestClient(test.TestCase): v6_prefix_length=mock_file_interface.prefix_length, gateway=mock_file_interface.gateway, vlan_id=mock_file_interface.vlan_id) + + @res_mock.patch_client + def test_get_snapshot(self, client): + snapshot = client.get_snapshot('Snapshot_1') + self.assertEqual('snapshot_1', snapshot.id) + + @res_mock.patch_client + def test_restore_snapshot(self, client): + snapshot = client.get_snapshot('Snapshot_1') + rst = client.restore_snapshot(snapshot.name) + self.assertIs(True, rst) + snapshot.restore.assert_called_once_with(delete_backup=True) diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py b/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py index a94b21b00f..0ac3de9f12 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py @@ -414,7 +414,6 @@ class TestConnection(test.TestCase): @res_mock.patch_connection def test_validate_port_configuration_exception(self, connection): - self.assertRaises(exception.BadConfigurationException, connection.validate_port_configuration, ['xxxx*']) @@ -653,3 +652,14 @@ class TestConnection(test.TestCase): 'vlan_id': '201'} connection.client.create_interface.assert_called_once_with(nas_server, **expected) + + @res_mock.mock_manila_input + @res_mock.patch_connection + def test_revert_to_snapshot(self, connection, mocked_input): + context = mock.Mock() + snapshot = mocked_input['snapshot'] + share_access_rules = [mocked_input['nfs_rw_access'], ] + snapshot_access_rules = [mocked_input['nfs_rw_access'], ] + + connection.revert_to_snapshot(context, snapshot, share_access_rules, + snapshot_access_rules) diff --git a/releasenotes/notes/unity-revert-to-snapshot-support-1cffc3914982003d.yaml b/releasenotes/notes/unity-revert-to-snapshot-support-1cffc3914982003d.yaml new file mode 100644 index 0000000000..cc2561bbde --- /dev/null +++ b/releasenotes/notes/unity-revert-to-snapshot-support-1cffc3914982003d.yaml @@ -0,0 +1,3 @@ +--- +features: + - Revert to snapshot support for Dell EMC Unity Manila driver.