From 7562f4ae1d1362d3b6bc13c621959b497d205303 Mon Sep 17 00:00:00 2001 From: Ping Li Date: Thu, 11 Aug 2016 17:36:02 +0800 Subject: [PATCH] Add cases for subcommand amend of qemu-img Add cases for upgrading and downgrading qcow2 version of image Signed-off-by: Ping Li pingl@redhat.com --- qemu/tests/cfg/qemu_img.cfg | 28 ++++++++++++++++++ qemu/tests/qemu_img.py | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/qemu/tests/cfg/qemu_img.cfg b/qemu/tests/cfg/qemu_img.cfg index baeef11d..47c05e02 100644 --- a/qemu/tests/cfg/qemu_img.cfg +++ b/qemu/tests/cfg/qemu_img.cfg @@ -86,3 +86,31 @@ - commit: install setup image_copy unattended_install.cdrom no vmdk raw qed subcommand = commit + - amend: + only Host_RHEL.m7 + subcommand = amend + start_vm = no + images += " stg" + image_name_stg = "images/stg" + force_create_image_stg = yes + remove_image_stg = yes + check_image_stg = no + variants: + - upgrade: + image_extra_params_stg = "compat=0.10," + qemu_img_options = compat + compat = 1.1 + - downgrade: + image_extra_params_stg = "compat=1.1," + qemu_img_options = compat + compat = 0.10 + variants: + - @default: + - refcount_bits: + variants: + - refcount_bits_32: + image_extra_params_stg += "refcount_bits=32," + check_output = stderr + command_result_pattern = "(compat=0.10 requires refcount_bits=16)" + - refcount_bits_16: + image_extra_params_stg += "refcount_bits=16," diff --git a/qemu/tests/qemu_img.py b/qemu/tests/qemu_img.py index 0ae4eae2..eac1bfa3 100644 --- a/qemu/tests/qemu_img.py +++ b/qemu/tests/qemu_img.py @@ -264,6 +264,9 @@ def run(test, params, env): sub_info += ": (.*)" matches = re.findall(sub_info, output) + if "virtual size" in sub_info: + p = re.compile(r'\.0*(G|K)$') + return p.sub(r'\1', matches[0].split()[0]) if matches: return matches[0] return None @@ -498,6 +501,60 @@ def run(test, params, env): remove(sn2) remove(sn1) + def _amend(cmd, img_name, img_fmt, options): + """ + Simple wrapper of 'qemu-img amend'. + + :param cmd: qemu-img base command + :param img_name: image name that should be amended + :param img_fmt: image format + :param options: a comma separated list of format specific options + """ + + msg = "Amend '%s' with options '%s'" % (img_name, options) + cmd += " amend" + if img_fmt: + cmd += " -f %s" % img_fmt + cache = params.get("cache_mode", '') + if cache: + cmd += " -t %s" % cache + if options: + cmd += " -o " + for option in options: + cmd += "%s=%s," % (option, params.get(option)) + cmd = cmd.rstrip(',') + cmd += " %s" % img_name + error.context(msg, logging.info) + check_command_output(utils.run(cmd, ignore_status=True)) + + def amend_test(cmd): + """ + Subcommand 'qemu-img amend' test + Amend the image format specific options for the image file + + :param cmd: qemu-img base command. + """ + img_name = params.get("image_name_stg") + img_fmt = params.get("image_format_stg", "qcow2") + options = params.get("qemu_img_options", "").split() + check_output = params.get("check_output", "exit_status") + img = _get_image_filename(img_name, img_fmt=img_fmt) + _amend(cmd, img, img_fmt, options) + if check_output == "exit_status": + for option in options: + expect = params.get(option) + if option == "size": + option = "virtual size" + actual = _info(cmd, img, option) + if actual is not None and actual != expect: + msg = "Get wrong %s from image %s!" % (option, img_name) + msg += "Expect: %s, actual: %s" % (expect, actual) + raise error.TestFail(msg) + status, output = _check(cmd, img) + if not status: + raise error.TestFail("Check image '%s' failed after rebase;" + "got error: %s" % (img, output)) + def _boot(img_name, img_fmt): """ Boot test: -- GitLab