From: Jean-Baptiste Ransy Date: Fri, 12 Jul 2013 13:41:12 +0000 (+0200) Subject: CoraidDriver: Allow volumes in error state to be deleted X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8a042e0732fbac24e412306d337c0742b681cfc2;p=openstack-build%2Fcinder-build.git CoraidDriver: Allow volumes in error state to be deleted This fix will allow the delete call to be successfull if volume doesn't exists on the SAN. Fixes bug 1195788 Change-Id: I0396f1252c8faafff3e8b4f9a4aeffb930350a8d --- diff --git a/cinder/tests/test_coraid.py b/cinder/tests/test_coraid.py index 793eeca18..e2cb275c9 100644 --- a/cinder/tests/test_coraid.py +++ b/cinder/tests/test_coraid.py @@ -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', diff --git a/cinder/volume/drivers/coraid.py b/cinder/volume/drivers/coraid.py index db07bb38b..ed9c614da 100644 --- a/cinder/volume/drivers/coraid.py +++ b/cinder/volume/drivers/coraid.py @@ -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."""