From e28e87258351c4c0d261d7c04ce495ef73e1520c Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Thu, 24 Sep 2015 16:52:31 +0800 Subject: [PATCH] Report *real* free capacity in Huawei driver When we query capacity of a storage pool on Huawei storage, there are two items in the result: one is "USERFREECAPACITY" and the another one is "DATASPACE". In fact the "DATASPACE" is the *real* space we can use to create LUN, the "USERFREECAPACITY" contains some metadata that we can not use to store user data. Closes-Bug: #1499227 Change-Id: I34a8c67dea2a7b7f5a2a693a65c9303b2cc3d972 --- cinder/tests/unit/test_huawei_drivers.py | 33 ++++++++------------- cinder/volume/drivers/huawei/rest_client.py | 3 +- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index 04ee21d08..a7327132a 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -59,20 +59,6 @@ fake_smartx_value = {'smarttier': 'true', 'partitionname': 'partition-test', } -error_volume = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0637', - 'size': 2, - 'volume_name': 'vol2', - 'id': '21ec7341-9256-497b-97d9-ef48edcf0637', - 'volume_id': '21ec7341-9256-497b-97d9-ef48edcf0637', - 'provider_auth': None, - 'project_id': 'project', - 'display_name': 'vol2', - 'display_description': 'test error_volume', - 'volume_type_id': None, - 'host': 'ubuntu@huawei#OpenStack_Pool_error', - 'provider_location': '12', - } - test_snap = {'name': 'volume-21ec7341-9256-497b-97d9-ef48edcf0635', 'size': 1, 'volume_name': 'vol1', @@ -1476,9 +1462,6 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase): self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_volume, test_volume) - self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_volume, error_volume) - def test_delete_volume_fail(self): self.driver.restclient.login() self.driver.restclient.test_fail = True @@ -1608,7 +1591,13 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase): "ID": "1", "USERFREECAPACITY": "37", "USERTOTALCAPACITY": "49", - "USAGETYPE": constants.FILE_SYSTEM_POOL_TYPE}]} + "USAGETYPE": constants.FILE_SYSTEM_POOL_TYPE}, + {"NAME": "test003", + "ID": "0", + "USERFREECAPACITY": "36", + "DATASPACE": "35", + "USERTOTALCAPACITY": "48", + "USAGETYPE": constants.BLOCK_STORAGE_POOL_TYPE}]} pool_name = 'test001' test_info = {'CAPACITY': '36', 'ID': '0', 'TOTALCAPACITY': '48'} pool_info = self.driver.restclient.find_pool_info(pool_name, pools) @@ -1624,6 +1613,11 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase): pool_info = self.driver.restclient.find_pool_info(pool_name, pools) self.assertEqual(test_info, pool_info) + pool_name = 'test003' + test_info = {'CAPACITY': '35', 'ID': '0', 'TOTALCAPACITY': '48'} + pool_info = self.driver.restclient.find_pool_info(pool_name, pools) + self.assertEqual(test_info, pool_info) + def test_get_smartx_specs_opts(self): self.driver.restclient.login() smartx_opts = smartx.SmartX().get_smartx_specs_opts(smarttier_opts) @@ -1877,9 +1871,6 @@ class Huawei18000FCDriverTestCase(test.TestCase): self.assertRaises(exception.VolumeBackendAPIException, self.driver.create_volume, test_volume) - self.assertRaises(exception.VolumeBackendAPIException, - self.driver.create_volume, error_volume) - def test_delete_volume_fail(self): self.driver.restclient.login() self.driver.restclient.test_fail = True diff --git a/cinder/volume/drivers/huawei/rest_client.py b/cinder/volume/drivers/huawei/rest_client.py index e2db78ead..6a94a7799 100644 --- a/cinder/volume/drivers/huawei/rest_client.py +++ b/cinder/volume/drivers/huawei/rest_client.py @@ -216,7 +216,8 @@ class RestClient(object): item['USAGETYPE'] == constants.FILE_SYSTEM_POOL_TYPE): break pool_info['ID'] = item['ID'] - pool_info['CAPACITY'] = item['USERFREECAPACITY'] + pool_info['CAPACITY'] = item.get('DATASPACE', + item['USERFREECAPACITY']) pool_info['TOTALCAPACITY'] = item['USERTOTALCAPACITY'] break return pool_info -- 2.45.2