From 3a12a256a1d95a86939afb63d7fafa717becdb86 Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Tue, 22 Sep 2015 20:52:36 +0800 Subject: [PATCH] Fix capacity report error in Huawei driver 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 | 21 +++++++++++++++++++++ cinder/volume/drivers/huawei/constants.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index c15b289fb..4a53a3913 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -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') diff --git a/cinder/volume/drivers/huawei/constants.py b/cinder/volume/drivers/huawei/constants.py index f2174ba5f..4e3eb5cd7 100644 --- a/cinder/volume/drivers/huawei/constants.py +++ b/cinder/volume/drivers/huawei/constants.py @@ -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 -- 2.45.2