Skip to content

Commit

Permalink
CoraidDriver: Allow volumes in error state to be deleted
Browse files Browse the repository at this point in the history
This fix will allow the delete call to be successfull if volume
doesn't exists on the SAN.

Fixes bug 1195788

Change-Id: I0396f1252c8faafff3e8b4f9a4aeffb930350a8d
  • Loading branch information
Jean-Baptiste Ransy committed Jul 16, 2013
1 parent 5be6852 commit 8a042e0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
32 changes: 29 additions & 3 deletions cinder/tests/test_coraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,41 @@ def test_create_lun(self):
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',
Expand Down
34 changes: 26 additions & 8 deletions cinder/volume/drivers/coraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ def _admin_esm_cmd(self, url=False, data=None):
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'
Expand Down Expand Up @@ -217,14 +228,21 @@ def create_lun(self, volume_name, volume_size, repository):

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."""
Expand Down

0 comments on commit 8a042e0

Please sign in to comment.