Fixed an issue with creating a backup from snapshot with NFS volume driver.

Change-Id: Ib198372bf3e125a88d607c71377c95a24ab584ad
Closes-Bug: 1888951
This commit is contained in:
Alex Deiter 2020-07-25 18:18:14 +00:00
parent 2f600816a1
commit a21bf41413
3 changed files with 22 additions and 12 deletions

View File

@ -1332,12 +1332,13 @@ class NfsDriverTestCase(test.TestCase):
run_as_root=True)
mock_permission.assert_called_once_with(dest_vol_path)
@ddt.data([NFS_CONFIG1, QEMU_IMG_INFO_OUT3],
[NFS_CONFIG2, QEMU_IMG_INFO_OUT4],
[NFS_CONFIG3, QEMU_IMG_INFO_OUT3],
[NFS_CONFIG4, QEMU_IMG_INFO_OUT4])
@ddt.data([NFS_CONFIG1, QEMU_IMG_INFO_OUT3, 'available'],
[NFS_CONFIG2, QEMU_IMG_INFO_OUT4, 'backing-up'],
[NFS_CONFIG3, QEMU_IMG_INFO_OUT3, 'available'],
[NFS_CONFIG4, QEMU_IMG_INFO_OUT4, 'backing-up'])
@ddt.unpack
def test_create_volume_from_snapshot(self, nfs_conf, qemu_img_info):
def test_create_volume_from_snapshot(self, nfs_conf, qemu_img_info,
snap_status):
self._set_driver(extra_confs=nfs_conf)
drv = self._driver
@ -1354,7 +1355,7 @@ class NfsDriverTestCase(test.TestCase):
# Fake snapshot based in the previous created volume
snap_file = src_volume.name + '.' + fake_snap.id
fake_snap.volume = src_volume
fake_snap.status = 'available'
fake_snap.status = snap_status
fake_snap.size = 10
# New fake volume where the snap will be copied
@ -1397,7 +1398,9 @@ class NfsDriverTestCase(test.TestCase):
mock_ensure.assert_called_once()
mock_find_share.assert_called_once_with(new_volume)
def test_create_volume_from_snapshot_status_not_available(self):
@ddt.data('error', 'creating', 'deleting', 'deleted', 'updating',
'error_deleting', 'unmanaging', 'restoring')
def test_create_volume_from_snapshot_invalid_status(self, snap_status):
"""Expect an error when the snapshot's status is not 'available'."""
self._set_driver()
drv = self._driver
@ -1406,6 +1409,7 @@ class NfsDriverTestCase(test.TestCase):
fake_snap = fake_snapshot.fake_snapshot_obj(self.context)
fake_snap.volume = src_volume
fake_snap.status = snap_status
new_volume = self._simple_volume()
new_volume['size'] = fake_snap['volume_size']

View File

@ -1377,11 +1377,11 @@ class RemoteFSSnapDriverBase(RemoteFSDriver):
LOG.debug('Creating volume %(vol)s from snapshot %(snap)s',
{'vol': volume.id, 'snap': snapshot.id})
if snapshot.status != 'available':
msg = _('Snapshot status must be "available" to clone. '
'But is: %(status)s') % {'status': snapshot.status}
raise exception.InvalidSnapshot(msg)
status = snapshot.status
acceptable_states = ['available', 'backing-up']
self._validate_state(status, acceptable_states,
obj_description='snapshot',
invalid_exc=exception.InvalidSnapshot)
self._ensure_shares_mounted()

View File

@ -0,0 +1,6 @@
---
fixes:
- |
`Bug #1888951 <https://bugs.launchpad.net/cinder/+bug/1888951>`_:
Fixed an issue with creating a backup from snapshot with NFS volume
driver.