diff --git a/cinder/tests/unit/volume/drivers/test_nfs.py b/cinder/tests/unit/volume/drivers/test_nfs.py index 1ead034d7cf..f0efecdfe5e 100644 --- a/cinder/tests/unit/volume/drivers/test_nfs.py +++ b/cinder/tests/unit/volume/drivers/test_nfs.py @@ -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'] diff --git a/cinder/volume/drivers/remotefs.py b/cinder/volume/drivers/remotefs.py index ebb19732510..01c04adb305 100644 --- a/cinder/volume/drivers/remotefs.py +++ b/cinder/volume/drivers/remotefs.py @@ -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() diff --git a/releasenotes/notes/bug-1888951-backup-from-nfs-snapshot-2e06235eb318b852.yaml b/releasenotes/notes/bug-1888951-backup-from-nfs-snapshot-2e06235eb318b852.yaml new file mode 100644 index 00000000000..3f63402b5be --- /dev/null +++ b/releasenotes/notes/bug-1888951-backup-from-nfs-snapshot-2e06235eb318b852.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + `Bug #1888951 `_: + Fixed an issue with creating a backup from snapshot with NFS volume + driver.