From patchwork Tue May 26 21:08:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Huff X-Patchwork-Id: 26100 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 n4QL93i9024777 for ; Tue, 26 May 2009 21:09:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754592AbZEZVJA (ORCPT ); Tue, 26 May 2009 17:09:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754258AbZEZVI7 (ORCPT ); Tue, 26 May 2009 17:08:59 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45041 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753460AbZEZVI7 (ORCPT ); Tue, 26 May 2009 17:08:59 -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 n4QL91J0032581 for ; Tue, 26 May 2009 17:09:01 -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 n4QL90jF013860; Tue, 26 May 2009 17:09:00 -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 n4QL90WA006773; Tue, 26 May 2009 17:09:00 -0400 From: David Huff To: kvm@vger.kernel.org Cc: David Huff Subject: [PATCH][KVM_AUTOTEST] Added functionality to the preprocessor to run scripts Date: Tue, 26 May 2009 17:08:21 -0400 Message-Id: <1243372101-11455-1-git-send-email-dhuff@redhat.com> In-Reply-To: <4A1C13C6.4020603@redhat.com> References: <4A1C13C6.4020603@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 patch will run pre and post scripts defined in config file with the parameter pre_command and post_command post_command. Also exports all the prameters in preprocess for passing arguments to the script. --- client/tests/kvm_runtest_2/kvm_preprocessing.py | 34 +++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/client/tests/kvm_runtest_2/kvm_preprocessing.py b/client/tests/kvm_runtest_2/kvm_preprocessing.py index c9eb35d..07bfdeb 100644 --- a/client/tests/kvm_runtest_2/kvm_preprocessing.py +++ b/client/tests/kvm_runtest_2/kvm_preprocessing.py @@ -169,6 +169,7 @@ def preprocess(test, params, env): params -- a dict containing all VM and image parameters env -- the environment (a dict-like object) + Also, runs any setup command defined in the parameter pre_command Also, collect some host information, such as the KVM version. """ # Verify the identities of all living VMs @@ -192,6 +193,22 @@ def preprocess(test, params, env): vm.destroy() del env[key] + #execute any pre_commands + pre_command = params.get("pre_command") + if pre_command: + # export environment vars + for k in params.keys(): + kvm_log.info("Adding KVM_TEST_%s to Environment" % (k)) + os.putenv("KVM_TEST_%s" % (k), str(params[k])) + # execute command + kvm_log.info("Executing command '%s'..." % pre_command) + timeout = int(params.get("pre_commmand_timeout", "600")) + (status, pid, output) = kvm_utils.run_bg("cd %s; %s" % (test.bindir, pre_command), + None, kvm_log.debug, "(pre_command) ", timeout=timeout) + if status != 0: + kvm_utils.safe_kill(pid, signal.SIGTERM) + raise error.TestError, "Custom processing pre_command failed" + # Preprocess all VMs and images process(test, params, env, preprocess_image, preprocess_vm) @@ -232,6 +249,8 @@ def postprocess(test, params, env): test -- an Autotest test object params -- a dict containing all VM and image parameters env -- the environment (a dict-like object) + + Also, runs any command defined in the parameter post_command """ process(test, params, env, postprocess_image, postprocess_vm) @@ -241,6 +260,21 @@ def postprocess(test, params, env): kvm_log.debug("'keep_ppm_files' not specified; removing all PPM files from results dir...") kvm_utils.run_bg("rm -vf %s" % os.path.join(test.debugdir, "*.ppm"), None, kvm_log.debug, "(rm) ", timeout=5.0) + #execute any post_commands + post_command = params.get("post_command") + if post_command: + # export environment vars + for k in params.keys(): + kvm_log.info("Adding KVM_TEST_%s to Environment" % (k)) + os.putenv("KVM_TEST_%s" % (k), str(params[k])) + #execute command + kvm_log.info("Executing command '%s'..." % post_command) + timeout = int(params.get("post_commmand_timeout", "600")) + (status, pid, output) = kvm_utils.run_bg("cd %s; %s" % (test.bindir, post_command), + None, kvm_log.debug, "(pre_command) ", timeout=timeout) + if status != 0: + kvm_utils.safe_kill(pid, signal.SIGTERM) + raise error.TestError, "Custom processing command failed" def postprocess_on_error(test, params, env): """Perform postprocessing operations required only if the test failed.