Merge "Bug fix for revert to snapshot feature"

This commit is contained in:
Zuul 2021-03-23 15:47:31 +00:00 committed by Gerrit Code Review
commit f9c2b3159d
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',
'last_snap': {'snap_id': fake.SNAPSHOT_ID}}
FAKE_SNAP_INFO_REVERT = {'name': 'testsnap',
'id': fake.SNAPSHOT2_ID}
FAKE_CREATE_VOLUME_NEGATIVE_RESPONSE = exception.VolumeBackendAPIException(
"Volume testvolume not found")
@ -1274,17 +1277,20 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
FAKE_GET_VOL_INFO_REVERT)
self.mock_client_service.get_netconfig.return_value = (
FAKE_POSITIVE_NETCONFIG_RESPONSE)
self.mock_client_service.get_snap_info.return_value = (
FAKE_SNAP_INFO_REVERT)
ctx = context.get_admin_context()
self.driver.revert_to_snapshot(ctx,
{'id': fake.VOLUME_ID,
'size': 1,
'name': 'testvolume'},
{'id': fake.SNAPSHOT_ID,
{'id': fake.SNAPSHOT2_ID,
'name': 'testsnap',
'volume_id': fake.VOLUME_ID})
expected_calls = [mock.call.online_vol('testvolume', False),
mock.call.volume_restore('testvolume',
{'data': {'id': fake.VOLUME_ID,
'base_snap_id': fake.SNAPSHOT_ID}}),
'base_snap_id': fake.SNAPSHOT2_ID}}),
mock.call.online_vol('testvolume', True)]
self.mock_client_service.assert_has_calls(expected_calls)
@ -1301,6 +1307,8 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
FAKE_GET_VOL_INFO_REVERT)
self.mock_client_service.get_netconfig.return_value = (
FAKE_POSITIVE_NETCONFIG_RESPONSE)
self.mock_client_service.get_snap_info.return_value = (
FAKE_SNAP_INFO_REVERT)
ctx = context.get_admin_context()
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.revert_to_snapshot, ctx,
@ -1308,6 +1316,7 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase):
'size': 1,
'name': 'testvolume'},
{'id': fake.SNAPSHOT_ID,
'name': 'testsnap',
'volume_id': fake.VOLUME_ID})

View File

@ -755,7 +755,9 @@ class NimbleBaseVolumeDriver(san.SanDriver):
def revert_to_snapshot(self, context, volume, snapshot):
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']
LOG.debug("Reverting volume %(vol)s with snapshot id %(snap_id)s",
{'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.