All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org, Michael Goldish <mgoldish@redhat.com>
Subject: Re: [KVM-AUTOTEST PATCH 8/8] kvm_runtest_2.py: use pickle instead of shelve when loading/saving env
Date: Mon, 08 Jun 2009 12:21:15 -0300	[thread overview]
Message-ID: <1244474475.2849.65.camel@localhost.localdomain> (raw)
In-Reply-To: <1244234794-7844-9-git-send-email-lmr@redhat.com>

On Fri, 2009-06-05 at 17:46 -0300, Lucas Meneghel Rodrigues wrote:
> 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).

Applied.

> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
>  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)
-- 
Lucas Meneghel Rodrigues
Software Engineer (QE)
Red Hat - Emerging Technologies


  reply	other threads:[~2009-06-08 15:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-05 20:46 [KVM-AUTOTEST PATCH 0/8] Re-submitting some of the patches on the patch queue Lucas Meneghel Rodrigues
2009-06-05 20:46 ` [KVM-AUTOTEST PATCH 1/8] kvm_config: Allow for "=" in the value of a config parameter Lucas Meneghel Rodrigues
2009-06-05 20:46   ` [KVM-AUTOTEST PATCH 2/8] RHEL-4.7 step files: fix the initial boot barriers Lucas Meneghel Rodrigues
2009-06-05 20:46     ` [KVM-AUTOTEST PATCH 3/8] WinXP step file fixes Lucas Meneghel Rodrigues
2009-06-05 20:46       ` [KVM-AUTOTEST PATCH 4/8] RHEL 5.3 " Lucas Meneghel Rodrigues
2009-06-05 20:46         ` [KVM-AUTOTEST PATCH 5/8] stepeditor.py: get rid of some shortcuts Lucas Meneghel Rodrigues
2009-06-05 20:46           ` [KVM-AUTOTEST PATCH 6/8] Choose a monitor filename in the constructor of VM class Lucas Meneghel Rodrigues
2009-06-05 20:46             ` [KVM-AUTOTEST PATCH 7/8] Add new function, VM.clone() to clone an existing VM Lucas Meneghel Rodrigues
2009-06-05 20:46               ` [KVM-AUTOTEST PATCH 8/8] kvm_runtest_2.py: use pickle instead of shelve when loading/saving env Lucas Meneghel Rodrigues
2009-06-08 15:21                 ` Lucas Meneghel Rodrigues [this message]
2009-06-08 16:10                 ` [Autotest] " Martin Bligh
2009-06-08 16:54                   ` Lucas Meneghel Rodrigues
2009-06-08 15:20               ` [KVM-AUTOTEST PATCH 7/8] Add new function, VM.clone() to clone an existing VM Lucas Meneghel Rodrigues

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244474475.2849.65.camel@localhost.localdomain \
    --to=lmr@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mgoldish@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.