Skip to contentSkip to conversation

Removing scripts/check_image.py and scripts/hugepage.py

PATCH New Lucas Meneghel Rodrigues 1 participant 6 messages Jan 19, 2011 KVM

lore
Share & tools
lore
#0 lore raw

cover Removing scripts/check_image.py and scripts/hugepage.py

Fixed patchsets according to Michael's comments and re-sending them.

The purpose of this patchsets is start work on superseding and removing scripts under the kvm test scripts/ subdirectory, by turning them regular parts of the kvm autotest framework.

Lucas Meneghel Rodrigues (5):
KVM test: Introduce check_image postprocess directive v2 KVM test: Modify enospc test to not require scripts/check_image.py v2 KVM test: Removing scripts/check_image.py
KVM test: Turning hugepages setup into KVM autotest infrastructure v2 KVM test: Removing scripts/hugepage.py

 client/tests/kvm/kvm_preprocessing.py   |   11 +++-
 client/tests/kvm/kvm_utils.py           |  101 ++++++++++++++++++++++++++
 client/tests/kvm/kvm_vm.py              |   60 ++++++++++++++++
 client/tests/kvm/scripts/check_image.py |   99 --------------------------
 client/tests/kvm/scripts/hugepage.py    |  118 -------------------------------
 client/tests/kvm/tests/enospc.py        |   13 ++--
 client/tests/kvm/tests_base.cfg.sample  |    9 +--
 7 files changed, 180 insertions(+), 231 deletions(-)
 delete mode 100644 client/tests/kvm/scripts/check_image.py
 delete mode 100755 client/tests/kvm/scripts/hugepage.py
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/5 KVM test: Introduce check_image postprocess directive v2

With check_image_foo = yes, KVM autotest will use qemu-img to perform checks on the qcow2 image.

This new functionality intends to replace the script check_image.py. The plan is to supersede most of the pre/post scripts in place throughout KVM autotest.

Changes from v1:
- We already only raise exceptions during postprocessing only if the test passed, and that avoids masking the original test error reason. So eliminate the check_image_critical logic altogether, so we always raise errors.

---
 client/tests/kvm/kvm_preprocessing.py  |    3 +-
 client/tests/kvm/kvm_vm.py             |   60 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    6 +---
 3 files changed, 63 insertions(+), 6 deletions(-)
client/tests/kvm/kvm_preprocessing.py +2 -1
index 56acf0c..4a6e0f8 100644
@@ -93,11 +93,12 @@ def preprocess_vm(test, params, env, name):
 def postprocess_image(test, params):
     """
     Postprocess a single QEMU image according to the instructions in params.
-    Currently this function just removes an image if requested.
 
     @param test: An Autotest test object.
     @param params: A dict containing image postprocessing parameters.
     """
+    if params.get("check_image") == "yes":
+        kvm_vm.check_image(params, test.bindir)
     if params.get("remove_image") == "yes":
         kvm_vm.remove_image(params, test.bindir)
 
client/tests/kvm/kvm_vm.py +60 -0

72 lines not on this page · raw message

client/tests/kvm/tests_base.cfg.sample +1 -5
index 28064a8..3299af7 100644
@@ -2357,11 +2357,7 @@ kdump:
 variants:
     - @qcow2:
         image_format = qcow2
-        post_command += " python scripts/check_image.py;"
-        post_command_timeout = 600
-        post_command_noncritical = yes
-        ioquit:
-            post_command_noncritical = no
+        check_image = yes
     - vmdk:
         no ioquit
         only Fedora Ubuntu Windows
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 2/5 KVM test: Modify enospc test to not require scripts/check_image.py v2

In reply to Lucas Meneghel Rodrigues

With this we prepare to remove the aforementioned script.

Changes from v1:
* Accounting for the lost of the check_image_critical logic, now just trap kvm_vm.VMError() exceptions and log them as an error if they happen.

---
 client/tests/kvm/tests/enospc.py |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
client/tests/kvm/tests/enospc.py +7 -6
index 2d8b628..6a149f9 100644
@@ -1,7 +1,7 @@
 import logging, commands, time, os, re
 from autotest_lib.client.common_lib import error
 from autotest_lib.client.bin import utils
-import kvm_test_utils
+import kvm_test_utils, kvm_vm
 
 
 def run_enospc(test, params, env):
