From d93ca8b7f888a54004825542924280608e62f689 Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Thu, 24 Sep 2015 18:05:11 +0800 Subject: [PATCH] Fix update Huawei driver issue If a volume is created with old version of Huawei driver, there is no pool info related to the volume, but the new version of Huawei driver assumes that the volume have the pool info and will read the pool info from the volume, and then the read fails. This will happen when we call create_volume_from_snapshot() in new version of Huawei driver when the volume is created by old version of Huawei driver. Closes-bug: #1499251 Change-Id: I296f6354340e1a3698d8a284c9aa2a444c73771d --- cinder/tests/unit/test_huawei_drivers.py | 37 ++++++++++++++++++- cinder/volume/drivers/huawei/huawei_driver.py | 13 +++++-- cinder/volume/drivers/huawei/huawei_utils.py | 12 ++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index a7327132a..c15b289fb 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -70,6 +70,7 @@ test_snap = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', 'display_description': 'test volume', 'volume_type_id': None, 'provider_location': '11', + 'volume': {"volume_id": '21ec7341-9256-497b-97d9-ef48edcf0635'}, 'volume': {'provider_location': '12'}, } @@ -1391,6 +1392,38 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase): def test_create_volume_success(self): self.driver.restclient.login() + + # Have pool info in the volume. + test_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', + 'size': 2, + 'volume_name': 'vol1', + 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', + 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', + 'provider_auth': None, + 'project_id': 'project', + 'display_name': 'vol1', + 'display_description': 'test volume', + 'volume_type_id': None, + 'host': 'ubuntu001@backend001#OpenStack_Pool', + 'provider_location': '11', + } + lun_info = self.driver.create_volume(test_volume) + self.assertEqual('1', lun_info['provider_location']) + + # No pool info in the volume. + test_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', + 'size': 2, + 'volume_name': 'vol1', + 'id': '21ec7341-9256-497b-97d9-ef48edcf0635', + 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0635', + 'provider_auth': None, + 'project_id': 'project', + 'display_name': 'vol1', + 'display_description': 'test volume', + 'volume_type_id': None, + 'host': 'ubuntu001@backend001', + 'provider_location': '11', + } lun_info = self.driver.create_volume(test_volume) self.assertEqual('1', lun_info['provider_location']) @@ -1728,7 +1761,7 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase): lun = doc.createElement('LUN') config.appendChild(lun) storagepool = doc.createElement('StoragePool') - pool_text = doc.createTextNode('OpenStack_Pool') + pool_text = doc.createTextNode('OpenStack_Pool;OpenStack_Pool2') storagepool.appendChild(pool_text) lun.appendChild(storagepool) @@ -2219,7 +2252,7 @@ class Huawei18000FCDriverTestCase(test.TestCase): lun = doc.createElement('LUN') config.appendChild(lun) storagepool = doc.createElement('StoragePool') - pool_text = doc.createTextNode('OpenStack_Pool') + pool_text = doc.createTextNode('OpenStack_Pool;OpenStack_Pool2') storagepool.appendChild(pool_text) lun.appendChild(storagepool) diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py index 2a5d94aa2..90b269420 100644 --- a/cinder/volume/drivers/huawei/huawei_driver.py +++ b/cinder/volume/drivers/huawei/huawei_driver.py @@ -83,10 +83,15 @@ class HuaweiBaseDriver(driver.VolumeDriver): pools = self.restclient.find_all_pools() pool_info = self.restclient.find_pool_info(pool_name, pools) if not pool_info: - msg = (_('Error in getting pool information for the pool: %s.') - % pool_name) - LOG.error(msg) - raise exception.VolumeBackendAPIException(data=msg) + # The following code is to keep compatibility with old version of + # Huawei driver. + pool_names = huawei_utils.get_pools(self.xml_file_path) + for pool_name in pool_names.split(";"): + pool_info = self.restclient.find_pool_info(pool_name, + pools) + if pool_info: + break + volume_name = huawei_utils.encode_name(volume['id']) volume_description = volume['name'] volume_size = huawei_utils.get_volume_size(volume) diff --git a/cinder/volume/drivers/huawei/huawei_utils.py b/cinder/volume/drivers/huawei/huawei_utils.py index a82f7da4e..bb55b369c 100644 --- a/cinder/volume/drivers/huawei/huawei_utils.py +++ b/cinder/volume/drivers/huawei/huawei_utils.py @@ -527,3 +527,15 @@ def get_protocol(xml_file_path): raise exception.InvalidInput(reason=err_msg) return protocol + + +def get_pools(xml_file_path): + """Get pools from huawei conf file.""" + root = parse_xml_file(xml_file_path) + pool_names = root.findtext('LUN/StoragePool') + if not pool_names: + msg = _('Invalid resource pool name. ' + 'Please check the config file.') + LOG.error(msg) + raise exception.InvalidInput(msg) + return pool_names -- 2.45.2