def image_to_raw(image_href, path, path_tmp): with fileutils.remove_path_on_error(path_tmp): data = disk_utils.qemu_img_info(path_tmp) fmt = data.file_format if fmt is None: raise exception.ImageUnacceptable( reason=_("'qemu-img info' parsing failed."), image_id=image_href) backing_file = data.backing_file if backing_file is not None: raise exception.ImageUnacceptable( image_id=image_href, reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % {'fmt': fmt, 'backing_file': backing_file}) if fmt != "raw": staged = "%s.converted" % path LOG.debug("%(image)s was %(format)s, converting to raw" % {'image': image_href, 'format': fmt}) with fileutils.remove_path_on_error(staged): disk_utils.convert_image(path_tmp, staged, 'raw') os.unlink(path_tmp) data = disk_utils.qemu_img_info(staged) if data.file_format != "raw": raise exception.ImageConvertFailed( image_id=image_href, reason=_("Converted to raw, but format is " "now %s") % data.file_format) os.rename(staged, path) else: os.rename(path_tmp, path)
def image_to_raw(image_href, path, path_tmp): with fileutils.remove_path_on_error(path_tmp): fmt = get_source_format(image_href, path_tmp) if fmt != "raw": staged = "%s.converted" % path utils.is_memory_insufficent(raise_if_fail=True) LOG.debug("%(image)s was %(format)s, converting to raw", { 'image': image_href, 'format': fmt }) with fileutils.remove_path_on_error(staged): disk_utils.convert_image(path_tmp, staged, 'raw') os.unlink(path_tmp) data = disk_utils.qemu_img_info(staged) if data.file_format != "raw": raise exception.ImageConvertFailed( image_id=image_href, reason=_("Converted to raw, but format is " "now %s") % data.file_format) os.rename(staged, path) else: os.rename(path_tmp, path)
def image_to_raw(image_href, path, path_tmp): with fileutils.remove_path_on_error(path_tmp): data = disk_utils.qemu_img_info(path_tmp) fmt = data.file_format if fmt is None: raise exception.ImageUnacceptable( reason=_("'qemu-img info' parsing failed."), image_id=image_href) backing_file = data.backing_file if backing_file is not None: raise exception.ImageUnacceptable( image_id=image_href, reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % {'fmt': fmt, 'backing_file': backing_file}) if fmt != "raw": staged = "%s.converted" % path LOG.debug("%(image)s was %(format)s, converting to raw", {'image': image_href, 'format': fmt}) with fileutils.remove_path_on_error(staged): disk_utils.convert_image(path_tmp, staged, 'raw') os.unlink(path_tmp) data = disk_utils.qemu_img_info(staged) if data.file_format != "raw": raise exception.ImageConvertFailed( image_id=image_href, reason=_("Converted to raw, but format is " "now %s") % data.file_format) os.rename(staged, path) else: os.rename(path_tmp, path)
def test_convert_image(self, execute_mock): disk_utils.convert_image('source', 'dest', 'out_format') execute_mock.assert_called_once_with('qemu-img', 'convert', '-O', 'out_format', 'source', 'dest', run_as_root=False)
def test_convert_image(self, execute_mock): disk_utils.convert_image('source', 'dest', 'out_format') execute_mock.assert_called_once_with('qemu-img', 'convert', '-O', 'out_format', 'source', 'dest', run_as_root=False)