All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: Martin Bligh <mbligh@google.com>
Cc: autotest@test.kernel.org, Michael Goldish <mgoldish@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [Autotest] [KVM-AUTOTEST PATCH 8/8] kvm_runtest_2.py: use pickle  instead of shelve when loading/saving env
Date: Mon, 08 Jun 2009 13:54:01 -0300	[thread overview]
Message-ID: <1244480041.2849.142.camel@localhost.localdomain> (raw)
In-Reply-To: <33307c790906080910l3f4d1f83x5ba821295e79f59f@mail.gmail.com>

On Mon, 2009-06-08 at 09:10 -0700, Martin Bligh wrote:
> On Fri, Jun 5, 2009 at 1:46 PM, Lucas Meneghel Rodrigues<lmr@redhat.com> 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).
> >
> 
> > +def dump_env(obj, filename):
> > +    file = open(filename, "w")
> > +    cPickle.dump(obj, file)
> > +    file.close()
> 
> This seems like a strange function name - it's really pickling any
> object, nothing specific to do with the environment?

Yes, I agree it's pickling any object, but in the end, we are using this
file to unpickle data from our environment file, hence Michael choose
that name.

> > +
> > +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)
> > --
> > 1.6.2.2
> >
> > _______________________________________________
> > Autotest mailing list
> > Autotest@test.kernel.org
> > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
> >
-- 
Lucas Meneghel Rodrigues
Software Engineer (QE)
Red Hat - Emerging Technologies


  reply	other threads:[~2009-06-08 16:54 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
2009-06-08 16:10                 ` [Autotest] " Martin Bligh
2009-06-08 16:54                   ` Lucas Meneghel Rodrigues [this message]
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=1244480041.2849.142.camel@localhost.localdomain \
    --to=lmr@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mbligh@google.com \
    --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.