]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix capacity report error in Huawei driver
authorWilson Liu <liuxinguo@huawei.com>
Tue, 22 Sep 2015 12:52:36 +0000 (20:52 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Mon, 5 Oct 2015 09:44:17 +0000 (17:44 +0800)
Currently the capacity report is incorrect due
to wrong way code clear.

The previously right way is:
result = var / 1024.0 / 1024.0 / 2

But currently we use a constant CAPACITY_UNIT to make the code cleaner
like this:
CAPACITY_UNIT = 1024.0 / 1024.0 / 2
result = var / CAPACITY_UNIT
We want the CAPACITY_UNIT work like a *real* constant like C
language, but in python, it is not a *real* constant, it's
just a variable. It will calculate the CAPACITY_UNIT first,
so the finally result is:
result = var / 0.5
And this is wrong.

This patch will fix this.

Closes-Bug: #1498452
Change-Id: I4dc20ef8805d7c414fedb1dc441deb3f9fcd75b5

cinder/tests/unit/test_huawei_drivers.py
cinder/volume/drivers/huawei/constants.py

index c15b289fb714c212b40b830c946bab34afd327ab..4a53a3913b54e09aab6ead806f03cc63023b21f2 100644 (file)
@@ -1758,6 +1758,11 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase):
         url.appendChild(url_text)
         storage.appendChild(url)
 
+        storagepool = doc.createElement('StoragePool')
+        pool_text = doc.createTextNode('OpenStack_Pool')
+        storagepool.appendChild(pool_text)
+        storage.appendChild(storagepool)
+
         lun = doc.createElement('LUN')
         config.appendChild(lun)
         storagepool = doc.createElement('StoragePool')
@@ -2206,6 +2211,17 @@ class Huawei18000FCDriverTestCase(test.TestCase):
         re = self.driver.restclient._get_id_from_result(result, name, key)
         self.assertEqual('1', re)
 
+    @mock.patch.object(rest_client.RestClient, 'find_pool_info',
+                       return_value={'ID': 1,
+                                     'CAPACITY': 110362624,
+                                     'TOTALCAPACITY': 209715200})
+    def test_get_capacity(self, mock_find_pool_info):
+        expected_pool_capacity = {'total_capacity': 100.0,
+                                  'free_capacity': 52.625}
+        pool_capacity = self.driver.restclient._get_capacity(None,
+                                                             None)
+        self.assertEqual(expected_pool_capacity, pool_capacity)
+
     def create_fake_conf_file(self):
         """Create a fake Config file
 
@@ -2249,6 +2265,11 @@ class Huawei18000FCDriverTestCase(test.TestCase):
         url.appendChild(url_text)
         storage.appendChild(url)
 
+        storagepool = doc.createElement('StoragePool')
+        pool_text = doc.createTextNode('OpenStack_Pool')
+        storagepool.appendChild(pool_text)
+        storage.appendChild(storagepool)
+
         lun = doc.createElement('LUN')
         config.appendChild(lun)
         storagepool = doc.createElement('StoragePool')
index f2174ba5fc079c73da36bed359cba14a9d3bd405..4e3eb5cd78d3ae814b319adffe24d2dbed864e37 100644 (file)
@@ -29,7 +29,7 @@ QOS_NAME_PREFIX = 'OpenStack_'
 ARRAY_VERSION = 'V300R003C00'
 FC_PORT_CONNECTED = '10'
 FC_INIT_ONLINE = '27'
-CAPACITY_UNIT = 1024.0 / 1024.0 / 2
+CAPACITY_UNIT = 1024.0 * 1024.0 * 2
 DEFAULT_WAIT_TIMEOUT = 3600 * 24 * 30
 DEFAULT_WAIT_INTERVAL = 5