From patchwork Tue May 26 16:27:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Huff X-Patchwork-Id: 26048 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 n4QGStKY032586 for ; Tue, 26 May 2009 16:28:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755009AbZEZQ1o (ORCPT ); Tue, 26 May 2009 12:27:44 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754970AbZEZQ1n (ORCPT ); Tue, 26 May 2009 12:27:43 -0400 Received: from mx2.redhat.com ([66.187.237.31]:42652 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753836AbZEZQ1k (ORCPT ); Tue, 26 May 2009 12:27:40 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4QGRgZv015379 for ; Tue, 26 May 2009 12:27:42 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4QGRfU6029738; Tue, 26 May 2009 12:27:41 -0400 Received: from localhost.localdomain (dhcp231-89.rdu.redhat.com [10.11.231.89]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4QGReF2028568; Tue, 26 May 2009 12:27:41 -0400 From: David Huff To: kvm@vger.kernel.org Cc: David Huff Subject: [PATCH] Modified kvm_runtest_2.py to look for tests in kvm_tests/ Date: Tue, 26 May 2009 12:27:00 -0400 Message-Id: <1243355222-30876-2-git-send-email-dhuff@redhat.com> In-Reply-To: <1243355222-30876-1-git-send-email-dhuff@redhat.com> References: <1243355222-30876-1-git-send-email-dhuff@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This will allow for adding of additional tests with out modifying the "code." One would just add the testname.py file to the test_dir and edit the comfig file. fixed typo --- client/tests/kvm_runtest_2/kvm_runtest_2.py | 32 +++++++++++++++++++------- 1 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/tests/kvm_runtest_2/kvm_runtest_2.py b/client/tests/kvm_runtest_2/kvm_runtest_2.py index fda7282..6420191 100644 --- a/client/tests/kvm_runtest_2/kvm_runtest_2.py +++ b/client/tests/kvm_runtest_2/kvm_runtest_2.py @@ -2,6 +2,7 @@ import sys import os +import inspect import time import shelve import random @@ -21,26 +22,26 @@ class test_routine: class kvm_runtest_2(test.test): version = 1 + def setup(self): pass def initialize(self): - # Define the test routines corresponding to different values of the 'type' field + # directory where to look for tests + self.test_dir = os.path.join(self.bindir, "kvm_tests") + + # pre-defined the test routines corresponding to different values of the 'type' field self.test_routines = { - # type module name routine + # type module name routine name "steps": test_routine("kvm_guest_wizard", "run_steps"), "stepmaker": test_routine("stepmaker", "run_stepmaker"), - "boot": test_routine("kvm_tests", "run_boot"), - "migration": test_routine("kvm_tests", "run_migration"), - "yum_update": test_routine("kvm_tests", "run_yum_update"), - "autotest": test_routine("kvm_tests", "run_autotest"), "kvm_install": test_routine("kvm_install", "run_kvm_install"), - "linux_s3": test_routine("kvm_tests", "run_linux_s3"), } - + # Make it possible to import modules from the test's bindir sys.path.append(self.bindir) - + sys.path.append(self.test_dir) + def run_once(self, params): import kvm_log import kvm_utils @@ -74,6 +75,12 @@ class kvm_runtest_2(test.test): type = params.get("type") routine_obj = self.test_routines.get(type) # If type could not be found in self.test_routines... + # look for test in kvm_tests directory, where type = 'testname' + # defined in file 'testname'.py and test routine method run_'testname' + if os.path.isfile(os.path.join(self.test_dir,type+".py")): + module_name = type + routine_name = "run_"+module_name + routine_obj = test_routine(module_name,routine_name) if not routine_obj: message = "Unsupported test type: %s" % type kvm_log.error(message) @@ -83,6 +90,13 @@ class kvm_runtest_2(test.test): # Dynamically import the module module = __import__(routine_obj.module_name) # Get the needed routine + try: + inspect.isfunction(eval("module."+routine_obj.routine_name)) + except Exception, e: + kvm_log.error("Test failed: %s" % e) + kvm_log.error("could not load:%s" % eval("module."+routine_obj.routine_name)) + raise + routine_obj.routine = eval("module." + routine_obj.routine_name) # Preprocess