]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fail when image is bigger than the volume
authorXavier Queralt <xqueralt@redhat.com>
Tue, 22 Oct 2013 18:37:53 +0000 (20:37 +0200)
committerXavier Queralt <xqueralt@redhat.com>
Tue, 12 Nov 2013 12:00:15 +0000 (13:00 +0100)
When creating a new volume from a qcow2 image stored in glance, we will
be given the physical size of the image instead of the virtual size.
Most drivers will convert that image to raw after downloading for
resizing it to the requested volume size afterwards.

If the virtual size of the image is bigger than the requested one, the
resulting volume might end up being unusable after the resize even
though the creation went good.

This patch will make the volume creation fail if the virtual size of
the image exceeds the one of the requested volume.

Closes-Bug: #1235358
Change-Id: I254cd9e3acf5d9eb7eb913b37d27a14e97568dec

15 files changed:
cinder/image/image_utils.py
cinder/tests/test_block_device.py
cinder/tests/test_coraid.py
cinder/tests/test_image_utils.py
cinder/tests/test_nfs.py
cinder/tests/test_rbd.py
cinder/tests/test_scality.py
cinder/tests/test_volume.py
cinder/volume/driver.py
cinder/volume/drivers/block_device.py
cinder/volume/drivers/gpfs.py
cinder/volume/drivers/lvm.py
cinder/volume/drivers/nfs.py
cinder/volume/drivers/rbd.py
cinder/volume/drivers/scality.py

index 7ce3c1768e00ebb3039cf61fc2c80e29c6a2f251..f853f75be82e05d2cba808754abec28b4c9d6d7c 100644 (file)
@@ -37,7 +37,7 @@ from cinder.openstack.common import fileutils
 from cinder.openstack.common import imageutils
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import processutils
-from cinder.openstack.common import strutils
+from cinder import units
 from cinder import utils
 from cinder.volume import utils as volume_utils
 
@@ -84,7 +84,7 @@ def fetch(context, image_service, image_id, path, _user_id, _project_id):
 
 
 def fetch_verify_image(context, image_service, image_id, dest,
-                       user_id=None, project_id=None):
+                       user_id=None, project_id=None, size=None):
     fetch(context, image_service, image_id, dest,
           None, None)
 
@@ -103,6 +103,15 @@ def fetch_verify_image(context, image_service, image_id, dest,
                 reason=(_("fmt=%(fmt)s backed by: %(backing_file)s") %
                         {'fmt': fmt, 'backing_file': backing_file}))
 
+        # NOTE(xqueralt): If the image virtual size doesn't fit in the
+        # requested volume there is no point on resizing it because it will
+        # generate an unusable image.
+        if size is not None and data.virtual_size > size:
+            params = {'image_size': data.virtual_size, 'volume_size': size}
+            reason = _("Size is %(image_size)dGB and doesn't fit in a "
+                       "volume of size %(volume_size)dGB.") % params
+            raise exception.ImageUnacceptable(image_id=image_id, reason=reason)
+
 
 def fetch_to_vhd(context, image_service,
                  image_id, dest,
@@ -113,19 +122,19 @@ def fetch_to_vhd(context, image_service,
 
 def fetch_to_raw(context, image_service,
                  image_id, dest,
-                 user_id=None, project_id=None):
+                 user_id=None, project_id=None, size=None):
     fetch_to_volume_format(context, image_service, image_id, dest, 'raw',
-                           user_id, project_id)
+                           user_id, project_id, size)
 
 
 def fetch_to_volume_format(context, image_service,
                            image_id, dest, volume_format,
-                           user_id=None, project_id=None):
+                           user_id=None, project_id=None, size=None):
     if (CONF.image_conversion_dir and not
             os.path.exists(CONF.image_conversion_dir)):
         os.makedirs(CONF.image_conversion_dir)
 
-    no_qemu_img = False
+    qemu_img = True
     image_meta = image_service.show(context, image_id)
 
     # NOTE(avishay): I'm not crazy about creating temp files which may be
