From patchwork Tue Sep 15 18:02:46 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: 47700 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 n8FI376x007115 for ; Tue, 15 Sep 2009 18:03:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753089AbZIOSC7 (ORCPT ); Tue, 15 Sep 2009 14:02:59 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754059AbZIOSC7 (ORCPT ); Tue, 15 Sep 2009 14:02:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31041 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753089AbZIOSC4 (ORCPT ); Tue, 15 Sep 2009 14:02:56 -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 n8FI2xQJ010257; Tue, 15 Sep 2009 14:02:59 -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 n8FI2om7015125; Tue, 15 Sep 2009 14:02:57 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 3/4] KVM test: Moving utility functions to kvm_utils.py Date: Tue, 15 Sep 2009 15:02:46 -0300 Message-Id: <1253037767-7165-3-git-send-email-lmr@redhat.com> In-Reply-To: <1253037767-7165-2-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> 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 Moved dump_env and load_env to kvm_utils.py since it makes the main test class cleaner. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm.py | 26 +++++--------------------- client/tests/kvm/kvm_utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index f6883c8..a5ced7b 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -10,22 +10,6 @@ class test_routine: self.routine = None -def dump_env(obj, filename): - file = open(filename, "w") - cPickle.dump(obj, file) - file.close() - - -def load_env(filename, default=None): - try: - file = open(filename, "r") - except: - return default - obj = cPickle.load(file) - file.close() - return obj - - class kvm(test.test): """ Suite of KVM virtualization functional tests. @@ -84,7 +68,7 @@ class kvm(test.test): # Open the environment file env_filename = os.path.join(self.bindir, params.get("env", "env")) - env = load_env(env_filename, {}) + env = kvm_utils.load_env(env_filename, {}) logging.debug("Contents of environment: %s" % str(env)) try: @@ -107,20 +91,20 @@ class kvm(test.test): # Preprocess kvm_preprocessing.preprocess(self, params, env) - dump_env(env, env_filename) + kvm_utils.dump_env(env, env_filename) # Run the test function routine_obj.routine(self, params, env) - dump_env(env, env_filename) + kvm_utils.dump_env(env, env_filename) except Exception, e: logging.error("Test failed: %s", e) logging.debug("Postprocessing on error...") kvm_preprocessing.postprocess_on_error(self, params, env) - dump_env(env, env_filename) + kvm_utils.dump_env(env, env_filename) raise finally: # Postprocess kvm_preprocessing.postprocess(self, params, env) logging.debug("Contents of environment: %s", str(env)) - dump_env(env, env_filename) + kvm_utils.dump_env(env, env_filename) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index ceae4a4..d0e3ea4 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -11,6 +11,32 @@ from autotest_lib.client.common_lib import error import kvm_subprocess +def dump_env(obj, filename): + """ + Dump KVM test environment to a file. + + @param filename: Path to a file where the environment will be dumped to. + """ + file = open(filename, "w") + cPickle.dump(obj, file) + file.close() + + +def load_env(filename, default=None): + """ + Load KVM test environment from an environment file. + + @param filename: Path to a file where the environment was dumped to. + """ + try: + file = open(filename, "r") + except: + return default + obj = cPickle.load(file) + file.close() + return obj + + def get_sub_dict(dict, name): """ Return a "sub-dict" corresponding to a specific object.