kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 02/11] virt: Introducing virt_test.virt_test class
Date: Tue, 11 Oct 2011 18:07:08 -0300	[thread overview]
Message-ID: <1318367237-26081-3-git-send-email-lmr@redhat.com> (raw)
In-Reply-To: <1318367237-26081-1-git-send-email-lmr@redhat.com>

During the process of implementing the libvirt test,
we've noticed that the whole mechanism implemented
by the KVM test (subtest loader, use of env file, params)
could be turned into common infrastructure. So move
all implementation to a class called virt_test.

We believe most virt test classes don't even need to be
implemented with this common infrastructure in place.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/kvm.py  |  126 +-------------------------------------------
 client/virt/virt_test.py |  131 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+), 123 deletions(-)
 create mode 100644 client/virt/virt_test.py

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index 3d5eef2..8388391 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -1,10 +1,7 @@
-import os, logging, imp, sys
-from autotest_lib.client.bin import test
-from autotest_lib.client.common_lib import error
-from autotest_lib.client.virt import virt_utils, virt_env_process
+from autotest_lib.client.virt import virt_test
 
 
-class kvm(test.test):
+class kvm(virt_test.virt_test):
     """
     Suite of KVM virtualization functional tests.
     Contains tests for testing both KVM kernel code and userspace code.
@@ -20,121 +17,4 @@ class kvm(test.test):
     @see: http://www.linux-kvm.org/page/KVM-Autotest/Client_Install
             (Online doc - Getting started with KVM testing)
     """
