From patchwork Tue Jan 26 03:25:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yolkfull Chow X-Patchwork-Id: 75138 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0Q3PLrG003060 for ; Tue, 26 Jan 2010 03:25:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752617Ab0AZDZR (ORCPT ); Mon, 25 Jan 2010 22:25:17 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752506Ab0AZDZR (ORCPT ); Mon, 25 Jan 2010 22:25:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19704 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752486Ab0AZDZP (ORCPT ); Mon, 25 Jan 2010 22:25:15 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0Q3PD2U023637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Jan 2010 22:25:13 -0500 Received: from localhost.localdomain (dhcp-65-181.nay.redhat.com [10.66.65.181]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0Q3P8Aq021262; Mon, 25 Jan 2010 22:25:11 -0500 From: Yolkfull Chow To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Yolkfull Chow Subject: [Autotest PATCH] KVM-test: Add a subtest 'qemu_img' Date: Tue, 26 Jan 2010 11:25:09 +0800 Message-Id: <1264476309-4867-1-git-send-email-yzhou@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/tests/qemu_img.py b/client/tests/kvm/tests/qemu_img.py new file mode 100644 index 0000000..1ae04f0 --- /dev/null +++ b/client/tests/kvm/tests/qemu_img.py @@ -0,0 +1,155 @@ +import os, logging, commands +from autotest_lib.client.common_lib import error +import kvm_vm + + +def run_qemu_img(test, params, env): + """ + `qemu-img' functions test: + 1) Judge what subcommand is going to be tested + 2) Run subcommand test + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + cmd = params.get("qemu_img_binary") + subcommand = params.get("subcommand") + image_format = params.get("image_format") + image_name = kvm_vm.get_image_filename(params, test.bindir) + + def check(img): + global cmd + cmd += " check %s" % img + logging.info("Checking image '%s'..." % img) + s, o = commands.getstatusoutput(cmd) + if not (s == 0 or "does not support checks" in o): + return (False, o) + return (True, "") + + # Subcommand 'qemu-img check' test + # This tests will 'dd' to create a specified size file, and check it. + # Then convert it to supported image_format in each loop and check again. + def check_test(): + size = params.get("dd_image_size") + test_image = params.get("dd_image_name") + create_image_cmd = params.get("create_image_cmd") + create_image_cmd = create_image_cmd % (test_image, size) + s, o = commands.getstatusoutput(create_image_cmd) + if s != 0: + raise error.TestError("Failed command: %s; Output is: %s" % + (create_image_cmd, o)) + s, o = check(test_image) + if not s: + raise error.TestFail("Failed to check image '%s' with error: %s" % + (test_image, o)) + for fmt in params.get("supported_image_formats").split(): + output_image = test_image + ".%s" % fmt + convert(fmt, test_image, output_image) + s, o = check(output_image) + if not s: + raise error.TestFail("Check image '%s' got error: %s" % + (output_image, o)) + commands.getoutput("rm -f %s" % output_image) + commands.getoutput("rm -f %s" % test_image) + + #Subcommand 'qemu-img create' test + def create_test(): + global cmd + cmd += " create" + if params.get("encrypted") == "yes": + cmd += " -e" + if params.get("base_image"): + cmd += " -F %s -b %s" % (params.get("base_image_format"), + params.get("base_image")) + format = params.get("image_format") + cmd += " -f %s" % format + image_name_test = os.path.join(test.bindir, + params.get("image_name_test")) + '.' + format + cmd += " %s %s" % (image_name_test, params.get("image_size_test")) + s, o = commands.getstatusoutput(cmd) + if s != 0: + raise error.TestFail("Create image '%s' failed: %s" % + (image_name_test, o)) + commands.getoutput("rm -f %s" % image_name_test) + + def convert(output_format, image_name, output_filename, + format=None, compressed="no", encrypted="no"): + global cmd + cmd += " convert" + if compressed == "yes": + cmd += " -c" + if encrypted == "yes": + cmd += " -e" + if format: + cmd += " -f %s" % image_format + cmd += " -O %s" % params.get("dest_image_format") + cmd += " %s %s" % (image_name, output_filename) + s, o = commands.getstatusoutput(cmd) + if s != 0: + raise error.TestFail("Image converted failed; Command: %s;" + "Output is: %s" % (cmd, o)) + + #Subcommand 'qemu-img convert' test + def convert_test(): + dest_image_format = params.get("dest_image_format") + output_filename = "%s.converted_%s" % (image_name, dest_image_format) + + convert(dest_image_format, image_name, params.get("dest_image_format"), + image_format, params.get("compressed"), params.get("encrypted")) + + if dest_image_format == "qcow2": + s, o = check(output_filename) + if s: + commands.getoutput("rm -f %s" % output_filename) + else: + raise error.TestFail("Check image '%s' failed with error: %s" % + (dest_image_format, o)) + else: + commands.getoutput("rm -f %s" % output_filename) + + #Subcommand 'qemu-img info' test + def info_test(): + global cmd + cmd += " info" + cmd += " -f %s %s" % (image_format, image_name) + s, o = commands.getstatusoutput(cmd) + if s != 0: + raise error.TestFail("Get info of image '%s' failed: %s" % + (image_name, o)) + logging.info("Info of image '%s': \n%s" % (image_name, o)) + + #Subcommand 'qemu-img snapshot' test + def snapshot_test(): + global cmd + cmd += " snapshot" + for i in range(2): + crtcmd = cmd + snapshot_name = "snapshot%d" % i + crtcmd += " -c %s %s" % (snapshot_name, image_name) + s, o = commands.getstatusoutput(crtcmd) + if s != 0: + raise error.TestFail("Create snapshot failed via command: %s;" + "Output is: %s" % (crtcmd, o)) + logging.info("Created snapshot#%d" % i) + listcmd = cmd + listcmd += " -l %s" % image_name + s, o = commands.getstatusoutput(listcmd) + if not ("snapshot0" in o and "snapshot1" in o and s == 0): + raise error.TestFail("Snapshot created failed or missed;" + "snapshot list is: \n%s" % o) + for i in range(2): + snapshot_name = "snapshot%d" % i + delcmd = cmd + delcmd += " -d %s %s" % (snapshot_name, image_name) + s, o = commands.getstatusoutput(delcmd) + if s != 0: + raise error.TestFail("Delete snapshot '%s' failed: %s" % + (snapshot_name, o)) + + #Subcommand 'qemu-img commit' test + def commit_test(cmd): + pass + + # Here starts test + eval("%s_test" % subcommand) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 2d03f1f..cedd919 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -273,6 +273,42 @@ variants: type = physical_resources_check catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}' + - qemu_img: + type = qemu_img + vms = '' + variants: + - check: + subcommand = check + dd_image_size = 1G + dd_image_name = /tmp/test_image + force_create_image_dd = no + create_image_cmd = "dd if=/dev/zero of=%s bs=%s count=1" + # Test the convertion from 'dd_image_name' to specified format + supported_image_formats = qcow2 raw + - create: + subcommand = create + post_command = "" + images += " stg" + force_create_image_test = yes + image_size_test = 5000G + image_name_test = qemu_img_test + remove_image_test = yes + - convert: + subcommand = convert + variants: + - to_qcow2: + dest_image_format = qcow2 + compressed = no + encrypted = no + - to_raw: + dest_image_format = raw + - snapshot: + subcommand = snapshot + - commit: + subcommand = commit + - info: + subcommand = info + # NICs variants: - @rtl8139: