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)
This commit is contained in:
Clinton Knight 2017-05-31 13:52:02 -04:00 committed by Goutham Pacha Ravi
parent e39147621b
commit 038eb7be4f
3 changed files with 30 additions and 9 deletions

View File

@ -879,7 +879,8 @@ class NetAppCmodeFileStorageLibrary(object):
"""Reverts a share (in place) to the specified snapshot."""
vserver, vserver_client = self._get_vserver(share_server=share_server)
share_name = self._get_backend_share_name(snapshot['share_id'])
snapshot_name = self._get_backend_snapshot_name(snapshot['id'])
snapshot_name = (snapshot.get('provider_location') or
self._get_backend_snapshot_name(snapshot['id']))
LOG.debug('Restoring snapshot %s', snapshot_name)
vserver_client.restore_snapshot(share_name, snapshot_name)
@ -1824,8 +1825,10 @@ class NetAppCmodeFileStorageLibrary(object):
vserver, vserver_client = self._get_vserver(share_server=share_server)
share_name = self._get_backend_share_name(
active_replica_snapshot['share_id'])
snapshot_name = self._get_backend_snapshot_name(
active_replica_snapshot['id'])
snapshot_name = (
active_replica_snapshot.get('provider_location') or
self._get_backend_snapshot_name(active_replica_snapshot['id']))
LOG.debug('Restoring snapshot %s', snapshot_name)
dm_session = data_motion.DataMotionSession()

View File

@ -1309,22 +1309,29 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
snapshot_name)
self.assertEqual(snapshot_name, model_update['provider_location'])
def test_revert_to_snapshot(self):
@ddt.data(True, False)
def test_revert_to_snapshot(self, use_snap_provider_location):
vserver_client = mock.Mock()
self.mock_object(self.library,
'_get_vserver',
mock.Mock(return_value=(fake.VSERVER1,
vserver_client)))
fake_snapshot = copy.deepcopy(fake.SNAPSHOT)
if use_snap_provider_location:
fake_snapshot['provider_location'] = 'fake-provider-location'
else:
del fake_snapshot['provider_location']
result = self.library.revert_to_snapshot(
self.context, fake.SNAPSHOT, share_server=fake.SHARE_SERVER)
self.context, fake_snapshot, share_server=fake.SHARE_SERVER)
self.assertIsNone(result)
share_name = self.library._get_backend_share_name(
fake.SNAPSHOT['share_id'])
snapshot_name = self.library._get_backend_snapshot_name(
fake.SNAPSHOT['id'])
fake_snapshot['share_id'])
snapshot_name = (self.library._get_backend_snapshot_name(
fake_snapshot['id']) if not use_snap_provider_location
else 'fake-provider-location')
vserver_client.restore_snapshot.assert_called_once_with(share_name,
snapshot_name)
@ -3919,11 +3926,18 @@ class NetAppFileStorageLibraryTestCase(test.TestCase):
snapshot_list = [fake_snapshot, fake_snapshot_2, fake_snapshot_3]
return replica_list, snapshot_list
def test_revert_to_replicated_snapshot(self):
@ddt.data(True, False)
def test_revert_to_replicated_snapshot(self, use_snap_provider_location):
replica_list, snapshot_list = self._get_fake_replicas_and_snapshots()
fake_replica, fake_replica_2, fake_replica_3 = replica_list
fake_snapshot, fake_snapshot_2, fake_snapshot_3 = snapshot_list
if not use_snap_provider_location:
del fake_snapshot['provider_location']
del fake_snapshot_2['provider_location']
del fake_snapshot_3['provider_location']
share_name = self.library._get_backend_share_name(
fake_snapshot['share_id'])
snapshot_name = self.library._get_backend_snapshot_name(

View File

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