From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yolkfull Chow Subject: Re: [Autotest] [Autotest PATCH] KVM-test: Add a subtest 'qemu_img' Date: Tue, 30 Mar 2010 12:53:21 +0800 Message-ID: <20100330045321.GA2183@aFu.nay.redhat.com> References: <1264748409-9503-1-git-send-email-yzhou@redhat.com> <6ac58f4f1003170638w468cace9o4082a1f94627a3f9@mail.gmail.com> Reply-To: Yolkfull Chow Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: autotest@test.kernel.org, kvm@vger.kernel.org, Michael Goldish To: Lucas Meneghel Rodrigues Return-path: Received: from mx1.redhat.com ([209.132.183.28]:2010 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751297Ab0C3Ex2 (ORCPT ); Tue, 30 Mar 2010 00:53:28 -0400 Content-Disposition: inline In-Reply-To: <6ac58f4f1003170638w468cace9o4082a1f94627a3f9@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Mar 17, 2010 at 10:38:58AM -0300, Lucas Meneghel Rodrigues wrot= e: > Copying Michael on the message. >=20 > Hi Yolkfull, I have reviewed this patch and I have some comments to > make on it, similar to the ones I made on an earlier version of it: >=20 > One of the things that I noticed is that this patch doesn't work very > well out of the box: >=20 > [lmr@freedom kvm]$ ./scan_results.py > Test Status Seconds Info > ---- ------ ------- ---- > (Result file: ../../results/default/status) > smp2.Fedora.11.64.qemu_img.check GOOD 47 completed s= uccessfully > smp2.Fedora.11.64.qemu_img.create GOOD 44 completed s= uccessfully > smp2.Fedora.11.64.qemu_img.convert.to_qcow2 FAIL 45 Image > converted failed; Command: /usr/bin/qemu-img convert -f qcow2 -O qcow= 2 > /tmp/kvm_autotest_root/images/fc11-64.qcow2 > /tmp/kvm_autotest_root/images/fc11-64.qcow2.converted_qcow2;Output is= : > qemu-img: Could not open '/tmp/kvm_autotest_root/images/fc11-64.qcow2= ' > smp2.Fedora.11.64.qemu_img.convert.to_raw FAIL 46 Image > converted failed; Command: /usr/bin/qemu-img convert -f qcow2 -O raw > /tmp/kvm_autotest_root/images/fc11-64.qcow2 > /tmp/kvm_autotest_root/images/fc11-64.qcow2.converted_raw;Output is: > qemu-img: Could not open '/tmp/kvm_autotest_root/images/fc11-64.qcow2= ' > smp2.Fedora.11.64.qemu_img.snapshot FAIL 44 Create > snapshot failed via command: /usr/bin/qemu-img snapshot -c snapshot0 > /tmp/kvm_autotest_root/images/fc11-64.qcow2;Output is: qemu-img: Coul= d > not open '/tmp/kvm_autotest_root/images/fc11-64.qcow2' > smp2.Fedora.11.64.qemu_img.commit GOOD 44 completed s= uccessfully > smp2.Fedora.11.64.qemu_img.info FAIL 44 Unhandled > str: Unhandled TypeError: argument of type 'NoneType' is not iterable > smp2.Fedora.11.64.qemu_img.rebase TEST_NA 43 Current > kvm user space version does not support 'rebase' subcommand > ---- GOOD 412=09 >=20 > We need to fix that before upstream inclusion. Hi Lucas, did you run the test on fedora or other box? I ran this test = on my fedora 13 box for several times, worked fine: # ./scan_results.py=20 Test Status Seconds Info ---- ------ ------- ---- (Result file: ../../results/default/status) smp2.RHEL.5.4.i386.qemu_img.check GOOD 132 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.create GOOD 144 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.convert.to_qcow2 GOOD 251 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.convert.to_raw GOOD 245 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.snapshot GOOD 140 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.commit GOOD 146 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.info GOOD 133 completed su= ccessfully smp2.RHEL.5.4.i386.qemu_img.rebase TEST_NA 137 Current k= vm user space version does not support 'rebase' subcommand ---- GOOD 1392=09 [root@aFu kvm]#=20 Weird why there are some case failed... Please test again based on the new patch I will send later. >=20 > Also, one thing that I've noticed is that this test doesn't depend of > any other variants, so we don't need to repeat it to every combinatio= n > of guest and qemu command line options. Michael, does it occur to you > a way to get this test out of the variants block, so it gets executed > only once per job and not every combination of guest and other qemu > options? Lucas and Michael, maybe we could add a parameter say 'ignore_vm_config= =3D yes' to config file which let a test ignore all configurations combination.=20 Another method is ugly adding following block into config file: --- qemu_img: only ide only qcow2 only up only ... (use 'only' to filter all configurations combination) --- But I don't think it's a good idea. What do you think? >=20 > On Fri, Jan 29, 2010 at 4:00 AM, Yolkfull Chow wro= te: > > This is designed to test all subcommands of 'qemu-img' however > > so far 'commit' is not implemented. > > > > * For 'check' subcommand test, it will 'dd' to create a file with s= pecified > > size and see whether it's supported to be checked. Then convert it = to be > > supported formats ('qcow2' and 'raw' so far) to see whether there's= error > > after convertion. > > > > * For 'convert' subcommand test, it will convert both to 'qcow2' an= d 'raw' from > > the format specified in config file. And only check 'qcow2' after c= onvertion. > > > > * For 'snapshot' subcommand test, it will create two snapshots and = list them. > > Finally delete them if no errors found. > > > > * For 'info' subcommand test, it will check image format & size acc= ording to > > output of 'info' subcommand =A0at specified image file. > > > > * For 'rebase' subcommand test, it will create first snapshot 'sn1'= based on original > > base_img, and create second snapshot based on sn1. And then rebase = sn2 to base_img. > > After rebase check the baking_file of sn2. > > > > This supports two rebase mode: unsafe mode and safe mode: > > Unsafe mode: > > With -u an unsafe mode is enabled that doesn't require the backing = files to exist. > > It merely changes the backing file reference in the COW image. This= is useful for > > renaming or moving the backing file. The user is responsible to mak= e sure that the > > new backing file has no changes compared to the old one, or corrupt= ion may occur. > > > > Safe Mode: > > Both the current and the new backing file need to exist, and after = the rebase, the > > COW image is guaranteed to have the same guest visible content as b= efore. > > To achieve this, old and new backing file are compared and, if nece= ssary, data is > > copied from the old backing file into the COW image. > > > > Signed-off-by: Yolkfull Chow > > --- > > =A0client/tests/kvm/tests/qemu_img.py =A0 =A0 | =A0235 ++++++++++++= ++++++++++++++++++++ > > =A0client/tests/kvm/tests_base.cfg.sample | =A0 40 ++++++ > > =A02 files changed, 275 insertions(+), 0 deletions(-) > > =A0create mode 100644 client/tests/kvm/tests/qemu_img.py > > > > diff --git a/client/tests/kvm/tests/qemu_img.py b/client/tests/kvm/= tests/qemu_img.py > > new file mode 100644 > > index 0000000..e6352a0 > > --- /dev/null > > +++ b/client/tests/kvm/tests/qemu_img.py > > @@ -0,0 +1,235 @@ > > +import re, os, logging, commands > > +from autotest_lib.client.common_lib import utils, error > > +import kvm_vm, kvm_utils > > + > > + > > +def run_qemu_img(test, params, env): > > + =A0 =A0""" > > + =A0 =A0`qemu-img' functions test: > > + =A0 =A01) Judge what subcommand is going to be tested > > + =A0 =A02) Run subcommand test > > + > > + =A0 =A0@param test: kvm test object > > + =A0 =A0@param params: Dictionary with the test parameters > > + =A0 =A0@param env: Dictionary with test environment. > > + =A0 =A0""" > > + =A0 =A0cmd =3D kvm_utils.get_path(test.bindir, params.get("qemu_i= mg_binary")) > > + =A0 =A0if not os.path.exists(cmd): > > + =A0 =A0 =A0 =A0raise error.TestError("Binary of 'qemu-img' not fo= und") > > + =A0 =A0image_format =3D params.get("image_format") > > + =A0 =A0image_size =3D params.get("image_size", "10G") > > + =A0 =A0image_name =3D kvm_vm.get_image_filename(params, test.bind= ir) > > + > > + =A0 =A0def check(cmd, img): > > + =A0 =A0 =A0 =A0cmd +=3D " check %s" % img > > + =A0 =A0 =A0 =A0logging.info("Checking image '%s'..." % img) > > + =A0 =A0 =A0 =A0o =3D commands.getoutput(cmd) > > + =A0 =A0 =A0 =A0if "does not support checks" in o or "No errors" i= n o: > > + =A0 =A0 =A0 =A0 =A0 =A0return (True, "") > > + =A0 =A0 =A0 =A0return (False, o) >=20 > Here you're using the commands module. We already have an API on > autotest, utils,system() that will return the exit code, with command > logging and will raise an exception if the test fails. This would > allow for shorter code and brevity. I see you have used system_output > down on the patch, so why not make it all consistent? In one or two > cases you have to do exception handling, but in the majority of the > executions, a simple utils.system(command) would work. Here I wanted to catch the output and ignore the exit status.=20 However 'utils.system_output(cmd, ignore_status=3DTrue)' doesn't work w= ell here. Any suggestion? >=20 > Also, it would be a good idea to make all the auxiliary functions (ie= , > the ones being used by the actual test functions) as private function= s > (with an underscore _ at the beginning of its name. Another thing tha= t > occurred to me is that all functions but the top level one lack > docstrings. Will modify them. >=20 > > + > > + =A0 =A0# Subcommand 'qemu-img check' test > > + =A0 =A0# This tests will 'dd' to create a specified size file, an= d check it. > > + =A0 =A0# Then convert it to supported image_format in each loop a= nd check again. > > + =A0 =A0def check_test(cmd): > > + =A0 =A0 =A0 =A0test_image =3D params.get("image_name_dd") > > + =A0 =A0 =A0 =A0create_image_cmd =3D params.get("create_image_cmd"= ) > > + =A0 =A0 =A0 =A0create_image_cmd =3D create_image_cmd % test_image > > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(create_image_cmd= ) > > + =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestError("Failed command: %s;= Output is: %s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 (create_image_cmd, o)) > > + =A0 =A0 =A0 =A0s, o =3D check(cmd, test_image) >=20 > In the above code you are trying to qemu-img check a raw image, which > doesn't support checks. This will fail every single time unless I am > very mistaken. It doesn't matter because the error 'does not support checks' will be c= aught in '_check()'=20 during checking raw format. >=20 > > + =A0 =A0 =A0 =A0if not s: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Check image '%s' fai= led with error: %s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (test_image, o)) > > + =A0 =A0 =A0 =A0for fmt in params.get("supported_image_formats").s= plit(): > > + =A0 =A0 =A0 =A0 =A0 =A0output_image =3D test_image + ".%s" % fmt > > + =A0 =A0 =A0 =A0 =A0 =A0convert(cmd, fmt, test_image, output_image= ) > > + =A0 =A0 =A0 =A0 =A0 =A0s, o =3D check(cmd, output_image) > > + =A0 =A0 =A0 =A0 =A0 =A0if not s: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Check image = '%s' got error: %s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (output_image, o)) > > + =A0 =A0 =A0 =A0 =A0 =A0os.remove(output_image) > > + =A0 =A0 =A0 =A0os.remove(test_image) > > + > > + =A0 =A0def create(cmd, img_name, fmt, img_size=3DNone, base_img=3D= None, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 base_img_fmt=3DNone, encrypted=3D"no"= ): > > + =A0 =A0 =A0 =A0cmd +=3D " create" > > + =A0 =A0 =A0 =A0if encrypted =3D=3D "yes": > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -e" > > + =A0 =A0 =A0 =A0if base_img: > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -b %s" % base_img > > + =A0 =A0 =A0 =A0 =A0 =A0if base_img_fmt: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -F %s" % base_img_fmt > > + =A0 =A0 =A0 =A0cmd +=3D " -f %s" % fmt > > + =A0 =A0 =A0 =A0cmd +=3D " %s" % img_name > > + =A0 =A0 =A0 =A0if img_size: > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " %s" % img_size > > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(cmd) > > + =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Create image '%s' fa= iled: %s;Command:\n%s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (img_name, o, cmd)) > > + =A0 =A0 =A0 =A0logging.info("Created image '%s'" % img_name) > > + > > + =A0 =A0# Subcommand 'qemu-img create' test > > + =A0 =A0def create_test(cmd): > > + =A0 =A0 =A0 =A0image_large =3D params.get("image_name_large") > > + =A0 =A0 =A0 =A0img =3D kvm_utils.get_path(test.bindir, image_larg= e) > > + =A0 =A0 =A0 =A0img +=3D '.' + image_format > > + =A0 =A0 =A0 =A0create(cmd, img_name=3Dimg, fmt=3Dimage_format, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 img_size=3Dparams.get("image_size_lar= ge")) > > + =A0 =A0 =A0 =A0os.remove(img) > > + > > + =A0 =A0def convert(cmd, output_fmt, img_name, output_filename, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fmt=3DNone, compressed=3D"no", enc= rypted=3D"no"): > > + =A0 =A0 =A0 =A0cmd +=3D " convert" > > + =A0 =A0 =A0 =A0if compressed =3D=3D "yes": > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -c" > > + =A0 =A0 =A0 =A0if encrypted =3D=3D "yes": > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -e" > > + =A0 =A0 =A0 =A0if fmt: > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -f %s" % fmt > > + =A0 =A0 =A0 =A0cmd +=3D " -O %s" % output_fmt > > + =A0 =A0 =A0 =A0cmd +=3D " %s %s" % (img_name, output_filename) > > + =A0 =A0 =A0 =A0logging.info("Converting '%s' from format '%s' to = '%s'" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 (img_name, fmt, output_fmt)) > > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(cmd) > > + =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Image converted fail= ed; Command: %s;" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "= Output is: %s" % (cmd, o)) > > + > > + =A0 =A0# Subcommand 'qemu-img convert' test > > + =A0 =A0def convert_test(cmd): > > + =A0 =A0 =A0 =A0dest_img_fmt =3D params.get("dest_image_format") > > + =A0 =A0 =A0 =A0output_filename =3D "%s.converted_%s" % (image_nam= e, dest_img_fmt) > > + > > + =A0 =A0 =A0 =A0convert(cmd, dest_img_fmt, image_name, output_file= name, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image_format, params.get("compress= ed"), params.get("encrypted")) > > + > > + =A0 =A0 =A0 =A0if dest_img_fmt =3D=3D "qcow2": > > + =A0 =A0 =A0 =A0 =A0 =A0s, o =3D check(cmd, output_filename) > > + =A0 =A0 =A0 =A0 =A0 =A0if s: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0os.remove(output_filename) > > + =A0 =A0 =A0 =A0 =A0 =A0else: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Check image = '%s' failed with error: %s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(output_filename, o)) > > + =A0 =A0 =A0 =A0else: > > + =A0 =A0 =A0 =A0 =A0 =A0os.remove(output_filename) > > + > > + =A0 =A0def info(cmd, img, string=3DNone, fmt=3DNone): > > + =A0 =A0 =A0 =A0cmd +=3D " info" > > + =A0 =A0 =A0 =A0if fmt: > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -f %s" % fmt > > + =A0 =A0 =A0 =A0cmd +=3D " %s" % img > > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(cmd) > > + =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0logging.error("Get info of image '%s' fail= ed: %s" % (img, o)) > > + =A0 =A0 =A0 =A0 =A0 =A0return None > > + =A0 =A0 =A0 =A0if not string: > > + =A0 =A0 =A0 =A0 =A0 =A0return o > > + =A0 =A0 =A0 =A0string +=3D ": (.*)" > > + =A0 =A0 =A0 =A0str =3D re.findall(string, o) > > + =A0 =A0 =A0 =A0if str: > > + =A0 =A0 =A0 =A0 =A0 =A0return str[0] > > + =A0 =A0 =A0 =A0return None > > + > > + =A0 =A0# Subcommand 'qemu-img info' test > > + =A0 =A0def info_test(cmd): > > + =A0 =A0 =A0 =A0img_info =3D info(cmd, image_name) > > + =A0 =A0 =A0 =A0logging.info("Info of image '%s': \n%s" % (image_n= ame, img_info)) > > + =A0 =A0 =A0 =A0if not image_format in img_info: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Got unexpected forma= t of image '%s'" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "= in info test" % image_name) > > + =A0 =A0 =A0 =A0if not image_size in img_info: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Got unexpected size = of image '%s'" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "= in info test" % image_name) > > + > > + =A0 =A0# Subcommand 'qemu-img snapshot' test > > + =A0 =A0def snapshot_test(cmd): > > + =A0 =A0 =A0 =A0cmd +=3D " snapshot" > > + =A0 =A0 =A0 =A0for i in range(2): > > + =A0 =A0 =A0 =A0 =A0 =A0crtcmd =3D cmd > > + =A0 =A0 =A0 =A0 =A0 =A0sn_name =3D "snapshot%d" % i > > + =A0 =A0 =A0 =A0 =A0 =A0crtcmd +=3D " -c %s %s" % (sn_name, image_= name) > > + =A0 =A0 =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(crtcmd) > > + =A0 =A0 =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Create snaps= hot failed via command: %s;" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 "Output is: %s" % (crtcmd, o)) > > + =A0 =A0 =A0 =A0 =A0 =A0logging.info("Created snapshot '%s' in '%s= '" % (sn_name,image_name)) > > + =A0 =A0 =A0 =A0listcmd =3D cmd > > + =A0 =A0 =A0 =A0listcmd +=3D " -l %s" % image_name > > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(listcmd) > > + =A0 =A0 =A0 =A0if not ("snapshot0" in o and "snapshot1" in o and = s =3D=3D 0): > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Snapshot created fai= led or missed;" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "= snapshot list is: \n%s" % o) > > + =A0 =A0 =A0 =A0for i in range(2): > > + =A0 =A0 =A0 =A0 =A0 =A0sn_name =3D "snapshot%d" % i > > + =A0 =A0 =A0 =A0 =A0 =A0delcmd =3D cmd > > + =A0 =A0 =A0 =A0 =A0 =A0delcmd +=3D " -d %s %s" % (sn_name, image_= name) > > + =A0 =A0 =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(delcmd) > > + =A0 =A0 =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Delete snaps= hot '%s' failed: %s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (sn_name, o)) > > + > > + =A0 =A0#Subcommand 'qemu-img commit' test > > + =A0 =A0def commit_test(cmd): > > + =A0 =A0 =A0 =A0pass > > + > > + =A0 =A0def rebase(cmd, img_name, base_img, backing_fmt, mode=3D"u= nsafe"): > > + =A0 =A0 =A0 =A0cmd +=3D " rebase" > > + =A0 =A0 =A0 =A0if mode =3D=3D "unsafe": > > + =A0 =A0 =A0 =A0 =A0 =A0cmd +=3D " -u" > > + =A0 =A0 =A0 =A0cmd +=3D " -b %s -F %s %s" % (base_img, backing_fm= t, img_name) > > + =A0 =A0 =A0 =A0logging.info("Trying to rebase '%s' to '%s'..." % = (img_name, base_img)) > > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(cmd) > > + =A0 =A0 =A0 =A0if s !=3D 0: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestError("Failed to rebase '%= s' to '%s': %s" % > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 (img_name, base_img, o)) > > + > > + =A0 =A0# Subcommand 'qemu-img rebase' test > > + =A0 =A0# Change the backing file of a snapshot image in "unsafe m= ode": > > + =A0 =A0# Assume the previous backing file had missed and we just = have to change > > + =A0 =A0# reference of snapshot to new one. After change the backi= ng file of a > > + =A0 =A0# snapshot image in unsafe mode, the snapshot should work = still. > > + =A0 =A0def rebase_test(cmd): > > + =A0 =A0 =A0 =A0if not 'rebase' in utils.system_output(cmd+' --hel= p',ignore_status=3DTrue): > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestNAError("Current kvm user = space version does not" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0" support 'rebase' subcommand") > > + =A0 =A0 =A0 =A0sn_fmt =3D params.get("snapshot_format", "qcow2") > > + =A0 =A0 =A0 =A0sn1 =3D params.get("image_name_snapshot1") > > + =A0 =A0 =A0 =A0sn1 =3D kvm_utils.get_path(test.bindir, sn1) + ".%= s" % sn_fmt > > + =A0 =A0 =A0 =A0base_img =3D kvm_vm.get_image_filename(params, tes= t.bindir) > > + =A0 =A0 =A0 =A0create(cmd, sn1, sn_fmt, base_img=3Dbase_img, base= _img_fmt=3Dimage_format) > > + > > + =A0 =A0 =A0 =A0# Create snapshot2 based on snapshot1 > > + =A0 =A0 =A0 =A0sn2 =3D params.get("image_name_snapshot2") > > + =A0 =A0 =A0 =A0sn2 =3D kvm_utils.get_path(test.bindir, sn2) + ".%= s" % sn_fmt > > + =A0 =A0 =A0 =A0create(cmd, sn2, sn_fmt, base_img=3Dsn1, base_img_= fmt=3Dsn_fmt) > > + > > + =A0 =A0 =A0 =A0rebase_mode =3D params.get("rebase_mode") > > + =A0 =A0 =A0 =A0if rebase_mode =3D=3D "unsafe": > > + =A0 =A0 =A0 =A0 =A0 =A0os.remove(sn1) > > + > > + =A0 =A0 =A0 =A0rebase(cmd, sn2, base_img, image_format, mode=3Dre= base_mode) > > + > > + =A0 =A0 =A0 =A0# Check sn2's format and backing_file > > + =A0 =A0 =A0 =A0actual_base_img =3D info(cmd, sn2, "backing file") > > + =A0 =A0 =A0 =A0base_img_name =3D os.path.basename(params.get("ima= ge_name")) > > + =A0 =A0 =A0 =A0if not base_img_name in actual_base_img: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("After rebase the bac= king_file of 'sn2' is " > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "= '%s' which is not expected as '%s'" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 %= (actual_base_img, base_img_name)) > > + =A0 =A0 =A0 =A0s, o =3D check(cmd, sn2) > > + =A0 =A0 =A0 =A0if not s: > > + =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("Check image '%s' fai= led after rebase;" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "= got error: %s" % (sn2, o)) > > + =A0 =A0 =A0 =A0try: > > + =A0 =A0 =A0 =A0 =A0 =A0os.remove(sn2) > > + =A0 =A0 =A0 =A0 =A0 =A0os.remove(sn1) > > + =A0 =A0 =A0 =A0except: > > + =A0 =A0 =A0 =A0 =A0 =A0pass > > + > > + =A0 =A0# Here starts test > > + =A0 =A0subcommand =3D params.get("subcommand") > > + =A0 =A0eval("%s_test(cmd)" % subcommand) > > diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/= kvm/tests_base.cfg.sample > > index 2d03f1f..e7670c7 100644 > > --- a/client/tests/kvm/tests_base.cfg.sample > > +++ b/client/tests/kvm/tests_base.cfg.sample > > @@ -273,6 +273,46 @@ variants: > > =A0 =A0 =A0 =A0 type =3D physical_resources_check > > =A0 =A0 =A0 =A0 catch_uuid_cmd =3D dmidecode | awk -F: '/UUID/ {pri= nt $2}' > > > > + =A0 =A0- qemu_img: > > + =A0 =A0 =A0 =A0type =3D qemu_img > > + =A0 =A0 =A0 =A0vms =3D '' > > + =A0 =A0 =A0 =A0variants: > > + =A0 =A0 =A0 =A0 =A0 =A0- check: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D check > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image_name_dd =3D dd_created_image > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0force_create_image_dd =3D no > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0remove_image_dd =3D yes > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0create_image_cmd =3D "dd if=3D/dev= /zero of=3D%s bs=3D1G count=3D1" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Test the convertion from 'dd_ima= ge_name' to specified format > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0supported_image_formats =3D qcow2 = raw > > + =A0 =A0 =A0 =A0 =A0 =A0- create: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D create > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0images +=3D " large" > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0force_create_image_large =3D yes > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image_size_large =3D 1G > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image_name_large =3D create_large_= image > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0remove_image_large =3D yes > > + =A0 =A0 =A0 =A0 =A0 =A0- convert: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D convert > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0variants: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0- to_qcow2: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dest_image_format = =3D qcow2 > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0compressed =3D no > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0encrypted =3D no > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0- to_raw: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dest_image_format = =3D raw > > + =A0 =A0 =A0 =A0 =A0 =A0- snapshot: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D snapshot > > + =A0 =A0 =A0 =A0 =A0 =A0- commit: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D commit > > + =A0 =A0 =A0 =A0 =A0 =A0- info: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D info > > + =A0 =A0 =A0 =A0 =A0 =A0- rebase: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0subcommand =3D rebase > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rebase_mode =3D unsafe > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image_name_snapshot1 =3D sn1 > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image_name_snapshot2 =3D sn2 > > + > > =A0# NICs > > =A0variants: > > =A0 =A0 - @rtl8139: > > -- > > 1.5.5.6 > > > > _______________________________________________ > > Autotest mailing list > > Autotest@test.kernel.org > > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > > >=20 >=20 >=20 > --=20 > Lucas > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html