From patchwork Fri Jun 5 20:46:34 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: 28307 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 n55KlDtf016208 for ; Fri, 5 Jun 2009 20:47:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753234AbZFEUqy (ORCPT ); Fri, 5 Jun 2009 16:46:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753092AbZFEUqx (ORCPT ); Fri, 5 Jun 2009 16:46:53 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59809 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753118AbZFEUqv (ORCPT ); Fri, 5 Jun 2009 16:46:51 -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 n55Kkse3003274; Fri, 5 Jun 2009 16:46:54 -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 n55KkpHU017644; Fri, 5 Jun 2009 16:46:51 -0400 Received: from localhost.localdomain (vpn-10-165.bos.redhat.com [10.16.10.165]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n55KkZ48015832; Fri, 5 Jun 2009 16:46:50 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues , Michael Goldish Subject: [KVM-AUTOTEST PATCH 8/8] kvm_runtest_2.py: use pickle instead of shelve when loading/saving env Date: Fri, 5 Jun 2009 17:46:34 -0300 Message-Id: <1244234794-7844-9-git-send-email-lmr@redhat.com> In-Reply-To: <1244234794-7844-8-git-send-email-lmr@redhat.com> References: <1244234794-7844-1-git-send-email-lmr@redhat.com> <1244234794-7844-2-git-send-email-lmr@redhat.com> <1244234794-7844-3-git-send-email-lmr@redhat.com> <1244234794-7844-4-git-send-email-lmr@redhat.com> <1244234794-7844-5-git-send-email-lmr@redhat.com> <1244234794-7844-6-git-send-email-lmr@redhat.com> <1244234794-7844-7-git-send-email-lmr@redhat.com> <1244234794-7844-8-git-send-email-lmr@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 pickle allows more control over the load/save process. Specifically, it enables us to dump the contents of an object to disk without having to unpickle it. shelve, which uses pickle, seems to pickle and unpickle every time sync() is called. This is bad for classes that need to be unpickled only once per test (such a class will be introduced in a future patch). Signed-off-by: Michael Goldish --- client/tests/kvm/kvm.py | 35 +++++++++++++++++++++++++---------- 1 files changed, 25 insertions(+), 10 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index 1b9013c..a658425 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -1,4 +1,4 @@ -import sys, os, time, shelve, random, resource, logging +import sys, os, time, shelve, random, resource, logging, cPickle from autotest_lib.client.bin import test from autotest_lib.client.common_lib import error @@ -10,6 +10,22 @@ 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. @@ -62,12 +78,12 @@ class kvm(test.test): keys = params.keys() keys.sort() for key in keys: - logging.debug(" %s = %s" % (key, params[key])) + logging.debug(" %s = %s", key, params[key]) self.write_test_keyval({key: params[key]}) # Open the environment file env_filename = os.path.join(self.bindir, "env") - env = shelve.open(env_filename, writeback=True) + env = load_env(env_filename, {}) logging.debug("Contents of environment: %s" % str(env)) try: @@ -90,21 +106,20 @@ class kvm(test.test): # Preprocess kvm_preprocessing.preprocess(self, params, env) - env.sync() + dump_env(env, env_filename) # Run the test function routine_obj.routine(self, params, env) - env.sync() + dump_env(env, env_filename) except Exception, e: - logging.error("Test failed: %s" % e) + logging.error("Test failed: %s", e) logging.debug("Postprocessing on error...") kvm_preprocessing.postprocess_on_error(self, params, env) - env.sync() + dump_env(env, env_filename) raise finally: # Postprocess kvm_preprocessing.postprocess(self, params, env) - logging.debug("Contents of environment: %s" % str(env)) - env.sync() - env.close() + logging.debug("Contents of environment: %s", str(env)) + dump_env(env, env_filename)