@@ -46,11 +46,12 @@ def run_enospc(test, params, env):
         if "paused" in status:
             pause_n += 1
             logging.info("Checking all images in use by the VM")
-            script_path = os.path.join(test.bindir, "scripts/check_image.py")
-            try:
-                cmd_result = utils.run('python %s' % script_path)
-            except error.CmdError, e:
-                logging.debug(e.result_obj.stdout)
+            for image_name in vm.params.objects("images"):
+                image_params = vm.params.object_params(image_name)
+                try:
+                    kvm_vm.check_image(image_params, test.bindir)
+                except kvm_vm.VMError, e:
+                    logging.error(e)
             logging.info("Guest paused, extending Logical Volume size")
             try:
                 cmd_result = utils.run("lvextend -L +200M /dev/vgtest/lvtest")
Signature · 1 line
1.7.3.4
#3 lore raw

PATCH 3/5 KVM test: Removing scripts/check_image.py

In reply to Lucas Meneghel Rodrigues

As its functionality was implemented as part of the framework on previous patches.

---
 client/tests/kvm/scripts/check_image.py |   99 -------------------------------
 1 files changed, 0 insertions(+), 99 deletions(-)
 delete mode 100644 client/tests/kvm/scripts/check_image.py
client/tests/kvm/scripts/check_image.py deleted +0 -99
deleted file mode 100644
index 2b5c227..0000000
@@ -1,99 +0,0 @@
-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 "Command qemu-img check not available, not checking..."
-        cmd = "%s |grep info" % self.qemu_img_path
-        (s2, output) = commands.getstatusoutput(cmd)
-        if s2:
-            self.qemu_img_check = False
-            print "Command qemu-img info not available, not checking..."
-
-    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 image with command %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:
-            if not os.path.exists(image_path):
-                print "Image %s does not exist!" % image_path
-                continue
-            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 were found, please check log!')
-
-
-if __name__ == "__main__":
-    image_check = ImageCheck()
-    if image_check.qemu_img_check:
-        image_check.check_image()
Signature · 1 line
1.7.3.4
#4 lore raw

PATCH 4/5 KVM test: Turning hugepages setup into KVM autotest infrastructure v2

In reply to Lucas Meneghel Rodrigues

So we can get rid of scripts/hugepage.py. The implementation strategy is to have a kvm_utils.HugePageConfig class that can do both hugepages setup and cleanup, and call it during pre/postprocessing.

Changes from v1:
- Stylistic changes on usage of error.context as suggested by Michael

---
 client/tests/kvm/kvm_preprocessing.py  |    8 +++
 client/tests/kvm/kvm_utils.py          |  101 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    3 +-
 3 files changed, 110 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_preprocessing.py +8 -0
index 4a6e0f8..41455cf 100644
@@ -254,6 +254,10 @@ def preprocess(test, params, env):
     logging.debug("KVM userspace version: %s" % kvm_userspace_version)
     test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version})
 
