Bug fix for revert to snapshot feature

Snapshot information should be retrieved from the snapshot API
instead of retrieving volume's last_snap

Closes-bug: #1918099
Change-Id: Iee7d2e8d935a806f92f3991a943a458f5b74ef48
This commit is contained in:
Ajitha Robert 2021-03-08 18:46:00 -08:00
parent a1f567e3b3
commit 77127e7d46
3 changed files with 20 additions and 3 deletions

View File

@ -167,6 +167,9 @@ FAKE_GET_VOL_INFO_REVERT = {'name': 'testvolume',
'agent_type': 'openstack', 'agent_type': 'openstack',
'last_snap': {'snap_id': fake.SNAPSHOT_ID}} 'last_snap': {'snap_id': fake.SNAPSHOT_ID}}
FAKE_SNAP_INFO_REVERT = {'name': 'testsnap',
'id': fake.SNAPSHOT2_ID}
FAKE_CREATE_VOLUME_NEGATIVE_RESPONSE = exception.VolumeBackendAPIException( FAKE_CREATE_VOLUME_NEGATIVE_RESPONSE = exception.VolumeBackendAPIException(
"Volume testvolume not found") "Volume testvolume not found")
@ -1274,17 +1277,20 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
FAKE_GET_VOL_INFO_REVERT) FAKE_GET_VOL_INFO_REVERT)
self.mock_client_service.get_netconfig.return_value = ( self.mock_client_service.get_netconfig.return_value = (
FAKE_POSITIVE_NETCONFIG_RESPONSE) FAKE_POSITIVE_NETCONFIG_RESPONSE)
self.mock_client_service.get_snap_info.return_value = (
FAKE_SNAP_INFO_REVERT)
ctx = context.get_admin_context() ctx = context.get_admin_context()
self.driver.revert_to_snapshot(ctx, self.driver.revert_to_snapshot(ctx,
{'id': fake.VOLUME_ID, {'id': fake.VOLUME_ID,
'size': 1, 'size': 1,
'name': 'testvolume'}, 'name': 'testvolume'},
{'id': fake.SNAPSHOT_ID, {'id': fake.SNAPSHOT2_ID,
'name': 'testsnap',
'volume_id': fake.VOLUME_ID}) 'volume_id': fake.VOLUME_ID})
expected_calls = [mock.call.online_vol('testvolume', False), expected_calls = [mock.call.online_vol('testvolume', False),
mock.call.volume_restore('testvolume', mock.call.volume_restore('testvolume',
{'data': {'id': fake.VOLUME_ID, {'data': {'id': fake.VOLUME_ID,
'base_snap_id': fake.SNAPSHOT_ID}}), 'base_snap_id': fake.SNAPSHOT2_ID}}),
mock.call.online_vol('testvolume', True)] mock.call.online_vol('testvolume', True)]
self.mock_client_service.assert_has_calls(expected_calls) self.mock_client_service.assert_has_calls(expected_calls)
@ -1301,6 +1307,8 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
FAKE_GET_VOL_INFO_REVERT) FAKE_GET_VOL_INFO_REVERT)
self.mock_client_service.get_netconfig.return_value = ( self.mock_client_service.get_netconfig.return_value = (
FAKE_POSITIVE_NETCONFIG_RESPONSE) FAKE_POSITIVE_NETCONFIG_RESPONSE)
self.mock_client_service.get_snap_info.return_value = (
FAKE_SNAP_INFO_REVERT)
ctx = context.get_admin_context() ctx = context.get_admin_context()
self.assertRaises(exception.VolumeBackendAPIException, self.assertRaises(exception.VolumeBackendAPIException,
self.driver.revert_to_snapshot, ctx, self.driver.revert_to_snapshot, ctx,
@ -1308,6 +1316,7 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
'size': 1, 'size': 1,
'name': 'testvolume'}, 'name': 'testvolume'},
{'id': fake.SNAPSHOT_ID, {'id': fake.SNAPSHOT_ID,
'name': 'testsnap',
'volume_id': fake.VOLUME_ID}) 'volume_id': fake.VOLUME_ID})

View File

@ -755,7 +755,9 @@ class NimbleBaseVolumeDriver(san.SanDriver):
def revert_to_snapshot(self, context, volume, snapshot): def revert_to_snapshot(self, context, volume, snapshot):
vol_info = self.APIExecutor.get_vol_info(volume['name']) vol_info = self.APIExecutor.get_vol_info(volume['name'])
snap_id = vol_info['last_snap']['snap_id'] snap_info = self.APIExecutor.get_snap_info(snapshot['name'],
volume['name'])
snap_id = snap_info['id']
volume_id = vol_info['id'] volume_id = vol_info['id']
LOG.debug("Reverting volume %(vol)s with snapshot id %(snap_id)s", LOG.debug("Reverting volume %(vol)s with snapshot id %(snap_id)s",
{'vol': volume['name'], 'snap_id': snap_id}) {'vol': volume['name'], 'snap_id': snap_id})

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Nimble driver `bug #1918099
<https://bugs.launchpad.net/cinder/+bug/1918099>`_: Fix
revert to snapshot not working as expected.