KVM test: Remove unnecessary callouts to external programs
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 <avi@redhat.com>
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3528 592f7852-d20e-0410-864c-8624ca9c26a4
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 @@
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"):