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',
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'
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."""