image_size_m should get ceiling of image

In function fetch_to_volume_format when converting the
image size to Mb, image_meta['size'] is int and units.Mi
is int. In python2, image_meta['size'] / units.Mi get floor
int. So the image_size_m is less than the real image data.
This will cause copying image data is not complete. This
patch fixes it by getting the ceiling of image_size_m.

Change-Id: If7a7ea873e49ca1d071f3a2f080315f9f43cf059
Closes-Bug: #1591841
This commit is contained in:
zhengyao1 2016-06-14 13:21:13 +08:00
parent 1c9b6f116f
commit 19361445ff
2 changed files with 2 additions and 2 deletions

View File

@ -292,7 +292,7 @@ def fetch_to_volume_format(context, image_service,
LOG.debug('Copying image from %(tmp)s to volume %(dest)s - '
'size: %(size)s', {'tmp': tmp, 'dest': dest,
'size': image_meta['size']})
image_size_m = math.ceil(image_meta['size'] / units.Mi)
image_size_m = math.ceil(float(image_meta['size']) / units.Mi)
volume_utils.copy_volume(tmp, dest, image_size_m, blocksize)
return

View File

@ -795,7 +795,7 @@ class TestFetchToVolumeFormat(test.TestCase):
tmp = mock_temp.return_value.__enter__.return_value
image_service.show.return_value = {'disk_format': 'raw',
'size': 41126400}
image_size_m = math.ceil(41126400 / units.Mi)
image_size_m = math.ceil(float(41126400) / units.Mi)
output = image_utils.fetch_to_volume_format(
ctxt, image_service, image_id, dest, volume_format, blocksize,