@@ -143,7 +152,7 @@ def fetch_to_volume_format(context, image_service,
             # Use the empty tmp file to make sure qemu_img_info works.
             qemu_img_info(tmp)
         except processutils.ProcessExecutionError:
-            no_qemu_img = True
+            qemu_img = False
             if image_meta:
                 if image_meta['disk_format'] != 'raw':
                     raise exception.ImageUnacceptable(
@@ -164,7 +173,7 @@ def fetch_to_volume_format(context, image_service,
         if is_xenserver_image(context, image_service, image_id):
             replace_xenserver_image_with_coalesced_vhd(tmp)
 
-        if no_qemu_img:
+        if noqemu_img:
             # qemu-img is not installed but we do have a RAW image.  As a
             # result we only need to copy the image to the destination and then
             # return.
@@ -175,6 +184,17 @@ def fetch_to_volume_format(context, image_service,
             return
 
         data = qemu_img_info(tmp)
+        virt_size = data.virtual_size / units.GiB
+
+        # NOTE(xqueralt): If the image virtual size doesn't fit in the
+        # requested volume there is no point on resizing it because it will
+        # generate an unusable image.
+        if size is not None and virt_size > size:
+            params = {'image_size': virt_size, 'volume_size': size}
+            reason = _("Size is %(image_size)dGB and doesn't fit in a "
+                       "volume of size %(volume_size)dGB.") % params
+            raise exception.ImageUnacceptable(image_id=image_id, reason=reason)
+
         fmt = data.file_format
         if fmt is None:
             raise exception.ImageUnacceptable(
index 2cc0d208c500281eeeb19153ba93f7b49b8dce74..5a71afe721a7bef67c90cce31533e1b5c02a9609 100644 (file)
@@ -145,14 +145,14 @@ class TestBlockDeviceDriver(cinder.test.TestCase):
                                                'None None None /dev/loop2'})
 
     def test_copy_image_to_volume(self):
-        TEST_VOLUME = {'provider_location': '1 2 3 /dev/loop1'}
+        TEST_VOLUME = {'provider_location': '1 2 3 /dev/loop1', 'size': 1}
         TEST_IMAGE_SERVICE = "image_service"
         TEST_IMAGE_ID = "image_id"
         self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')
         self.mox.StubOutWithMock(self.drv, 'local_path')
         self.drv.local_path(TEST_VOLUME).AndReturn('/dev/loop1')
         image_utils.fetch_to_raw(context, TEST_IMAGE_SERVICE,
-                                 TEST_IMAGE_ID, '/dev/loop1')
+                                 TEST_IMAGE_ID, '/dev/loop1', size=1)
         self.mox.ReplayAll()
         self.drv.copy_image_to_volume(context, TEST_VOLUME, TEST_IMAGE_SERVICE,
                                       TEST_IMAGE_ID)
index 277ba6ef7a88839224a1db48e223754ab3f89035..2dd2cecada311e074af7b044566fed0e53b4cf17 100644 (file)
@@ -827,7 +827,8 @@ class CoraidDriverImageTestCases(CoraidDriverTestCase):
         image_utils.fetch_to_raw({},
                                  fake_image_service,
                                  fake_image_id,
-                                 self.fake_dev_path)
+                                 self.fake_dev_path,
+                                 size=fake_volume_size)
 
         self.mox.ReplayAll()
 
index 174c263ab3d2f5e25cde77670ecb0162a7b01bf8..def72d4a4a5bd0131992eff0a639efbf36a007af 100644 (file)
 import contextlib
 import mox
 import tempfile
-import textwrap
 
 from cinder import context
 from cinder import exception
 from cinder.image import image_utils
+from cinder.openstack.common import processutils
 from cinder import test
 from cinder import units
 from cinder import utils
@@ -53,6 +53,8 @@ class TestUtils(test.TestCase):
     def setUp(self):
         super(TestUtils, self).setUp()
         self._mox = mox.Mox()
+        self._image_service = FakeImageService()
+
         self.addCleanup(self._mox.UnsetStubs)
 
     def test_resize_image(self):
@@ -191,174 +193,158 @@ class TestUtils(test.TestCase):
 
         self.assertEquals(str(inf), TEST_STR)
 
-    def test_fetch_to_raw(self):
-        TEST_RET = "image: qemu.qcow2\n"\
-                   "file_format: qcow2 \n"\
-                   "virtual_size: 50M (52428800 bytes)\n"\
-                   "cluster_size: 65536\n"\
-                   "disk_size: 196K (200704 bytes)"
-        TEST_RETURN_RAW = "image: qemu.raw\n"\
-                          "file_format: raw\n"\
-                          "virtual_size: 50M (52428800 bytes)\n"\
-                          "cluster_size: 65536\n"\
-                          "disk_size: 196K (200704 bytes)\n"\
-
-        fake_image_service = FakeImageService()
+    def _test_fetch_to_raw(self, has_qemu=True, src_inf=None, dest_inf=None):
         mox = self._mox
-
         mox.StubOutWithMock(image_utils, 'create_temporary_file')
         mox.StubOutWithMock(utils, 'execute')
         mox.StubOutWithMock(image_utils, 'fetch')
 
-        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
-        image_utils.fetch(context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)
-
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
-
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
+        TEST_INFO = ("image: qemu.qcow2\n"
+                     "file format: raw\n"
+                     "virtual size: 0 (0 bytes)\n"
+                     "disk size: 0")
 
-        utils.execute('qemu-img', 'convert', '-O', 'raw',
-                      self.TEST_DEV_PATH, self.TEST_DEV_PATH, run_as_root=True)
+        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
 
-        utils.execute(
+        test_qemu_img = utils.execute(
             'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RETURN_RAW, 'ignored')
-            )
-
-        mox.ReplayAll()
+            self.TEST_DEV_PATH, run_as_root=True)
+
+        if has_qemu:
+            test_qemu_img.AndReturn((TEST_INFO, 'ignored'))
+            image_utils.fetch(context, self._image_service, self.TEST_IMAGE_ID,
+                              self.TEST_DEV_PATH, None, None)
+        else:
+            test_qemu_img.AndRaise(processutils.ProcessExecutionError())
+
+        if has_qemu and src_inf:
+            utils.execute(
+                'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
+                self.TEST_DEV_PATH, run_as_root=True).AndReturn(
+                    (src_inf, 'ignored')
+                )
+
+        if has_qemu and dest_inf:
+            utils.execute(
+                'qemu-img', 'convert', '-O', 'raw',
+                self.TEST_DEV_PATH, self.TEST_DEV_PATH, run_as_root=True)
+
+            utils.execute(
+                'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
+                self.TEST_DEV_PATH, run_as_root=True).AndReturn(
+                    (dest_inf, 'ignored')
+                )
+
+        self._mox.ReplayAll()
 
-        image_utils.fetch_to_raw(context, fake_image_service,
+    def test_fetch_to_raw(self):
+        SRC_INFO = ("image: qemu.qcow2\n"
+                    "file_format: qcow2 \n"
+                    "virtual_size: 50M (52428800 bytes)\n"
+                    "cluster_size: 65536\n"
+                    "disk_size: 196K (200704 bytes)")
+        DST_INFO = ("image: qemu.raw\n"
+                    "file_format: raw\n"
+                    "virtual_size: 50M (52428800 bytes)\n"
+                    "cluster_size: 65536\n"
+                    "disk_size: 196K (200704 bytes)\n")
+
+        self._test_fetch_to_raw(src_inf=SRC_INFO, dest_inf=DST_INFO)
+
+        image_utils.fetch_to_raw(context, self._image_service,
                                  self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
-        mox.VerifyAll()
+        self._mox.VerifyAll()
 
-    def test_fetch_to_raw_on_error_parsing_failed(self):
-        TEST_RET = "image: qemu.qcow2\n"\
-                   "virtual_size: 50M (52428800 bytes)\n"\
-                   "cluster_size: 65536\n"\
-                   "disk_size: 196K (200704 bytes)"
+    def test_fetch_to_raw_no_qemu_img(self):
+        self._test_fetch_to_raw(has_qemu=False)
 
-        fake_image_service = FakeImageService()
-        mox = self._mox
-
-        mox.StubOutWithMock(image_utils, 'create_temporary_file')
-        mox.StubOutWithMock(utils, 'execute')
-        mox.StubOutWithMock(image_utils, 'fetch')
-
-        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
-        image_utils.fetch(context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)
+        self.assertRaises(exception.ImageUnacceptable,
+                          image_utils.fetch_to_raw,
+                          context, self._image_service,
+                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
 
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
+        self._mox.VerifyAll()
 
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
+    def test_fetch_to_raw_on_error_parsing_failed(self):
+        SRC_INFO_NO_FORMAT = ("image: qemu.qcow2\n"
+                              "virtual_size: 50M (52428800 bytes)\n"
+                              "cluster_size: 65536\n"
+                              "disk_size: 196K (200704 bytes)")
 
-        mox.ReplayAll()
+        self._test_fetch_to_raw(src_inf=SRC_INFO_NO_FORMAT)
 
         self.assertRaises(exception.ImageUnacceptable,
-                          image_utils.fetch_to_raw, context,
-                          fake_image_service, self.TEST_IMAGE_ID,
-                          self.TEST_DEV_PATH)
+                          image_utils.fetch_to_raw,
+                          context, self._image_service,
+                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
+        self._mox.VerifyAll()
 
     def test_fetch_to_raw_on_error_backing_file(self):
-        TEST_RET = "image: qemu.qcow2\n"\
-                   "backing_file: qemu.qcow2 (actual path: qemu.qcow2)\n"\
-                   "file_format: qcow2 \n"\
-                   "virtual_size: 50M (52428800 bytes)\n"\
-                   "cluster_size: 65536\n"\
-                   "disk_size: 196K (200704 bytes)"
+        SRC_INFO_BACKING_FILE = ("image: qemu.qcow2\n"
+                                 "backing_file: qemu.qcow2\n"
+                                 "file_format: qcow2 \n"
+                                 "virtual_size: 50M (52428800 bytes)\n"
+                                 "cluster_size: 65536\n"
+                                 "disk_size: 196K (200704 bytes)")
 
-        fake_image_service = FakeImageService()
-        mox = self._mox
+        self._test_fetch_to_raw(src_inf=SRC_INFO_BACKING_FILE)
 
-        mox.StubOutWithMock(image_utils, 'create_temporary_file')
-        mox.StubOutWithMock(utils, 'execute')
-        mox.StubOutWithMock(image_utils, 'fetch')
-
-        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
-        image_utils.fetch(context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)
+        self.assertRaises(exception.ImageUnacceptable,
+                          image_utils.fetch_to_raw,
+                          context, self._image_service,
+                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
+        self._mox.VerifyAll()
 
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
+    def test_fetch_to_raw_on_error_not_convert_to_raw(self):
+        IMG_INFO = ("image: qemu.qcow2\n"
+                    "file_format: qcow2 \n"
+                    "virtual_size: 50M (52428800 bytes)\n"
+                    "cluster_size: 65536\n"
+                    "disk_size: 196K (200704 bytes)")
 
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
+        self._test_fetch_to_raw(src_inf=IMG_INFO, dest_inf=IMG_INFO)
 
-        mox.ReplayAll()
         self.assertRaises(exception.ImageUnacceptable,
                           image_utils.fetch_to_raw,
-                          context, fake_image_service,
+                          context, self._image_service,
                           self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
 
-    def test_fetch_to_raw_on_error_not_convert_to_raw(self):
-        TEST_RET = "image: qemu.qcow2\n"\
-                   "file_format: qcow2 \n"\
-                   "virtual_size: 50M (52428800 bytes)\n"\
-                   "cluster_size: 65536\n"\
-                   "disk_size: 196K (200704 bytes)"
+    def test_fetch_to_raw_on_error_image_size(self):
+        TEST_VOLUME_SIZE = 1
+        SRC_INFO = ("image: qemu.qcow2\n"
+                    "file_format: qcow2 \n"
+                    "virtual_size: 2G (2147483648 bytes)\n"
+                    "cluster_size: 65536\n"
+                    "disk_size: 196K (200704 bytes)")
 
+        self._test_fetch_to_raw(src_inf=SRC_INFO)
+
+        self.assertRaises(exception.ImageUnacceptable,
+                          image_utils.fetch_to_raw,
+                          context, self._image_service,
+                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH,
+                          size=TEST_VOLUME_SIZE)
+
+    def _test_fetch_verify_image(self, qemu_info, volume_size=1):
         fake_image_service = FakeImageService()
         mox = self._mox
-
-        mox.StubOutWithMock(image_utils, 'create_temporary_file')
-        mox.StubOutWithMock(utils, 'execute')
         mox.StubOutWithMock(image_utils, 'fetch')
-
-        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
+        mox.StubOutWithMock(utils, 'execute')
         image_utils.fetch(context, fake_image_service,
                           self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)
 
         utils.execute(
             'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
             self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
+                (qemu_info, 'ignored')
             )
 
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
-
-        utils.execute('qemu-img', 'convert', '-O', 'raw',
-                      self.TEST_DEV_PATH, self.TEST_DEV_PATH, run_as_root=True)
-
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RET, 'ignored')
-            )
-
-        mox.ReplayAll()
-
+        self._mox.ReplayAll()
         self.assertRaises(exception.ImageUnacceptable,
-                          image_utils.fetch_to_raw,
+                          image_utils.fetch_verify_image,
                           context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
+                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH,
+                          size=volume_size)
 
     def test_fetch_verify_image_with_backing_file(self):
         TEST_RETURN = "image: qemu.qcow2\n"\
@@ -371,25 +357,7 @@ class TestUtils(test.TestCase):
                       "ID TAG  VM SIZE DATE VM CLOCK\n"\
                       "1  snap1 1.7G 2011-10-04 19:04:00 32:06:34.974"
 
-        fake_image_service = FakeImageService()
-        mox = self._mox
-        mox.StubOutWithMock(image_utils, 'fetch')
-        mox.StubOutWithMock(utils, 'execute')
-        image_utils.fetch(context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)
-
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RETURN, 'ignored')
-            )
-
-        mox.ReplayAll()
-
-        self.assertRaises(exception.ImageUnacceptable,
-                          image_utils.fetch_verify_image,
-                          context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
+        self._test_fetch_verify_image(TEST_RETURN)
 
     def test_fetch_verify_image_without_file_format(self):
         TEST_RETURN = "image: qemu.qcow2\n"\
@@ -400,25 +368,19 @@ class TestUtils(test.TestCase):
                       "ID TAG  VM SIZE DATE VM CLOCK\n"\
                       "1  snap1 1.7G 2011-10-04 19:04:00 32:06:34.974"
 
-        fake_image_service = FakeImageService()
-        mox = self._mox
-        mox.StubOutWithMock(image_utils, 'fetch')
-        mox.StubOutWithMock(utils, 'execute')
-        image_utils.fetch(context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)
+        self._test_fetch_verify_image(TEST_RETURN)
 
-        utils.execute(
-            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
-            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
-                (TEST_RETURN, 'ignored')
-            )
-
-        mox.ReplayAll()
+    def test_fetch_verify_image_image_size(self):
+        TEST_RETURN = "image: qemu.qcow2\n"\
+                      "file_format: qcow2\n"\
+                      "virtual_size: 2G (2147483648 bytes)\n"\
+                      "cluster_size: 65536\n"\
+                      "disk_size: 196K (200704 bytes)\n"\
+                      "Snapshot list:\n"\
+                      "ID TAG  VM SIZE DATE VM CLOCK\n"\
+                      "1  snap1 1.7G 2011-10-04 19:04:00 32:06:34.974"
 
-        self.assertRaises(exception.ImageUnacceptable,
-                          image_utils.fetch_verify_image,
-                          context, fake_image_service,
-                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
+        self._test_fetch_verify_image(TEST_RETURN)
 
     def test_upload_volume(self):
         image_meta = {'id': 1, 'disk_format': 'qcow2'}
index 993f35d17b0c188e1d0e09ccba7db8f107702206..7ce00e1b34d70f687eb16ab8ab4a6cd36e359b9a 100644 (file)
@@ -175,7 +175,8 @@ class NfsDriverTestCase(test.TestCase):
         self.stubs.Set(drv, 'local_path', fake_local_path)
 
         mox.StubOutWithMock(image_utils, 'fetch_to_raw')
-        image_utils.fetch_to_raw(None, None, None, TEST_IMG_SOURCE)
+        image_utils.fetch_to_raw(None, None, None, TEST_IMG_SOURCE,
+                                 size=self.TEST_SIZE_IN_GB)
 
         mox.StubOutWithMock(image_utils, 'resize_image')
         image_utils.resize_image(TEST_IMG_SOURCE, self.TEST_SIZE_IN_GB)
index 33fc0630e9afe40b155e1769bb33ec2d00bca34a..97ca7fd764885f0b5c1b962dcce852394556faf1 100644 (file)
@@ -293,9 +293,13 @@ class RBDTestCase(test.TestCase):
                 def __init__(self, name):
                     self.name = name
             yield FakeTmp('test')
+
+        def fake_fetch_to_raw(ctx, image_service, image_id, path, size=None):
+            pass
+
         self.stubs.Set(tempfile, 'NamedTemporaryFile', fake_temp_file)
         self.stubs.Set(os.path, 'exists', lambda x: True)
-        self.stubs.Set(image_utils, 'fetch_to_raw', lambda w, x, y, z: None)
+        self.stubs.Set(image_utils, 'fetch_to_raw', fake_fetch_to_raw)
         self.stubs.Set(self.driver, 'delete_volume', lambda x: None)
         self.stubs.Set(self.driver, '_resize', lambda x: None)
         self.driver.copy_image_to_volume(None, {'name': 'test',
index 5c4c62d37d98a66da2723afa7c4e1d840d820538..f3f9ea8baf23c599a129fafc5fd4bbec54ba0d21 100644 (file)
@@ -237,7 +237,8 @@ class ScalityDriverTestCase(test.TestCase):
         image_utils.fetch_to_raw(context,
                                  self.TEST_IMAGE_SERVICE,
                                  self.TEST_IMAGE_ID,
-                                 self.TEST_VOLPATH)
+                                 self.TEST_VOLPATH,
+                                 size=self.TEST_VOLSIZE)
 
         self.mox.ReplayAll()
 
index 86cff8bc5f82754dd926a23804bd2dd693a61986..5017acbc424e0264cd6804d00187347089d191ea 100644 (file)
@@ -1214,7 +1214,7 @@ class VolumeTestCase(BaseVolumeTestCase):
                                       image_service, image_id):
             pass
 
-        def fake_fetch_to_raw(context, image_service, image_id, vol_path):
+        def fake_fetch_to_raw(ctx, image_service, image_id, path, size=None):
             pass
 
         def fake_clone_image(volume_ref, image_location, image_id):
index a286b4b3b7d3d38975f274729acca830a43efb1f..98b6fad00508a531b550ad0bf3365209fa5e1af9 100644 (file)
@@ -337,7 +337,8 @@ class VolumeDriver(object):
             image_utils.fetch_to_raw(context,
                                      image_service,
                                      image_id,
-                                     attach_info['device']['path'])
+                                     attach_info['device']['path'],
+                                     size=volume['size'])
         finally:
             self._detach_volume(attach_info)
             self.terminate_connection(volume, properties)
index 76bfcf0181e7d4bdb5ee5787b0e7603fda1c6606..4d0aca2807020f24e65c84f70a9a1fa2e665a401 100644 (file)
@@ -294,7 +294,8 @@ class BlockDeviceDriver(driver.ISCSIDriver):
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
-                                 self.local_path(volume))
+                                 self.local_path(volume),
+                                 size=volume['size'])
 
     def copy_volume_to_image(self, context, volume, image_service, image_meta):
         """Copy the volume to the specified image."""
index 2e5b8119cbbcf531437a2f4802c3be00cc6500d4..13cf89dcb37cf6cd60a5d8e04d39f21485d9ab03 100644 (file)
@@ -542,7 +542,7 @@ class GPFSDriver(driver.VolumeDriver):
         LOG.debug('Copy image to vol %s using image_utils fetch_to_raw' %
                   volume['id'])
         image_utils.fetch_to_raw(context, image_service, image_id,
-                                 self.local_path(volume))
+                                 self.local_path(volume), size=volume['size'])
         image_utils.resize_image(self.local_path(volume), volume['size'])
 
     def copy_volume_to_image(self, context, volume, image_service, image_meta):
