From patchwork Mon Feb 22 09:30:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Yang X-Patchwork-Id: 81108 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1M9UqM7009822 for ; Mon, 22 Feb 2010 09:30:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149Ab0BVJau (ORCPT ); Mon, 22 Feb 2010 04:30:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58907 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752041Ab0BVJau (ORCPT ); Mon, 22 Feb 2010 04:30:50 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1M9UmbJ031636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Feb 2010 04:30:48 -0500 Received: from localhost.localdomain ([10.66.91.72]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1M9Uigq030071; Mon, 22 Feb 2010 04:30:45 -0500 From: Feng Yang To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Feng Yang Subject: [Autotest][PATCH] KVM Test: Add check_image script as post_command script of qcow2 variant.-V2 Date: Mon, 22 Feb 2010 17:30:44 +0800 Message-Id: <1266831044-15454-1-git-send-email-fyang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 22 Feb 2010 09:30:52 +0000 (UTC) diff --git a/client/tests/kvm/scripts/check_image.py b/client/tests/kvm/scripts/check_image.py new file mode 100755 index 0000000..97f5136 --- /dev/null +++ b/client/tests/kvm/scripts/check_image.py @@ -0,0 +1,85 @@ +import os, sys, commands + + +class ImageCheckError(Exception): + """ + Simple wrapper for the builtin Exception class. + """ + pass + + +class ImageCheck(object): + """ + Check qcow2 image by qemu-img info/check command. + """ + def __init__(self): + """ + Gets params from environment variables and sets class attributes. + """ + self.image_path_list = [] + client_dir = os.environ['AUTODIR'] + self.kvm_dir = os.path.join(client_dir, 'tests/kvm') + img_to_check = os.environ['KVM_TEST_images'].split() + + for img in img_to_check: + img_name_str = "KVM_TEST_image_name_%s" % img + if not os.environ.has_key(img_name_str): + img_name_str = "KVM_TEST_image_name" + img_format_str = "KVM_TEST_image_format_%s" % img + if os.environ.has_key(img_format_str): + image_format = os.environ[img_format_str] + else: + image_format = os.environ['KVM_TEST_image_format'] + if image_format != "qcow2": + continue + image_name = os.environ[img_name_str] + image_filename = "%s.%s" % (image_name, image_format) + image_filename = os.path.join(self.kvm_dir, image_filename) + self.image_path_list.append(image_filename) + if os.environ.has_key('KVM_TEST_qemu_img_binary'): + self.qemu_img_path = os.environ['KVM_TEST_qemu_img_binary'] + else: + self.qemu_img_path = os.path.join(self.kvm_dir, 'qemu-img') + + + def exec_img_cmd(self, cmd_type, image_path): + """ + Run qemu-img info/check on given image. + + @param cmd_type: Sub command used together with qemu. + @param image_path: Real path of the image. + """ + cmd = ' '.join([self.qemu_img_path, cmd_type, image_path]) + print "checking with %s" % cmd + (status, output) = commands.getstatusoutput(cmd) + if status or (cmd_type == "check" and not "No errors" in output): + msg = "Command %s failed" % cmd + print output + return False, msg + else: + return True, '' + + + def check_image(self): + """ + Run qemu-img info/check to check the image in list. + + If the image checking is failed, raise an exception. + """ + # Check all the image in list. + errmsg = [] + for image_path in self.image_path_list: + s, o = self.exec_img_cmd('info', image_path) + if not s: + errmsg.append(o) + s, o = self.exec_img_cmd('check', image_path) + if not s: + errmsg.append(o) + + if len(errmsg) > 0: + raise ImageCheckError('Errors are found and please check log!') + + +if __name__ == "__main__": + image_check = ImageCheck() + image_check.check_image() diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index e9fdd05..159c1be 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -1019,6 +1019,10 @@ virtio|virtio_blk|e1000: variants: - @qcow2: image_format = qcow2 + post_command = python scripts/check_image.py + remove_image = no + post_command_timeout = 600 + - vmdk: only Fedora Ubuntu Windows only smp2