]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix to allow RBD delete an unprotected snapshot
authorYuriy Nesenenko <ynesenenko@mirantis.com>
Mon, 28 Dec 2015 13:35:47 +0000 (15:35 +0200)
committerYuriy Nesenenko <ynesenenko@mirantis.com>
Mon, 28 Dec 2015 17:10:14 +0000 (19:10 +0200)
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
cinder/volume/drivers/rbd.py

index a163dfb352b16fc0325701801dba4a98024bd800..6b75ba844104f40bea921d2e20cf89a2cfaf90a9 100644 (file)
@@ -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
index c1baca5b01cc41af236672149b3a32d057b9f791..2b67b790dc0276974ca19cbc7bda687fe439271e 100644 (file)
@@ -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)