]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
CoraidDriver: Allow volumes in error state to be deleted
authorJean-Baptiste Ransy <jean-baptiste.ransy@alyseo.com>
Fri, 12 Jul 2013 13:41:12 +0000 (15:41 +0200)
committerJean-Baptiste Ransy <jean-baptiste.ransy@alyseo.com>
Tue, 16 Jul 2013 17:41:20 +0000 (19:41 +0200)
This fix will allow the delete call to be successfull if volume
doesn't exists on the SAN.

Fixes bug 1195788

Change-Id: I0396f1252c8faafff3e8b4f9a4aeffb930350a8d

cinder/tests/test_coraid.py
cinder/volume/drivers/coraid.py

index 793eeca18655fdcbdd3cf7042a5f2c095188a3de..e2cb275c93b4265e7658dd5331354d43a918d790 100644 (file)
@@ -249,15 +249,41 @@ class TestCoraidRESTClient(test.TestCase):
         self.drv.create_lun(fake_volume_name, '10',
                             fake_repository_name)
 
-    def test_delete_lun(self):
+    def test_delete_lun_ok(self):
+        """Test Delete Volume classic case."""
         setattr(self.rest_mock, 'delete_lun',
-                lambda *_: True)
+                lambda *_: self.mox.CreateMockAnything())
         self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                        lambda *_: fake_volume_info)
         self.stubs.Set(CoraidRESTClient, '_configure',
                        lambda *_: fake_esm_success)
         self.rest_mock.delete_lun(fake_volume_name)
-        self.drv.delete_lun(fake_volume_name)
+        result = self.drv.delete_lun(fake_volume_name)
+        self.assertTrue(result)
+
+    def test_delete_lun_in_error(self):
+        """Test Delete Volume in Error State."""
+        setattr(self.rest_mock, 'delete_lun',
+                lambda *_: self.mox.CreateMockAnything())
+        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
+                       lambda *_: Exception)
+        self.stubs.Set(CoraidRESTClient, '_check_esm_alive',
+                       lambda *_: True)
+        self.rest_mock.delete_lun(fake_volume_name)
+        result = self.drv.delete_lun(fake_volume_name)
+        self.assertTrue(result)
+
+    def test_delete_lun_esm_unavailable(self):
+        """Test Delete Volume with ESM Unavailable."""
+        setattr(self.rest_mock, 'delete_lun',
+                lambda *_: self.mox.CreateMockAnything())
+        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
+                       lambda *_: Exception)
+        self.stubs.Set(CoraidRESTClient, '_check_esm_alive',
+                       lambda *_: False)
+        self.rest_mock.delete_lun(fake_volume_name)
+        result = self.drv.delete_lun(fake_volume_name)
+        self.assertRaises(Exception, result)
 
     def test_create_snapshot(self):
         setattr(self.rest_mock, 'create_snapshot',
index db07bb38bf2c1f3d9c5f5d6d15c6f1175e2099a0..ed9c614dacf29fdca6dbf5bbd6eeca377615f9c0 100644 (file)
@@ -166,6 +166,17 @@ class CoraidRESTClient(object):
         else:
             raise CoraidRESTException(_('Request without URL'))
 
+    def _check_esm_alive(self):
+        try:
+            url = self.url + 'fetch'
+            req = urllib2.Request(url)
+            code = self.urlOpener.open(req).getcode()
+            if code == '200':
+                return True
+            return False
+        except Exception:
+            return False
+
     def _configure(self, data):
         """In charge of all commands into 'configure'."""
         url = 'configure'
@@ -217,14 +228,21 @@ class CoraidRESTClient(object):
 
     def delete_lun(self, volume_name):
         """Delete LUN."""
-        volume_info = self._get_volume_info(volume_name)
-        repository = volume_info['repo']
-        data = '[{"addr":"cms","data":"{' \
-               '\\"repoName\\":\\"%s\\",' \
-               '\\"lvName\\":\\"%s\\"}",' \
-               '"op":"orchStrLun/verified",' \
-               '"args":"delete"}]' % (repository, volume_name)
-        return self._configure(data)
+        try:
+            volume_info = self._get_volume_info(volume_name)
+            repository = volume_info['repo']
+            data = '[{"addr":"cms","data":"{' \
+                   '\\"repoName\\":\\"%(repo)s\\",' \
+                   '\\"lvName\\":\\"%(volname)s\\"}",' \
+                   '"op":"orchStrLun/verified",' \
+                   '"args":"delete"}]' % dict(repo=repository,
+                                              volname=volume_name)
+            return self._configure(data)
+        except Exception:
+            if self._check_esm_alive():
+                return True
+            else:
+                return False
 
     def create_snapshot(self, volume_name, snapshot_name):
         """Create Snapshot."""