]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
rbd: Change capacity calculation from integer to float
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Mon, 7 Mar 2016 15:25:09 +0000 (16:25 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Wed, 9 Mar 2016 07:49:03 +0000 (08:49 +0100)
The current capacity calculation in the rbd driver use old
c-style integer calculation while e.g. the scheduler
_weigh_object function uses float, therefore calculate
capacity information in float with 2 digits precision for
Gb sizes.

Closes-Bug: #1508340

Change-Id: I1a731c7606a7dee0295b1604b582447d2da6e750
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
cinder/tests/unit/test_rbd.py
cinder/volume/drivers/rbd.py

index c1f4a49041f8db7e7cd3df61f4246eccb333b195..c2bd7622b648477babc104ba5139d39faba6d60b 100644 (file)
@@ -770,8 +770,8 @@ class RBDTestCase(test.TestCase):
             vendor_name='Open Source',
             driver_version=self.driver.VERSION,
             storage_protocol='ceph',
-            total_capacity_gb=27,
-            free_capacity_gb=26,
+            total_capacity_gb=28.44,
+            free_capacity_gb=27.0,
             reserved_percentage=0,
             multiattach=False)
 
index 91a02133e58d42c067a118348c79f6687ee2cd9f..91ecd01bab89af0a0ca10af9f48cf575149e40de 100644 (file)
@@ -404,11 +404,12 @@ class RBDDriver(driver.TransferVD, driver.ExtendVD,
                     pool_stats = [pool for pool in outbuf['pools'] if
                                   pool['name'] ==
                                   self.configuration.rbd_pool][0]['stats']
-                    stats['free_capacity_gb'] = (
-                        pool_stats['max_avail'] // units.Gi)
-                    used_capacity_gb = pool_stats['bytes_used'] // units.Gi
-                    stats['total_capacity_gb'] = (stats['free_capacity_gb']
-                                                  + used_capacity_gb)
+                    stats['free_capacity_gb'] = round((float(
+                        pool_stats['max_avail']) / units.Gi), 2)
+                    used_capacity_gb = float(
+                        pool_stats['bytes_used']) / units.Gi
+                    stats['total_capacity_gb'] = round(
+                        (stats['free_capacity_gb'] + used_capacity_gb), 2)
         except self.rados.Error:
             # just log and return unknown capacities
             LOG.exception(_LE('error refreshing volume stats'))