]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
GPFS convert glance image to raw only when needed
authorBill Owen <billowen@us.ibm.com>
Mon, 22 Jul 2013 00:35:50 +0000 (17:35 -0700)
committerBill Owen <billowen@us.ibm.com>
Tue, 23 Jul 2013 19:26:05 +0000 (12:26 -0700)
Modify _gpfs_fetch_to_raw to check image format.  If already in raw
format, no need to call convert_image.  In that case, simply rename
to destination name.

Change-Id: I197d99194f93c02ce3c501de25433d89b23e6a35
Fixes: bug #1201676
cinder/volume/drivers/gpfs.py

index 901924c7e77b440fc5ccb040f7d6f539568f53b9..e463ca5ea4dfb8705119fda5ad2c9c0b9bf1f433 100644 (file)
@@ -448,14 +448,8 @@ class GPFSDriver(driver.VolumeDriver):
 
             data = image_utils.qemu_img_info(tmp)
             fmt = data.file_format
-            if fmt is None:
-                msg = _("'qemu-img info' parsing failed.")
-                LOG.error(msg)
-                raise exception.ImageUnacceptable(
-                    reason=msg,
-                    image_id=image_id)
-
             backing_file = data.backing_file
+
             if backing_file is not None:
                 msg = (_("fmt = %(fmt)s backed by: %(backing_file)s") %
                        {'fmt': fmt, 'backing_file': backing_file})
@@ -464,16 +458,25 @@ class GPFSDriver(driver.VolumeDriver):
                     image_id=image_id,
                     reason=msg)
 
-            LOG.debug("%s was %s, converting to raw" % (image_id, fmt))
-            image_utils.convert_image(tmp, dest, 'raw')
+            if fmt is None:
+                msg = _("'qemu-img info' parsing failed.")
+                LOG.error(msg)
+                raise exception.ImageUnacceptable(
+                    reason=msg,
+                    image_id=image_id)
+            elif fmt == 'raw':  # already in raw format - just rename to dest
+                self._execute('mv', tmp, dest, run_as_root=True)
+            else:  # conversion to raw format required
+                LOG.debug("%s was %s, converting to raw" % (image_id, fmt))
+                image_utils.convert_image(tmp, dest, 'raw')
+                os.unlink(tmp)
 
             data = image_utils.qemu_img_info(dest)
             if data.file_format != "raw":
-                msg = (_("Converted to raw, but format is now %s") %
+                msg = (_("Expected image to be in raw format, but is %s") %
                        data.file_format)
                 LOG.error(msg)
                 raise exception.ImageUnacceptable(
                     image_id=image_id,
                     reason=msg)
-            os.unlink(tmp)
             return {'size': math.ceil(data.virtual_size / 1024.0 ** 3)}