From 5fecd1450de562d6aeb064df73669311e51ec8f7 Mon Sep 17 00:00:00 2001 From: Alex Deiter Date: Sat, 25 Jul 2020 18:18:14 +0000 Subject: [PATCH] Fixed an issue with creating a backup from snapshot with NFS volume driver. Change-Id: Ib198372bf3e125a88d607c71377c95a24ab584ad Closes-Bug: 1888951 (cherry picked from commit a21bf41413b8e5b56c1a61460039ec7609f45042) (cherry picked from commit d2e9c4a43c6a1f788fa16ab424a27c1689cdfe69) --- cinder/tests/unit/volume/drivers/test_nfs.py | 18 +++++++++++------- cinder/volume/drivers/remotefs.py | 10 +++++----- ...kup-from-nfs-snapshot-2e06235eb318b852.yaml | 6 ++++++ 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 releasenotes/notes/bug-1888951-backup-from-nfs-snapshot-2e06235eb318b852.yaml diff --git a/cinder/tests/unit/volume/drivers/test_nfs.py b/cinder/tests/unit/volume/drivers/test_nfs.py index c5f1570e3b2..28c6c8cf981 100644 --- a/cinder/tests/unit/volume/drivers/test_nfs.py +++ b/cinder/tests/unit/volume/drivers/test_nfs.py @@ -1224,12 +1224,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 @@ -1246,7 +1247,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 @@ -1289,7 +1290,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 @@ -1298,6 +1301,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 4bbc9d0cec6..a0ba35db972 100644 --- a/cinder/volume/drivers/remotefs.py +++ b/cinder/volume/drivers/remotefs.py @@ -1260,11 +1260,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.