+    if params.get("setup_hugepages") == "yes":
+        h = kvm_utils.HugePageConfig(params)
+        h.setup()
+
     # Execute any pre_commands
     if params.get("pre_command"):
         process_command(test, params, env, params.get("pre_command"),
@@ -350,6 +354,10 @@ def postprocess(test, params, env):
         env["tcpdump"].close()
         del env["tcpdump"]
 
+    if params.get("setup_hugepages") == "yes":
+        h = kvm_utils.HugePageConfig(params)
+        h.cleanup()
+
     # Execute any post_commands
     if params.get("post_command"):
         process_command(test, params, env, params.get("post_command"),
client/tests/kvm/kvm_utils.py +101 -0

107 lines not on this page · raw message

client/tests/kvm/tests_base.cfg.sample +1 -2
index 3299af7..360cf80 100644
@@ -2375,8 +2375,7 @@ variants:
 variants:
     - @smallpages:
     - hugepages:
-        pre_command += " scripts/hugepage.py /mnt/kvm_hugepage;"
-        post_command += " umount /mnt/kvm_hugepage && echo 0 > /proc/sys/vm/nr_hugepages;"
+        setup_hugepages = yes
         extra_params += " -mem-path /mnt/kvm_hugepage"
 
 
Signature · 1 line
1.7.3.4
#5 lore raw

PATCH 5/5 KVM test: Removing scripts/hugepage.py

In reply to Lucas Meneghel Rodrigues

Now that its functionality has been reimplemented as KVM test infrastructure.

---
 client/tests/kvm/scripts/hugepage.py |  118 ----------------------------------
 1 files changed, 0 insertions(+), 118 deletions(-)
 delete mode 100755 client/tests/kvm/scripts/hugepage.py
client/tests/kvm/scripts/hugepage.py deleted +0 -118
deleted file mode 100755
index 8a1b0f6..0000000
@@ -1,118 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-import os, sys, time
-
-"""
-Simple script to allocate enough hugepages for KVM testing purposes.
-"""
-
-class HugePageError(Exception):
-    """
-    Simple wrapper for the builtin Exception class.
-    """
-    pass
-
-
-class HugePage:
-    def __init__(self, hugepage_path=None):
-        """
-        Gets environment variable values and calculates the target number
-        of huge memory pages.
-
-        @param hugepage_path: Path where to mount hugetlbfs path, if not
-                yet configured.
-        """
-        self.vms = len(os.environ['KVM_TEST_vms'].split())
-        self.mem = int(os.environ['KVM_TEST_mem'])
-        try:
-            self.max_vms = int(os.environ['KVM_TEST_max_vms'])
-        except KeyError:
-            self.max_vms = 0
-
-        if hugepage_path:
-            self.hugepage_path = hugepage_path
-        else:
-            self.hugepage_path = '/mnt/kvm_hugepage'
-
-        self.hugepage_size = self.get_hugepage_size()
-        self.target_hugepages = self.get_target_hugepages()
-        print "Number of VMs this test will use: %d" % self.vms
-        print "Amount of memory used by each vm: %s" % self.mem
-        print ("System setting for large memory page size: %s" %
-               self.hugepage_size)
-        print ("Number of large memory pages needed for this test: %s" %
-               self.target_hugepages)
-
-
-    def get_hugepage_size(self):
-        """
-        Get the current system setting for huge memory page size.
-        """
-        meminfo = open('/proc/meminfo', 'r').readlines()
-        huge_line_list = [h for h in meminfo if h.startswith("Hugepagesize")]
-        try:
-            return int(huge_line_list[0].split()[1])
-        except ValueError, e:
-            raise HugePageError("Could not get huge page size setting from "
-                                "/proc/meminfo: %s" % e)
-
-
-    def get_target_hugepages(self):
-        """
-        Calculate the target number of hugepages for testing purposes.
-        """
-        if self.vms < self.max_vms:
-            self.vms = self.max_vms
-        # memory of all VMs plus qemu overhead of 64MB per guest
-        vmsm = (self.vms * self.mem) + (self.vms * 64)
-        return int(vmsm * 1024 / self.hugepage_size)
-
-
-    def set_hugepages(self):
-        """
-        Sets the hugepage limit to the target hugepage value calculated.
-        """
-        hugepage_cfg = open("/proc/sys/vm/nr_hugepages", "r+")
-        hp = hugepage_cfg.readline()
-        while int(hp) < self.target_hugepages:
-            loop_hp = hp
-            hugepage_cfg.write(str(self.target_hugepages))
-            hugepage_cfg.flush()
-            hugepage_cfg.seek(0)
-            hp = int(hugepage_cfg.readline())
-            if loop_hp == hp:
-                raise HugePageError("Cannot set the kernel hugepage setting "
-                                    "to the target value of %d hugepages." %
-                                    self.target_hugepages)
-        hugepage_cfg.close()
-        print ("Successfuly set %s large memory pages on host " %
-               self.target_hugepages)
-
-
-    def mount_hugepage_fs(self):
-        """
-        Verify if there's a hugetlbfs mount set. If there's none, will set up
-        a hugetlbfs mount using the class attribute that defines the mount
-        point.
-        """
-        if not os.path.ismount(self.hugepage_path):
-            if not os.path.isdir(self.hugepage_path):
-                os.makedirs(self.hugepage_path)
-            cmd = "mount -t hugetlbfs none %s" % self.hugepage_path
-            if os.system(cmd):
-                raise HugePageError("Cannot mount hugetlbfs path %s" %
-                                    self.hugepage_path)
-
-
-    def setup(self):
-        self.set_hugepages()
-        self.mount_hugepage_fs()
-
-
-if __name__ == "__main__":
-    if len(sys.argv) < 2:
-        huge_page = HugePage()
-    else:
-        huge_page = HugePage(sys.argv[1])
-
-    huge_page.setup()
Signature · 1 line
1.7.3.4