From 1730f2dd567092dc99eae81414ba169225c3feb8 Mon Sep 17 00:00:00 2001 From: yuyafei Date: Wed, 8 Jun 2016 15:05:02 +0800 Subject: [PATCH] Virtual size should get ceiling of image In function fetch_to_volume_format when converting the image virtual size to Gb, we need to get ceiling of image size. Otherwise the following comparing between image virtual size and volume size would not work if image virtual size is 2.75Gb and volume size is 2Gb. This patch fixes it by getting ceiling image virtual size in function fetch_to_volume_format. Change-Id: Id9ea080c109b7cc5068a991eb07b6c9bd1147c77 Closes-Bug: #1590242 --- cinder/image/image_utils.py | 2 +- cinder/tests/unit/test_image_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index a1154967486..4c47b57775c 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -297,7 +297,7 @@ def fetch_to_volume_format(context, image_service, return data = qemu_img_info(tmp, run_as_root=run_as_root) - virt_size = data.virtual_size / units.Gi + virt_size = int(math.ceil(float(data.virtual_size) / units.Gi)) # NOTE(xqueralt): If the image virtual size doesn't fit in the # requested volume there is no point on resizing it because it will diff --git a/cinder/tests/unit/test_image_utils.py b/cinder/tests/unit/test_image_utils.py index 3a90c287733..398bd28ae41 100644 --- a/cinder/tests/unit/test_image_utils.py +++ b/cinder/tests/unit/test_image_utils.py @@ -925,7 +925,7 @@ class TestFetchToVolumeFormat(test.TestCase): data = mock_info.return_value data.file_format = volume_format data.backing_file = None - data.virtual_size = 4321 * 1024 ** 3 + data.virtual_size = int(1234.5 * units.Gi) tmp = mock_temp.return_value.__enter__.return_value self.assertRaises(