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
This commit is contained in:
Wilson Liu 2015-09-22 20:52:36 +08:00
parent a9aab612c0
commit 3a12a256a1
2 changed files with 22 additions and 1 deletions

View 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')

View 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