From fba1af2bb1382af029e0340512f30b1ba10d389b Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Mon, 7 Mar 2016 16:25:09 +0100 Subject: [PATCH] rbd: Change capacity calculation from integer to float 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 --- cinder/tests/unit/test_rbd.py | 4 ++-- cinder/volume/drivers/rbd.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cinder/tests/unit/test_rbd.py b/cinder/tests/unit/test_rbd.py index c1f4a4904..c2bd7622b 100644 --- a/cinder/tests/unit/test_rbd.py +++ b/cinder/tests/unit/test_rbd.py @@ -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) diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index 91a02133e..91ecd01ba 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -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')) -- 2.45.2