From: Jean-Baptiste RANSY Date: Tue, 19 Mar 2013 15:56:21 +0000 (+0100) Subject: CoraidDriver: retrive volume info (improvement) X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=45a4bbdcf9e6c4d337384c0ebeb4d25eb0ec0a8c;p=openstack-build%2Fcinder-build.git CoraidDriver: retrive volume info (improvement) Some portions of code into this method are useless since the REST API on Coraid side has been improved. Fixes bug #1157242 Change-Id: Ie37b5b76710e77acb2acf627c9688e4f931e686c --- diff --git a/cinder/tests/test_coraid.py b/cinder/tests/test_coraid.py index e1db993d4..847d651d1 100644 --- a/cinder/tests/test_coraid.py +++ b/cinder/tests/test_coraid.py @@ -160,7 +160,7 @@ class TestCoraidRESTClient(test.TestCase): def test__get_volume_info(self): setattr(self.rest_mock, '_get_volume_info', - lambda *_: True) + lambda *_: fake_volume_info) self.stubs.Set(CoraidRESTClient, '_esm', lambda *_: fake_esm_fetch) self.drv._get_volume_info(fake_volume_name) diff --git a/cinder/volume/drivers/coraid.py b/cinder/volume/drivers/coraid.py index 8471a0b66..260a48aea 100644 --- a/cinder/volume/drivers/coraid.py +++ b/cinder/volume/drivers/coraid.py @@ -144,31 +144,19 @@ class CoraidRESTClient(object): raise CoraidESMException(msg % dict(message=errmsg)) return False - def _get_volume_info(self, lvname): - """Fetch information for a given Volume or Snapshot.""" - self._login() - url = 'fetch?shelf=cms&orchStrRepo&lv=%s' % (lvname) - response = self._esm(url) - - items = [] - for cmd, reply in response: - if len(reply['reply']) != 0: - items.append(reply['reply']) - - volume_info = False - for item in items[0]: - if item['lv']['name'] == lvname: - volume_info = { - "pool": item['lv']['containingPool'], - "repo": item['repoName'], - "vsxidx": item['lv']['lunIndex'], - "index": item['lv']['lvStatus']['exportedLun']['lun'], - "shelf": item['lv']['lvStatus']['exportedLun']['shelf']} - - if volume_info: - return volume_info - else: - msg = _('Informtion about Volume %(volname)s not found') + def _get_volume_info(self, volume_name): + """Retrive volume informations for a given volume name.""" + url = 'fetch?shelf=cms&orchStrRepo&lv=%s' % (volume_name) + try: + response = self._esm(url) + info = response[0][1]['reply'][0] + return {"pool": info['lv']['containingPool'], + "repo": info['repoName'], + "vsxidx": info['lv']['lunIndex'], + "index": info['lv']['lvStatus']['exportedLun']['lun'], + "shelf": info['lv']['lvStatus']['exportedLun']['shelf']} + except Exception: + msg = _('Unable to retrive volume infos for volume %(volname)s') raise CoraidESMException(msg % dict(volname=volume_name)) def _get_lun_address(self, volume_name):