From: Yuriy Nesenenko Date: Thu, 27 Aug 2015 14:39:10 +0000 (+0300) Subject: Add retries to delete a volume in the RBD driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e6a8cc3eb021d01b4341a5887d1d514247c6e2ca;p=openstack-build%2Fcinder-build.git Add retries to delete a volume in the RBD driver This patch adds retries to delete a volume. After N tries of a volume deletion failed we raise VolumeIsBusy exception. Change-Id: I9499be0c5985f9e8a3e55d1c9add01ad5cd11789 --- diff --git a/cinder/tests/unit/test_rbd.py b/cinder/tests/unit/test_rbd.py index 434ca109e..101d05b3c 100644 --- a/cinder/tests/unit/test_rbd.py +++ b/cinder/tests/unit/test_rbd.py @@ -313,10 +313,10 @@ class RBDTestCase(test.TestCase): self.assertFalse( self.mock_rbd.Image.return_value.unprotect_snap.called) self.assertEqual( - 1, self.mock_rbd.RBD.return_value.remove.call_count) + 3, self.mock_rbd.RBD.return_value.remove.call_count) + self.assertEqual(3, len(RAISED_EXCEPTIONS)) # Make sure the exception was raised - self.assertEqual(RAISED_EXCEPTIONS, - [self.mock_rbd.ImageBusy]) + self.assertIn(self.mock_rbd.ImageBusy, RAISED_EXCEPTIONS) @common_mocks def test_delete_volume_not_found(self): diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index 72a914228..71e766d00 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -699,10 +699,14 @@ class RBDDriver(driver.TransferVD, driver.ExtendVD, finally: rbd_image.close() + @utils.retry(self.rbd.ImageBusy, retries=3) + def _try_remove_volume(client, volume_name): + self.RBDProxy().remove(client.ioctx, volume_name) + if clone_snap is None: LOG.debug("deleting rbd volume %s", volume_name) try: - self.RBDProxy().remove(client.ioctx, volume_name) + _try_remove_volume(client, volume_name) except self.rbd.ImageBusy: msg = (_("ImageBusy error raised while deleting rbd " "volume. This may have been caused by a "