KVM test: Remove unnecessary callouts to external programs
PATCH 1/1 KVM test: Remove unnecessary callouts to external programs
From: Avi Kivity <[email protected]>
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.
--- client/tests/kvm/kvm_guest_wizard.py | 19 ++++++++++++++----- client/tests/kvm/kvm_preprocessing.py | 23 ++++++++++++++++------- 2 files changed, 30 insertions(+), 12 deletions(-)
client/tests/kvm/kvm_guest_wizard.py +14 -5
@@ -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
client/tests/kvm/kvm_preprocessing.py +16 -7
@@ -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"):
Signature · 1 line
1.6.2.5
Lucas Meneghel Rodrigues
AppliedQuoted 9 lines · Lucas Meneghel Rodrigues
From: Avi Kivity <[email protected]>
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.
Applied, thanks Avi!
Quoted 105 lines
Signed-off-by Avi Kivity <[email protected]>Signed-off-by Lucas Meneghel Rodrigues <[email protected]>---
client/tests/kvm/kvm_guest_wizard.py | 19 ++++++++++++++-----client/tests/kvm/kvm_preprocessing.py| 23 ++++++++++++++++-------2 files changed, 30 insertions(+), 12 deletions(-)client/tests/kvm/kvm_guest_wizard.py +0
-0@@ -1,6 +1,13 @@import os, time, md5, re, shutil, logging
from autotest_lib.client.common_lib import utils, error importkvm_utils,ppm_utils,kvm_subprocessclient/tests/kvm/kvm_guest_wizard.py +7
-0+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.client/tests/kvm/kvm_guest_wizard.py +6
-3@@ -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 ifkeep_screendump_historyand notkeep_all_history:
- kvm_subprocess.run_fg("rm -rvf %s" %history_dir,
- logging.debug, "(rm) ", timeout=30)
+ shutil.rmtree(history_dir)
# Report success
return Trueclient/tests/kvm/kvm_preprocessing.py +1
-1@@ -1,7 +1,14 @@ -import sys, os, time, commands, re, logging, signal +import sys, os, time, commands, re, logging, signal, globfrom autotest_lib.client.bin import test
from autotest_lib.client.common_lib import error
importkvm_vm,kvm_utils,kvm_subprocessclient/tests/kvm/kvm_preprocessing.py +7
-0+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):client/tests/kvm/kvm_preprocessing.py +0
-0@@ -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 inglob.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?
ifparams.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 inglob.glob(os.path.join(test.debugdir, '*.ppm')):
+ os.unlink(f)# Execute any
post_commands
ifparams.get("post_command"):
--
1.6.2.5--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Lucas Meneghel