index e1cb9fe0e62a9a9885505926a77918144d560228..cdd5a4c0bdc9d28c0bb0d754ecd1d92f69a46ad1 100644 (file)
@@ -275,7 +275,7 @@ class LVMVolumeDriver(driver.VolumeDriver):
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
-                                 self.local_path(volume))
+                                 self.local_path(volume), size=volume['size'])
 
     def copy_volume_to_image(self, context, volume, image_service, image_meta):
         """Copy the volume to the specified image."""
index 277b173a6495772be6ab5b6b043f8fd37c0bc46a..c92335b81e149ee7be320f05a1234281ddd7c597 100644 (file)
@@ -227,7 +227,8 @@ class RemoteFsDriver(driver.VolumeDriver):
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
-                                 self.local_path(volume))
+                                 self.local_path(volume),
+                                 size=volume['size'])
 
         # NOTE (leseb): Set the virtual size of the image
         # the raw conversion overwrote the destination file
index 0ab857c3ac07d90f78e5413d802066cf0dd9b42a..ea75f74a81689d788ebd29dd9e649594afc5e6d1 100644 (file)
@@ -743,7 +743,7 @@ class RBDDriver(driver.VolumeDriver):
 
         with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
             image_utils.fetch_to_raw(context, image_service, image_id,
-                                     tmp.name)
+                                     tmp.name, size=volume['size'])
 
             self.delete_volume(volume)
 
index 0d2d0d37c77d601774239e4b3c57e8bfbbe80f60..4cf49c6b731e072c105e518496759160a039b4b7 100644 (file)
@@ -239,7 +239,8 @@ class ScalityDriver(driver.VolumeDriver):
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
-                                 self.local_path(volume))
+                                 self.local_path(volume),
+                                 size=volume['size'])
         self.create_volume(volume)
 
     def copy_volume_to_image(self, context, volume, image_service, image_meta):