Volume manage should parse volume size as float

The function manage_existing_object_get_size casts the volume size as
an int, which results in returning the floor of the volume size instead
of the ceiling. It should cast it as a float, which will correctly
result in the ceiling.

Change-Id: I3c8134964e3d8709657fb8bf49d8ba2f9d673149
Closes-Bug: #1584567
This commit is contained in:
yuyafei 2016-05-23 16:18:31 +08:00
parent 87cdd7f7bd
commit 512d7dbcfb
2 changed files with 12 additions and 1 deletions

View File

@ -216,6 +216,17 @@ class RBDTestCase(test.TestCase):
mock_rbd_image_size.assert_called_once_with()
mock_rbd_image_close.assert_called_once_with()
@common_mocks
def test_manage_existing_get_non_integer_size(self):
rbd_image = self.driver.rbd.Image.return_value
rbd_image.size.return_value = int(1.75 * units.Gi)
existing_ref = {'source-name': self.volume_a.name}
return_size = self.driver.manage_existing_get_size(self.volume_a,
existing_ref)
self.assertEqual(2, return_size)
rbd_image.size.assert_called_once_with()
rbd_image.close.assert_called_once_with()
@common_mocks
def test_manage_existing_get_invalid_size(self):

View File

@ -1056,7 +1056,7 @@ class RBDDriver(driver.TransferVD, driver.ExtendVD,
# RBD image size is returned in bytes. Attempt to parse
# size as a float and round up to the next integer.
try:
convert_size = int(math.ceil(int(image_size))) / units.Gi
convert_size = int(math.ceil(float(image_size) / units.Gi))
return convert_size
except ValueError:
exception_message = (_("Failed to manage existing volume "