From: Lucas Meneghel Rodrigues Subject: Re: [PATCH] KVM test: Remove unnecessary callouts to external programs Date: Wed, 12 Aug 2009 12:18:56 -0300 Message-ID: <6ac58f4f0908120818le5d8920pdc2a486fbb72c1a2@mail.gmail.com> References: <1250089200-7522-1-git-send-email-lmr@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, Avi Kivity , Lucas Meneghel Rodrigues To: autotest@test.kernel.org Return-path: Received: from mail-vw0-f172.google.com ([209.85.212.172]:62811 "EHLO mail-vw0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752213AbZHLPS4 convert rfc822-to-8bit (ORCPT ); Wed, 12 Aug 2009 11:18:56 -0400 Received: by vws2 with SMTP id 2so76395vws.4 for ; Wed, 12 Aug 2009 08:18:56 -0700 (PDT) In-Reply-To: <1250089200-7522-1-git-send-email-lmr@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Aug 12, 2009 at 12:00 PM, Lucas Meneghel Rodrigues wrote: > From: Avi Kivity > > Calling out to external commands is slow, noisy, and unreliable. =A0T= his > patchset replaces two such cases with Python equivalents. > > =A0* Replace subprocess 'rm' by equivalent Python code > =A0* Convert images to JPEG and PNG using PIL instead of an external = program. > =A0If we don't have the python imaging library installed, log a warni= ng > =A0to the user and just degrade functionality accordingly. Applied, thanks Avi! > Signed-off-by: Avi Kivity > Signed-off-by: Lucas Meneghel Rodrigues > --- > =A0client/tests/kvm/kvm_guest_wizard.py =A0| =A0 19 ++++++++++++++---= -- > =A0client/tests/kvm/kvm_preprocessing.py | =A0 23 ++++++++++++++++---= ---- > =A02 files changed, 30 insertions(+), 12 deletions(-) > > diff --git a/client/tests/kvm/kvm_guest_wizard.py b/client/tests/kvm/= kvm_guest_wizard.py > index 73b830e..dd1879d 100644 > --- a/client/tests/kvm/kvm_guest_wizard.py > +++ b/client/tests/kvm/kvm_guest_wizard.py > @@ -1,6 +1,13 @@ > =A0import os, time, md5, re, shutil, logging > =A0from autotest_lib.client.common_lib import utils, error > =A0import kvm_utils, ppm_utils, kvm_subprocess > +try: > + =A0 =A0import PIL.Image > +except ImportError: > + =A0 =A0logging.warning('No python imaging library installed. PPM im= age ' > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'conversion to JPEG disabled= =2E In order to enable it, ' > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'please install python-imagi= ng or the equivalent for your ' > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'distro.') > > =A0""" > =A0Utilities to perform automatic guest installation using step files= =2E > @@ -110,9 +117,12 @@ def barrier_2(vm, words, params, debug_dir, data= _scrdump_filename, > =A0 =A0 =A0 =A0 =A0 =A0 history_scrdump_filename =3D os.path.join(his= tory_dir, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "scrdump-step_%s-%s.jpg" % (c= urrent_step_num, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 time.strftime("%Y%m%d-%H%M%S"))) > - =A0 =A0 =A0 =A0 =A0 =A0kvm_subprocess.run_fg("convert -quality 30 %= s %s" % > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= (scrdump_filename, history_scrdump_filename), > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= logging.debug, "(convert) ", timeout=3D30) > + =A0 =A0 =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image =3D PIL.Image.open(scrdump_fil= ename) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image.save(history_scrdump_filename,= format =3D 'JPEG', > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 quality =3D 30) > + =A0 =A0 =A0 =A0 =A0 =A0except NameError: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pass > > =A0 =A0 =A0 =A0 # Compare md5sum of barrier region with the expected = md5sum > =A0 =A0 =A0 =A0 calced_md5sum =3D ppm_utils.get_region_md5sum(w, h, d= ata, x1, y1, dx, dy, > @@ -120,8 +130,7 @@ def barrier_2(vm, words, params, debug_dir, data_= scrdump_filename, > =A0 =A0 =A0 =A0 if calced_md5sum =3D=3D md5sum: > =A0 =A0 =A0 =A0 =A0 =A0 # Success -- remove screendump history unless= requested not to > =A0 =A0 =A0 =A0 =A0 =A0 if keep_screendump_history and not keep_all_h= istory: > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0kvm_subprocess.run_fg("rm -rvf %s" %= history_dir, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0logging.debug, "(rm) ", timeout=3D30) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0shutil.rmtree(history_dir) > =A0 =A0 =A0 =A0 =A0 =A0 # Report success > =A0 =A0 =A0 =A0 =A0 =A0 return True > > diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm= /kvm_preprocessing.py > index d118826..2e55b34 100644 > --- a/client/tests/kvm/kvm_preprocessing.py > +++ b/client/tests/kvm/kvm_preprocessing.py > @@ -1,7 +1,14 @@ > -import sys, os, time, commands, re, logging, signal > +import sys, os, time, commands, re, logging, signal, glob > =A0from autotest_lib.client.bin import test > =A0from autotest_lib.client.common_lib import error > =A0import kvm_vm, kvm_utils, kvm_subprocess > +try: > + =A0 =A0import PIL.Image > +except ImportError: > + =A0 =A0logging.warning('No python imaging library installed. PPM im= age ' > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'conversion to JPEG disabled= =2E In order to enable it, ' > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'please install python-imagi= ng or the equivalent for your ' > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'distro.') > > > =A0def preprocess_image(test, params): > @@ -260,17 +267,19 @@ def postprocess(test, params, env): > =A0 =A0 if params.get("convert_ppm_files_to_png") =3D=3D "yes": > =A0 =A0 =A0 =A0 logging.debug("'convert_ppm_files_to_png' specified; = converting PPM" > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " files to PNG format..."= ) > - =A0 =A0 =A0 =A0mogrify_cmd =3D ("mogrify -format png %s" % > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 os.path.join(test.debug= dir, "*.ppm")) > - =A0 =A0 =A0 =A0kvm_subprocess.run_fg(mogrify_cmd, logging.debug, "(= mogrify) ", > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0timeout=3D= 30.0) > + =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0for f in glob.glob(os.path.join(test.debugdi= r, "*.ppm")): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image =3D PIL.Image.open(f) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0image.save(history_scrdump_filename,= format =3D 'PNG') > + =A0 =A0 =A0 =A0except NameError: > + =A0 =A0 =A0 =A0 =A0 =A0pass > > =A0 =A0 # Should we keep the PPM files? > =A0 =A0 if params.get("keep_ppm_files") !=3D "yes": > =A0 =A0 =A0 =A0 logging.debug("'keep_ppm_files' not specified; removi= ng all PPM files" > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " from debug dir...") > - =A0 =A0 =A0 =A0rm_cmd =3D "rm -vf %s" % os.path.join(test.debugdir,= "*.ppm") > - =A0 =A0 =A0 =A0kvm_subprocess.run_fg(rm_cmd, logging.debug, "(rm) "= , timeout=3D5.0) > + =A0 =A0 =A0 =A0for f in glob.glob(os.path.join(test.debugdir, '*.pp= m')): > + =A0 =A0 =A0 =A0 =A0 =A0os.unlink(f) > > =A0 =A0 # Execute any post_commands > =A0 =A0 if params.get("post_command"): > -- > 1.6.2.5 > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at =A0http://vger.kernel.org/majordomo-info.html > --=20 Lucas Meneghel