]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix update Huawei driver issue
authorWilson Liu <liuxinguo@huawei.com>
Thu, 24 Sep 2015 10:05:11 +0000 (18:05 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Tue, 29 Sep 2015 03:30:52 +0000 (11:30 +0800)
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
cinder/volume/drivers/huawei/huawei_driver.py
cinder/volume/drivers/huawei/huawei_utils.py

index a7327132a3e28f2293fe24ad7e5c2394abd982ee..c15b289fb714c212b40b830c946bab34afd327ab 100644 (file)
@@ -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)
 
index 2a5d94aa24914b497f6931c2f8e729ff157ebf3f..90b269420be8c0122c24592f1a0ef10ac91e4910 100644 (file)
@@ -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)
index a82f7da4eef6f2917ff2d9349d9d52b717c0d898..bb55b369cddf8a4543358739047f1ff9fe3650a2 100644 (file)
@@ -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