-    version = 1
-    env_version = 1
-
-
-    def initialize(self, params):
-        # Change the value of the preserve_srcdir attribute according to
-        # the value present on the configuration file (defaults to yes)
-        if params.get("preserve_srcdir", "yes") == "yes":
-            self.preserve_srcdir = True
-        dirname = os.path.dirname(sys.modules[__name__].__file__)
-        clientdir = os.path.abspath(os.path.join(dirname, "..", ".."))
-        self.virtdir = os.path.join(clientdir, "virt")
-
-
-    def run_once(self, params):
-        # Convert params to a Params object
-        params = virt_utils.Params(params)
-
-        # If a dependency test prior to this test has failed, let's fail
-        # it right away as TestNA.
-        if params.get("dependency_failed") == 'yes':
-            raise error.TestNAError("Test dependency failed")
-
-        # Report the parameters we've received and write them as keyvals
-        logging.debug("Test parameters:")
-        keys = params.keys()
-        keys.sort()
-        for key in keys:
-            logging.debug("    %s = %s", key, params[key])
-            self.write_test_keyval({key: params[key]})
-
-        # Set the log file dir for the logging mechanism used by kvm_subprocess
-        # (this must be done before unpickling env)
-        virt_utils.set_log_file_dir(self.debugdir)
-
-        # Open the environment file
-        env_filename = os.path.join(self.bindir, params.get("env", "env"))
-        env = virt_utils.Env(env_filename, self.env_version)
-
-        test_passed = False
-
-        try:
-            try:
-                try:
-                    # Get the test routine corresponding to the specified
-                    # test type
-                    t_type = params.get("type")
-                    # Verify if we have the correspondent source file for it
-                    virt_dir = os.path.dirname(virt_utils.__file__)
-                    subtest_dir_virt = os.path.join(virt_dir, "tests")
-                    subtest_dir_kvm = os.path.join(self.bindir, "tests")
-                    subtest_dir = None
-                    for d in [subtest_dir_kvm, subtest_dir_virt]:
-                        module_path = os.path.join(d, "%s.py" % t_type)
-                        if os.path.isfile(module_path):
-                            subtest_dir = d
-                            break
-                    if subtest_dir is None:
-                        raise error.TestError("Could not find test file %s.py "
-                                              "on either %s or %s directory" %
-                                              (t_type, subtest_dir_kvm,
-                                              subtest_dir_virt))
-                    # Load the test module
-                    f, p, d = imp.find_module(t_type, [subtest_dir])
-                    test_module = imp.load_module(t_type, f, p, d)
-                    f.close()
-
-                    # Preprocess
-                    try:
-                        virt_env_process.preprocess(self, params, env)
-                    finally:
-                        env.save()
-                    # Run the test function
-                    run_func = getattr(test_module, "run_%s" % t_type)
-                    try:
-                        run_func(self, params, env)
-                    finally:
-                        env.save()
-                    test_passed = True
-
-                except Exception, e:
-                    logging.error("Test failed: %s: %s",
-                                  e.__class__.__name__, e)
-                    try:
-                        virt_env_process.postprocess_on_error(
-                            self, params, env)
-                    finally:
-                        env.save()
-                    raise
-
-            finally:
-                # Postprocess
-                try:
-                    try:
-                        virt_env_process.postprocess(self, params, env)
-                    except Exception, e:
-                        if test_passed:
-                            raise
-                        logging.error("Exception raised during "
-                                      "postprocessing: %s", e)
-                finally:
-                    env.save()
-
-        except Exception, e:
-            if params.get("abort_on_error") != "yes":
-                raise
-            # Abort on error
-            logging.info("Aborting job (%s)", e)
-            for vm in env.get_all_vms():
-                if vm.is_dead():
-                    continue
-                logging.info("VM '%s' is alive.", vm.name)
-                for m in vm.monitors:
-                    logging.info("'%s' has a %s monitor unix socket at: %s",
-                                 vm.name, m.protocol, m.filename)
-                logging.info("The command line used to start '%s' was:\n%s",
-                             vm.name, vm.make_qemu_command())
-            raise error.JobError("Abort requested (%s)" % e)
+    pass
diff --git a/client/virt/virt_test.py b/client/virt/virt_test.py
new file mode 100644
index 0000000..e18081b
--- /dev/null
+++ b/client/virt/virt_test.py
@@ -0,0 +1,131 @@
+import os, sys, logging, imp
+
+from autotest_lib.client.bin import test
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.virt import virt_utils, virt_env_process
+
+
+class virt_test(test.test):
+    """
+    Shared test class infrastructure for tests such as the KVM test.
+
+    It comprises a subtest load system, use of parameters, and an env
+    file, all code that can be reused among those virt tests.
+    """
+    version = 1
+    env_version = 1
+
+
+    def initialize(self, params):
+        # Change the value of the preserve_srcdir attribute according to
+        # the value present on the configuration file (defaults to yes)
+        if params.get("preserve_srcdir", "yes") == "yes":
+            self.preserve_srcdir = True
+        self.virtdir = os.path.dirname(sys.modules[__name__].__file__)
+
+
+    def run_once(self, params):
+        # Convert params to a Params object
+        params = virt_utils.Params(params)
+
+        # If a dependency test prior to this test has failed, let's fail
+        # it right away as TestNA.
+        if params.get("dependency_failed") == 'yes':
+            raise error.TestNAError("Test dependency failed")
+
+        # Report the parameters we've received and write them as keyvals
+        logging.debug("Test parameters:")
+        keys = params.keys()
+        keys.sort()
+        for key in keys:
+            logging.debug("    %s = %s", key, params[key])
+            self.write_test_keyval({key: params[key]})
+
+        # Set the log file dir for the logging mechanism used by kvm_subprocess
+        # (this must be done before unpickling env)
+        virt_utils.set_log_file_dir(self.debugdir)
+
+        # Open the environment file
+        env_filename = os.path.join(self.bindir, params.get("env", "env"))
+        env = virt_utils.Env(env_filename, self.env_version)
+
+        test_passed = False
+
+        try:
+            try:
+                try:
+                    # Get the test routine corresponding to the specified
+                    # test type
+                    t_type = params.get("type")
+                    # Verify if we have the correspondent source file for it
+                    virt_dir = os.path.dirname(virt_utils.__file__)
+                    subtest_dir_common = os.path.join(virt_dir, "tests")
+                    subtest_dir_test = os.path.join(self.bindir, "tests")
+                    subtest_dir = None
+                    for d in [subtest_dir_test, subtest_dir_common]:
+                        module_path = os.path.join(d, "%s.py" % t_type)
+                        if os.path.isfile(module_path):
+                            subtest_dir = d
+                            break
+                    if subtest_dir is None:
+                        raise error.TestError("Could not find test file %s.py "
+                                              "on either %s or %s directory" %
+                                              (t_type, subtest_dir_test,
+                                              subtest_dir_common))
+                    # Load the test module
+                    f, p, d = imp.find_module(t_type, [subtest_dir])
+                    test_module = imp.load_module(t_type, f, p, d)
+                    f.close()
+
+                    # Preprocess
+                    try:
+                        virt_env_process.preprocess(self, params, env)
+                    finally:
+                        env.save()
+                    # Run the test function
+                    run_func = getattr(test_module, "run_%s" % t_type)
+                    try:
+                        run_func(self, params, env)
+                    finally:
+                        env.save()
+                    test_passed = True
+
+                except Exception, e:
+                    logging.error("Test failed: %s: %s",
+                                  e.__class__.__name__, e)
+                    try:
+                        virt_env_process.postprocess_on_error(
+                            self, params, env)
+                    finally:
+                        env.save()
+                    raise
+
+            finally:
+                # Postprocess
+                try:
+                    try:
+                        virt_env_process.postprocess(self, params, env)
+                    except Exception, e:
+                        if test_passed:
+                            raise
+                        logging.error("Exception raised during "
+                                      "postprocessing: %s", e)
+                finally:
+                    env.save()
+
+        except Exception, e:
+            if params.get("abort_on_error") != "yes":
+                raise
+            # Abort on error
+            logging.info("Aborting job (%s)", e)
+            if params.get("vm_type") == "kvm":
+                for vm in env.get_all_vms():
+                    if vm.is_dead():
+                        continue
+                    logging.info("VM '%s' is alive.", vm.name)
+                    for m in vm.monitors:
+                        logging.info("'%s' has a %s monitor unix socket at: %s",
+                                     vm.name, m.protocol, m.filename)
+                    logging.info("The command line used to start '%s' was:\n%s",
+                                 vm.name, vm.make_qemu_command())
+                raise error.JobError("Abort requested (%s)" % e)
-- 
1.7.6.4

  reply	other threads:[~2011-10-11 21:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-11 21:07 [PATCH 00/11] [RFC] Libvirt test v2 Lucas Meneghel Rodrigues
2011-10-11 21:07 ` Lucas Meneghel Rodrigues [this message]
2011-10-11 21:07 ` [PATCH 03/11] Moving unattended_install test from kvm test to common virt location Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 04/11] Moving get_started code to client.virt.virt_utils Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 05/11] virt: Introducing libvirt VM class Lucas Meneghel Rodrigues
2011-10-12  6:51   ` [Autotest] " Amos Kong
2011-10-12  8:14   ` Daniel P. Berrange
2011-10-13 17:26     ` Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 06/11] virt: Introducing libvirt monitor Lucas Meneghel Rodrigues
2011-10-12  7:48   ` [Autotest] " Amos Kong
2011-10-13 17:12     ` Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 07/11] virt.virt_env_process: Add libvirt vm handling Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 08/11] client.tests: Introducing libvirt test Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 09/11] Virt: builtin HTTP server for unattended installs Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 10/11] Virt: support XEN via libvirt and auto url installer Lucas Meneghel Rodrigues
2011-10-11 21:07 ` [PATCH 11/11] Virt: add support for XEN via libvirt installs and auto url Lucas Meneghel Rodrigues

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1318367237-26081-3-git-send-email-lmr@redhat.com \
    --to=lmr@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).