From patchwork Wed Aug 12 15:00:00 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: 40886 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 n7CF0H8u030895 for ; Wed, 12 Aug 2009 15:00:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753355AbZHLPAM (ORCPT ); Wed, 12 Aug 2009 11:00:12 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753342AbZHLPAM (ORCPT ); Wed, 12 Aug 2009 11:00:12 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59919 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753220AbZHLPAL (ORCPT ); Wed, 12 Aug 2009 11:00:11 -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 n7CF0B87013305; Wed, 12 Aug 2009 11:00:11 -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 n7CF0Ab6009558; Wed, 12 Aug 2009 11:00:10 -0400 Received: from localhost.localdomain (vpn-10-17.bos.redhat.com [10.16.10.17]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7CF07sx017269; Wed, 12 Aug 2009 11:00:08 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Avi Kivity , Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Remove unnecessary callouts to external programs Date: Wed, 12 Aug 2009 12:00:00 -0300 Message-Id: <1250089200-7522-1-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 From: Avi Kivity Calling out to external commands is slow, noisy, and unreliable. This patchset replaces two such cases with Python equivalents. * Replace subprocess 'rm' by equivalent Python code * Convert images to JPEG and PNG using PIL instead of an external program. If we don't have the python imaging library installed, log a warning to the user and just degrade functionality accordingly. Signed-off-by: Avi Kivity Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm_guest_wizard.py | 19 ++++++++++++++----- client/tests/kvm/kvm_preprocessing.py | 23 ++++++++++++++++------- 2 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 @@ import os, time, md5, re, shutil, logging from autotest_lib.client.common_lib import utils, error import kvm_utils, ppm_utils, kvm_subprocess +try: + import PIL.Image +except ImportError: + logging.warning('No python imaging library installed. PPM image ' + 'conversion to JPEG disabled. In order to enable it, ' + 'please install python-imaging or the equivalent for your ' + 'distro.') """ Utilities to perform automatic guest installation using step files. @@ -110,9 +117,12 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename, history_scrdump_filename = os.path.join(history_dir, "scrdump-step_%s-%s.jpg" % (current_step_num, time.strftime("%Y%m%d-%H%M%S"))) - kvm_subprocess.run_fg("convert -quality 30 %s %s" % - (scrdump_filename, history_scrdump_filename), - logging.debug, "(convert) ", timeout=30) + try: + image = PIL.Image.open(scrdump_filename) + image.save(history_scrdump_filename, format = 'JPEG', + quality = 30) + except NameError: + pass # Compare md5sum of barrier region with the expected md5sum calced_md5sum = ppm_utils.get_region_md5sum(w, h, data, x1, y1, dx, dy, @@ -120,8 +130,7 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename, if calced_md5sum == md5sum: # Success -- remove screendump history unless requested not to if keep_screendump_history and not keep_all_history: - kvm_subprocess.run_fg("rm -rvf %s" % history_dir, - logging.debug, "(rm) ", timeout=30) + shutil.rmtree(history_dir) # Report success 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 from autotest_lib.client.bin import test from autotest_lib.client.common_lib import error import kvm_vm, kvm_utils, kvm_subprocess +try: + import PIL.Image +except ImportError: + logging.warning('No python imaging library installed. PPM image ' + 'conversion to JPEG disabled. In order to enable it, ' + 'please install python-imaging or the equivalent for your ' + 'distro.') def preprocess_image(test, params): @@ -260,17 +267,19 @@ def postprocess(test, params, env): if params.get("convert_ppm_files_to_png") == "yes": logging.debug("'convert_ppm_files_to_png' specified; converting PPM" " files to PNG format...") - mogrify_cmd = ("mogrify -format png %s" % - os.path.join(test.debugdir, "*.ppm")) - kvm_subprocess.run_fg(mogrify_cmd, logging.debug, "(mogrify) ", - timeout=30.0) + try: + for f in glob.glob(os.path.join(test.debugdir, "*.ppm")): + image = PIL.Image.open(f) + image.save(history_scrdump_filename, format = 'PNG') + except NameError: + pass # Should we keep the PPM files? if params.get("keep_ppm_files") != "yes": logging.debug("'keep_ppm_files' not specified; removing all PPM files" " from debug dir...") - rm_cmd = "rm -vf %s" % os.path.join(test.debugdir, "*.ppm") - kvm_subprocess.run_fg(rm_cmd, logging.debug, "(rm) ", timeout=5.0) + for f in glob.glob(os.path.join(test.debugdir, '*.ppm')): + os.unlink(f) # Execute any post_commands if params.get("post_command"):