From 61bf5d86d00025fbe44582693ca4e8858bd4301e Mon Sep 17 00:00:00 2001 From: Yuriy Nesenenko Date: Mon, 28 Dec 2015 15:35:47 +0200 Subject: [PATCH] Fix to allow RBD delete an unprotected snapshot RBD creates snapshots and marks it as protected. Before deleting, RBD tries to 'unprotect' a snapshot. In the case when the snapshot was already marked as 'unprotected' RBD failed to remove it. This patch allow RBD delete such a snapshot. Change-Id: Ic1ea72cc107c2eb949c5748a309f0a8956ea8082 Closes-Bug: 1529626 --- cinder/tests/unit/test_rbd.py | 11 +++++++++++ cinder/volume/drivers/rbd.py | 2 ++ 2 files changed, 13 insertions(+) diff --git a/cinder/tests/unit/test_rbd.py b/cinder/tests/unit/test_rbd.py index a163dfb35..6b75ba844 100644 --- a/cinder/tests/unit/test_rbd.py +++ b/cinder/tests/unit/test_rbd.py @@ -83,6 +83,7 @@ def common_mocks(f): inst.mock_rbd.ImageBusy = MockImageBusyException inst.mock_rbd.ImageNotFound = MockImageNotFoundException inst.mock_rbd.ImageExists = MockImageExistsException + inst.mock_rbd.InvalidArgument = MockImageNotFoundException inst.driver.rbd = inst.mock_rbd inst.driver.rados = inst.mock_rados @@ -385,6 +386,16 @@ class RBDTestCase(test.TestCase): proxy.remove_snap.assert_called_with(self.snapshot_name) proxy.unprotect_snap.assert_called_with(self.snapshot_name) + @common_mocks + def test_delete_unprotected_snapshot(self): + proxy = self.mock_proxy.return_value + proxy.__enter__.return_value = proxy + proxy.unprotect_snap.side_effect = self.mock_rbd.InvalidArgument + + self.driver.delete_snapshot(self.snapshot) + self.assertTrue(proxy.unprotect_snap.called) + self.assertTrue(proxy.remove_snap.called) + @common_mocks def test_delete_busy_snapshot(self): proxy = self.mock_proxy.return_value diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index c1baca5b0..2b67b790d 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -749,6 +749,8 @@ class RBDDriver(driver.TransferVD, driver.ExtendVD, with RBDVolumeProxy(self, volume_name) as volume: try: volume.unprotect_snap(snap_name) + except self.rbd.InvalidArgument: + LOG.info(_LI("Unable to unprotect snapshot %s."), snap_name) except self.rbd.ImageNotFound: LOG.info(_LI("Snapshot %s does not exist in backend."), snap_name) -- 2.45.2