]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
PureISCSIDriver:Handle delete called on already deleted volume
authorMudassir Latif <mudassir.latif@purestorage.com>
Tue, 25 Nov 2014 03:00:47 +0000 (19:00 -0800)
committerMudassir Latif <mudassir.latif@purestorage.com>
Tue, 25 Nov 2014 20:09:54 +0000 (12:09 -0800)
If the delete_volume method gets an error from Purity
saying volume does not exist, don't proceed with attempt
at deletion

Change-Id: I2a830e43c876433da4cdb50eabe4fb66b7eb6faf
Closes-Bug: #1395826

cinder/tests/test_pure.py
cinder/volume/drivers/pure.py

index f2081d9d64342de49ad4c5b9be0c0fc649032be4..7e650c02eb7e82472c2f7d927a2178aa0e5cb4d0 100644 (file)
@@ -199,6 +199,24 @@ class PureISCSIDriverTestCase(test.TestCase):
             self.driver.create_cloned_volume, VOLUME, SRC_VOL)
         SRC_VOL["size"] = 2  # reset size
 
+    def test_delete_volume_already_deleted(self):
+        self.array.list_volume_hosts.side_effect = exception.PureAPIException(
+            code=400, reason="Volume does not exist")
+        self.driver.delete_volume(VOLUME)
+        self.assertFalse(self.array.destroy_volume.called)
+        self.array.list_volume_hosts.side_effect = None
+        self.assert_error_propagates([self.array.destroy_volume],
+                                     self.driver.delete_volume, VOLUME)
+        # Testing case where array.destroy_volume returns an exception
+        #  because volume already deleted
+        self.array.destroy_volume.side_effect = exception.PureAPIException(
+            code=400, reason="Volume does not exist")
+        self.driver.delete_volume(VOLUME)
+        self.assertTrue(self.array.destroy_volume.called)
+        self.array.destroy_volume.side_effect = None
+        self.assert_error_propagates([self.array.destroy_volume],
+                                     self.driver.delete_volume, VOLUME)
+
     def test_delete_volume(self):
         vol_name = VOLUME["name"] + "-cinder"
         self.driver.delete_volume(VOLUME)
index 46d6f3678897dedd5b1fb3910c81c6413f665aa6..2a2d7944c5335713dfd65db761c27342806b7925 100644 (file)
@@ -133,21 +133,20 @@ class PureISCSIDriver(san.SanISCSIDriver):
         """Disconnect all hosts and delete the volume"""
         LOG.debug("Enter PureISCSIDriver.delete_volume.")
         vol_name = _get_vol_name(volume)
-
-        connected_hosts = self._array.list_volume_hosts(vol_name)
-        for host_info in connected_hosts:
-            host_name = host_info["host"]
-            self._disconnect_host(host_name, vol_name)
-
         try:
+            connected_hosts = self._array.list_volume_hosts(vol_name)
+            for host_info in connected_hosts:
+                host_name = host_info["host"]
+                self._disconnect_host(host_name, vol_name)
             self._array.destroy_volume(vol_name)
         except exception.PureAPIException as err:
             with excutils.save_and_reraise_exception() as ctxt:
-                if err.kwargs["code"] == 400:
+                if err.kwargs["code"] == 400 and \
+                        "Volume does not exist" in err.msg:
                     # Happens if the volume does not exist.
                     ctxt.reraise = False
-                    LOG.error(_LE("Volume deletion failed with message: %s") %
-                              err.msg)
+                    LOG.warn(_LW("Volume deletion failed with message: %s")
+                             % err.msg)
         LOG.debug("Leave PureISCSIDriver.delete_volume.")
 
     def create_snapshot(self, snapshot):