From patchwork Tue Sep 15 18:02:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 47701 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8FI3770007115 for ; Tue, 15 Sep 2009 18:03:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754552AbZIOSDA (ORCPT ); Tue, 15 Sep 2009 14:03:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754059AbZIOSDA (ORCPT ); Tue, 15 Sep 2009 14:03:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55744 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752057AbZIOSC6 (ORCPT ); Tue, 15 Sep 2009 14:02:58 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8FI31JN012299; Tue, 15 Sep 2009 14:03:01 -0400 Received: from localhost.localdomain (vpn-12-148.rdu.redhat.com [10.11.12.148]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8FI2om8015125; Tue, 15 Sep 2009 14:02:59 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 4/4] KVM tests: Load tests from the test module Date: Tue, 15 Sep 2009 15:02:47 -0300 Message-Id: <1253037767-7165-4-git-send-email-lmr@redhat.com> In-Reply-To: <1253037767-7165-3-git-send-email-lmr@redhat.com> References: <1253037767-7165-1-git-send-email-lmr@redhat.com> <1253037767-7165-2-git-send-email-lmr@redhat.com> <1253037767-7165-3-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of defining test files and test routines explicitely on the test code, make the file name and run function schema a little more strict: Now test files should have the testname, and the run function should be called run_[testname]. While less flexible, this makes things more predictable. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm.py | 61 ++++++++--------------------------- client/tests/kvm/kvm_utils.py | 2 +- client/tests/kvm/tests/autotest.py | 2 +- 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index a5ced7b..204164d 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -1,13 +1,7 @@ -import sys, os, time, shelve, resource, logging, cPickle +import sys, os, time, logging from autotest_lib.client.bin import test from autotest_lib.client.common_lib import error - - -class test_routine: - def __init__(self, module_name, routine_name): - self.module_name = module_name - self.routine_name = routine_name - self.routine = None +import kvm_utils, kvm_preprocessing class kvm(test.test): @@ -28,36 +22,12 @@ class kvm(test.test): """ version = 1 def initialize(self): - # Define the test routines corresponding to different values - # of the 'type' field - self.test_routines = { - # type module name routine - "build": test_routine("build", "run_build"), - "steps": test_routine("steps", "run_steps"), - "stepmaker": test_routine("stepmaker", "run_stepmaker"), - "boot": test_routine("kvm_tests", "run_boot"), - "shutdown": test_routine("kvm_tests", "run_shutdown"), - "migration": test_routine("kvm_tests", "run_migration"), - "yum_update": test_routine("kvm_tests", "run_yum_update"), - "autotest": test_routine("kvm_tests", "run_autotest"), - "linux_s3": test_routine("kvm_tests", "run_linux_s3"), - "stress_boot": test_routine("kvm_tests", "run_stress_boot"), - "timedrift": test_routine("kvm_tests", "run_timedrift"), - "autoit": test_routine("kvm_tests", "run_autoit"), - } - # Make it possible to import modules from the test's bindir sys.path.append(self.bindir) + self.subtest_dir = os.path.join(self.bindir, 'tests') def run_once(self, params): - import logging - import kvm_utils - import kvm_preprocessing - - # Enable core dumps - resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) - # Report the parameters we've received and write them as keyvals logging.debug("Test parameters:") keys = params.keys() @@ -75,25 +45,22 @@ class kvm(test.test): try: # Get the test routine corresponding to the specified test type type = params.get("type") - routine_obj = self.test_routines.get(type) - # If type could not be found in self.test_routines... - if not routine_obj: - message = "Unsupported test type: %s" % type - logging.error(message) - raise error.TestError(message) - # If we don't have the test routine yet... - if not routine_obj.routine: - # Dynamically import the module - module = __import__(routine_obj.module_name) - # Get the needed routine - routine_name = "module." + routine_obj.routine_name - routine_obj.routine = eval(routine_name) + # Verify if we have the correspondent source file for it + module_path = os.path.join(self.subtest_dir, '%s.py' % type) + if not os.path.isfile(module_path): + raise error.TestError("No %s.py test file found" % type) + # Load the tests directory (which was turned into a py module) + try: + test_module = __import__("tests.%s" % type) + except ImportError, e: + raise error.TestError("Failed to import test %s: %s" % + (type, e)) # Preprocess kvm_preprocessing.preprocess(self, params, env) kvm_utils.dump_env(env, env_filename) # Run the test function - routine_obj.routine(self, params, env) + eval("test_module.%s.run_%s(self, params, env)" % (type, type)) kvm_utils.dump_env(env, env_filename) except Exception, e: diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index d0e3ea4..88299be 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -5,7 +5,7 @@ KVM test utility functions. """ import md5, thread, subprocess, time, string, random, socket, os, signal, pty -import select, re, logging, commands +import select, re, logging, commands, cPickle from autotest_lib.client.bin import utils from autotest_lib.client.common_lib import error import kvm_subprocess diff --git a/client/tests/kvm/tests/autotest.py b/client/tests/kvm/tests/autotest.py index 70e839f..5c9b2aa 100644 --- a/client/tests/kvm/tests/autotest.py +++ b/client/tests/kvm/tests/autotest.py @@ -1,6 +1,6 @@ import os, logging from autotest_lib.client.common_lib import error -import kvm_subprocess, kvm_utils, scan_results +import kvm_subprocess, kvm_utils, kvm_test_utils, scan_results def run_autotest(test, params, env):