public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM Test: Add check_image script as post_command script of qcow2 variant.
@ 2010-02-24 10:30 Feng Yang
  0 siblings, 0 replies; 4+ messages in thread
From: Feng Yang @ 2010-02-24 10:30 UTC (permalink / raw)
  To: autotest; +Cc: kvm, Feng Yang

Add check_image.py in scripts folder.  It will performance qemu-img info
and qemu-img check.
Add check_image.py as post command of qcow2 variant.

Signed-off-by: Feng Yang <fyang@redhat.com>
---
 client/tests/kvm/scripts/check_image.py |   96 +++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample  |    3 +
 2 files changed, 99 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/scripts/check_image.py

diff --git a/client/tests/kvm/scripts/check_image.py b/client/tests/kvm/scripts/check_image.py
new file mode 100755
index 0000000..f66cd99
--- /dev/null
+++ b/client/tests/kvm/scripts/check_image.py
@@ -0,0 +1,96 @@
+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')
+        self.qemu_img_check = True
+        cmd = "%s |grep check" % self.qemu_img_path
+        (s1, output) = commands.getstatusoutput(cmd)
+        if s1:
+            self.qemu_img_check = False
+            print "qemu-img check command is not available!"
+        cmd = "%s |grep info" % self.qemu_img_path
+        (s2, output) = commands.getstatusoutput(cmd)
+        if s2:
+            self.qemu_img_check = False
+            print "qemu-img info command is not available!"
+
+    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)
+        print output
+        if status or (cmd_type == "check" and not "No errors" in output):
+            msg = "Command %s failed" % cmd
+            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()
+    if image_check.qemu_img_check:
+        image_check.check_image()
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 4516ed0..6ad7573 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -1042,6 +1042,9 @@ 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
-- 
1.5.5.6


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] KVM Test: Add check_image script as post_command script of qcow2 variant.
@ 2010-01-29 10:17 Feng Yang
  2010-02-10 16:23 ` Lucas Meneghel Rodrigues
  0 siblings, 1 reply; 4+ messages in thread
From: Feng Yang @ 2010-01-29 10:17 UTC (permalink / raw)
  To: autotest; +Cc: kvm

Add check_image.py in scripts folder.  It will performance qemu-img info
and qemu-img check.
Add check_image.py as post command of qcow2 variant.

Signed-off-by: Feng Yang <fyang@redhat.com>
---
 client/tests/kvm/scripts/check_image.py |   89 +++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample  |    6 ++
 2 files changed, 95 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/scripts/check_image.py

diff --git a/client/tests/kvm/scripts/check_image.py b/client/tests/kvm/scripts/check_image.py
new file mode 100755
index 0000000..a37f055
--- /dev/null
+++ b/client/tests/kvm/scripts/check_image.py
@@ -0,0 +1,89 @@
+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')
+        if os.environ.has_key('KVM_TEST_img_to_check'):
+            img_to_check = os.environ['KVM_TEST_img_to_check'].split()
+        else:
+            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)
+
+
+    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.
+        """
+        if os.environ.has_key('KVM_TEST_qemu_img_binary'):
+            qemu_img_path = os.environ['KVM_TEST_qemu_img_binary']
+        else:
+            qemu_img_path = os.path.join(self.kvm_dir, 'qemu-img')
+        cmd = ' '.join([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 '\
+                                  'for details!')
+
+
+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 2d03f1f..33f9586 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -938,6 +938,12 @@ virtio|virtio_blk|e1000:
 variants:
     - @qcow2:
         image_format = qcow2
+        kill_vm = yes
+        post_command = python scripts/check_image.py
+        remove_image = no
+        # img_to_check =
+        post_command_timeout = 600
+
     - vmdk:
         only Fedora Ubuntu Windows
         only smp2
-- 
1.5.5.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-02-24 10:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-24 10:30 [PATCH] KVM Test: Add check_image script as post_command script of qcow2 variant Feng Yang
  -- strict thread matches above, loose matches on Subject: below --
2010-01-29 10:17 Feng Yang
2010-02-10 16:23 ` Lucas Meneghel Rodrigues
2010-02-22  9:29   ` Feng Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox