From: yogeshprasad Date: Wed, 11 Feb 2015 13:52:33 +0000 (+0530) Subject: Fixes total_capacity_gb value in CloudByte driver. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=59c992919064b06daa3c0ac7092d438e527ff7f7;p=openstack-build%2Fcinder-build.git Fixes total_capacity_gb value in CloudByte driver. CloudByte storage returns total capacity value in two formats. One is numeric and the other is alphanumeric. Previously data['total_capacity_gb'] was referring the alphanumeric value & now it is referring to the correct numeric value. In addition, changes were made to test_cloudbyte.py to unit test free_capacity_gb and total_capacity_gb. Closes-Bug: 1420746 Change-Id: I601c2a78c1727bc815771ca26aea928fa2887d09 --- diff --git a/cinder/tests/test_cloudbyte.py b/cinder/tests/test_cloudbyte.py index 1e7855fe5..6c183b31e 100644 --- a/cinder/tests/test_cloudbyte.py +++ b/cinder/tests/test_cloudbyte.py @@ -637,7 +637,7 @@ class CloudByteISCSIDriverTestCase(testtools.TestCase): self.driver = CloudByteISCSIDriver(configuration=configuration) # override some parts of driver configuration - self.driver.configuration.tsm_name = 'openstack' + self.driver.configuration.cb_tsm_name = 'openstack' self.driver.configuration.cb_account_name = 'CustomerA' def _side_effect_api_req(self, cmd, params, version='1.0'): @@ -930,7 +930,7 @@ class CloudByteISCSIDriverTestCase(testtools.TestCase): # assert equality checks for certain configuration attributes self.assertEqual( - 'openstack', self.driver.configuration.tsm_name) + 'openstack', self.driver.configuration.cb_tsm_name) self.assertEqual( 'CustomerA', self.driver.configuration.cb_account_name) self.assertThat( @@ -1179,6 +1179,8 @@ class CloudByteISCSIDriverTestCase(testtools.TestCase): self.assertEqual(1, mock_api_req.call_count) # assert the result attributes with respective values + self.assertEqual(1024.0, vol_stats['total_capacity_gb']) + self.assertEqual(824.0, vol_stats['free_capacity_gb']) self.assertEqual(0, vol_stats['reserved_percentage']) self.assertEqual('CloudByte', vol_stats['vendor_name']) self.assertEqual('iSCSI', vol_stats['storage_protocol']) diff --git a/cinder/volume/drivers/cloudbyte/cloudbyte.py b/cinder/volume/drivers/cloudbyte/cloudbyte.py index c33b9df0a..710874749 100644 --- a/cinder/volume/drivers/cloudbyte/cloudbyte.py +++ b/cinder/volume/drivers/cloudbyte/cloudbyte.py @@ -18,6 +18,7 @@ import json import time import urllib +from oslo_utils import units import six from cinder import exception @@ -563,22 +564,17 @@ class CloudByteISCSIDriver(san.SanISCSIDriver): for tsms in tsm_details: if tsms['name'] == tsmname: flag = 1 - storage_buckets = {} - storage_buckets = tsms['storageBuckets'] - quota = 0 - for bucket in storage_buckets: - quota = bucket['quota'] - break - - data['total_capacity_gb'] = quota + data['total_capacity_gb'] = ( + float(tsms['numericquota']) / units.Ki) data['free_capacity_gb'] = ( - int(tsms['availablequota']) / 1000) + float(tsms['availablequota']) / units.Ki) + break # TSM not found in CloudByte storage if flag == 0: LOG.error(_LE("TSM [%s] not found in CloudByte storage."), tsmname) - data['total_capacity_gb'] = 0 - data['free_capacity_gb'] = 0 + data['total_capacity_gb'] = 0.0 + data['free_capacity_gb'] = 0.0 return data