]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fetch_to_volume_format calls copy_volume using wrong parameter
authorwuyuting <wytdahu@gmail.com>
Mon, 26 Jan 2015 18:50:28 +0000 (02:50 +0800)
committerwuyuting <wytdahu@gmail.com>
Mon, 26 Jan 2015 22:30:23 +0000 (06:30 +0800)
When creating a volume from an image, if qemu-img is not installed,
fetch_to_volume_format will call volume_utils.copy_volume to copy
image to volume. Copy_volume need the size of image in megabyte,
but fetch_to_volume_format call it using size in bytes.

Change-Id: Ia3b0f9168235a977a12232e27a5755ad11ec18f5
Closes-Bug: #1414867

cinder/image/image_utils.py
cinder/tests/test_image_utils.py

index ff0570d05545d0c5ed766e491cc289812ef0bd62..bb1da6d0053bc955dfe53d6f28f13ccec758a038 100644 (file)
@@ -25,6 +25,7 @@ we should look at maybe pushing this up to Oslo
 
 
 import contextlib
+import math
 import os
 import tempfile
 
@@ -238,7 +239,8 @@ 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']})
-            volume_utils.copy_volume(tmp, dest, image_meta['size'], blocksize)
+            image_size_m = math.ceil(image_meta['size'] / units.Mi)
+            volume_utils.copy_volume(tmp, dest, image_size_m, blocksize)
             return
 
         data = qemu_img_info(tmp, run_as_root=run_as_root)
index 5028c83f5cee6c8d3da25b21f42c8f269610a2f7..7217e726bb5324d05e6c0c3fcceec366ab73d5ed 100644 (file)
 #    under the License.
 """Unit tests for image utils."""
 
+import math
+
 import mock
 from oslo_concurrency import processutils
+from oslo_utils import units
 
 from cinder import exception
 from cinder.image import image_utils
@@ -648,7 +651,8 @@ class TestFetchToVolumeFormat(test.TestCase):
         mock_conf.volume_copy_bps_limit = bps_limit
         tmp = mock_temp.return_value.__enter__.return_value
         image_service.show.return_value = {'disk_format': 'raw',
-                                           'size': mock.sentinel.image_size}
+                                           'size': 41126400}
+        image_size_m = math.ceil(41126400 / units.Mi)
 
         output = image_utils.fetch_to_volume_format(
             ctxt, image_service, image_id, dest, volume_format, blocksize,
@@ -662,7 +666,7 @@ class TestFetchToVolumeFormat(test.TestCase):
         mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
                                            tmp, user_id, project_id)
         self.assertFalse(mock_repl_xen.called)
-        mock_copy.assert_called_once_with(tmp, dest, mock.sentinel.image_size,
+        mock_copy.assert_called_once_with(tmp, dest, image_size_m,
                                           blocksize)
         self.assertFalse(mock_convert.called)