Moving from kvm_log to the upstream logging system.
PATCH 1/5 Moving from kvm_log to the upstream logging system.
From: [email protected] <[email protected]>
kvm_log can be replaced by the upstream logging system with advantages:
* Uses the standard python module, that allows us to define multiple message destinations
* It implements nearly all functionalities implemented on kvm_log
This patch converts all kvm_log statements to logging statements.
--- client/tests/kvm_runtest_2/kvm_guest_wizard.py | 14 ++-- client/tests/kvm_runtest_2/kvm_install.py | 56 +++++++------- client/tests/kvm_runtest_2/kvm_log.py | 60 -------------- client/tests/kvm_runtest_2/kvm_preprocessing.py | 58 +++++++------- client/tests/kvm_runtest_2/kvm_runtest_2.py | 18 ++-- client/tests/kvm_runtest_2/kvm_tests.py | 96 +++++++++++----------- client/tests/kvm_runtest_2/kvm_utils.py | 59 ++++++++------- client/tests/kvm_runtest_2/kvm_vm.py | 78 +++++++++--------- client/tests/kvm_runtest_2/stepmaker.py | 6 +- 9 files changed, 193 insertions(+), 252 deletions(-) delete mode 100644 client/tests/kvm_runtest_2/kvm_log.py
client/tests/kvm_runtest_2/kvm_guest_wizard.py +7 -7
@@ -9,7 +9,7 @@ import shutil from autotest_lib.client.common_lib import utils, error import kvm_utils -import kvm_log +import logging import ppm_utils
@@ -23,7 +23,7 @@ def handle_var(vm, params, varname): def barrier_2(vm, words, fail_if_stuck_for, stuck_detection_history, output_dir, data_scrdump_filename, current_step_num): if len(words) < 7: - kvm_log.error("Bad barrier_2 command line") + logging.error("Bad barrier_2 command line") return False cmd, dx, dy, x1, y1, md5sum, timeout = words[:7]
@@ -69,7 +69,7 @@ def barrier_2(vm, words, fail_if_stuck_for, stuck_detection_history, output_dir, # Request screendump (status, output) = vm.send_monitor_cmd("screendump %s" % scrdump_filename) if status: - kvm_log.error("Could not fetch screendump") + logging.error("Could not fetch screendump") continue # Make sure image is valid
@@ -108,7 +108,7 @@ def barrier_2(vm, words, fail_if_stuck_for, stuck_detection_history, output_dir, # What should we do with this failure? if words[-1] == "optional": - kvm_log.info(message) + logging.info(message) return False else: # Collect information and put it in output_dir
@@ -126,7 +126,7 @@ def barrier_2(vm, words, fail_if_stuck_for, stuck_detection_history, output_dir, ppm_utils.image_write_to_ppm_file(comparison_filename, w, h, data) # Print error messages and fail the test long_message = message + "\n(see analysis at %s)" % output_dir - kvm_log.error(long_message) + logging.error(long_message) raise error.TestFail, message
@@ -171,7 +171,7 @@ def run_steps(test, params, env): line = line.strip() if not line: continue - kvm_log.info(line) + logging.info(line) if line.startswith("#"): continue
@@ -191,7 +191,7 @@ def run_steps(test, params, env): vm.send_key(words[1]) elif words[0] == "var": if not handle_var(vm, params, words[1]): - kvm_log.error("Variable not defined: %s" % words[1]) + logging.error("Variable not defined: %s" % words[1]) elif words[0] == "barrier_2": if current_screendump: scrdump_filename = os.path.join(ppm_utils.get_data_dir(steps_filename), current_screendump)
client/tests/kvm_runtest_2/kvm_install.py +28 -28
190 lines not on this page · raw message
client/tests/kvm_runtest_2/kvm_log.py deleted +0 -60
60 lines not on this page · raw message
client/tests/kvm_runtest_2/kvm_preprocessing.py +27 -31
165 lines not on this page · raw message
client/tests/kvm_runtest_2/kvm_runtest_2.py +9 -9
@@ -42,7 +42,7 @@ class kvm_runtest_2(test.test): sys.path.append(self.bindir) def run_once(self, params): - import kvm_log + import logging import kvm_utils import kvm_preprocessing
@@ -53,20 +53,20 @@ class kvm_runtest_2(test.test): resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) # Set the logging prefix - kvm_log.set_prefix(params.get("shortname")) + #kvm_log.set_prefix(params.get("shortname")) # Report the parameters we've received and write them as keyvals - kvm_log.debug("Test parameters:") + logging.debug("Test parameters:") keys = params.keys() keys.sort() for key in keys: - kvm_log.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) - kvm_log.debug("Contents of environment: %s" % str(env)) + logging.debug("Contents of environment: %s" % str(env)) try: try:
@@ -76,7 +76,7 @@ class kvm_runtest_2(test.test): # If type could not be found in self.test_routines... if not routine_obj: message = "Unsupported test type: %s" % type - kvm_log.error(message) + logging.error(message) raise error.TestError, message # If we don't have the test routine yet... if not routine_obj.routine:
@@ -93,8 +93,8 @@ class kvm_runtest_2(test.test): env.sync() except Exception, e: - kvm_log.error("Test failed: %s" % e) - kvm_log.debug("Postprocessing on error...") + logging.error("Test failed: %s" % e) + logging.debug("Postprocessing on error...") kvm_preprocessing.postprocess_on_error(self, params, env) env.sync() raise
@@ -102,7 +102,7 @@ class kvm_runtest_2(test.test): finally: # Postprocess kvm_preprocessing.postprocess(self, params, env) - kvm_log.debug("Contents of environment: %s" % str(env)) + logging.debug("Contents of environment: %s" % str(env)) env.sync() env.close()
client/tests/kvm_runtest_2/kvm_tests.py +48 -48
299 lines not on this page · raw message
client/tests/kvm_runtest_2/kvm_utils.py +32 -27
196 lines not on this page · raw message
client/tests/kvm_runtest_2/kvm_vm.py +39 -39
214 lines not on this page · raw message
client/tests/kvm_runtest_2/stepmaker.py +3 -3
@@ -15,7 +15,7 @@ import commands from autotest_lib.client.common_lib import error import kvm_utils -import kvm_log +import logging import ppm_utils import stepeditor
@@ -136,7 +136,7 @@ class StepMaker(stepeditor.StepMakerWindow): (status, output) = self.vm.send_monitor_cmd("screendump " + self.screendump_filename) if status: # Failure - kvm_log.info("Could not fetch screendump") + logging.info("Could not fetch screendump") else: self.set_image_from_file(self.screendump_filename)
@@ -281,7 +281,7 @@ class StepMaker(stepeditor.StepMakerWindow): (status, output) = self.vm.send_monitor_cmd("screendump " + self.screendump_filename) if status: # Failure - kvm_log.info("Could not fetch screendump") + logging.info("Could not fetch screendump") else: self.set_image_from_file(self.screendump_filename)
Signature · 1 line
1.6.2.2
PATCH 2/5 Fixing exception raising to be compliant with the autotest coding standard.
On kvm autotest, we are raising exceptions like:
raise error.TestError, "Error message"
When the preferred form is:
raise error.TestError("Error message")
This change converts all occurrences of exception raising to the preferred form.
--- client/tests/kvm_runtest_2/kvm_guest_wizard.py | 8 +- client/tests/kvm_runtest_2/kvm_install.py | 18 +++--- client/tests/kvm_runtest_2/kvm_preprocessing.py | 4 +- client/tests/kvm_runtest_2/kvm_runtest_2.py | 2 +- client/tests/kvm_runtest_2/kvm_tests.py | 70 +++++++++++----------- client/tests/kvm_runtest_2/stepmaker.py | 8 +- 6 files changed, 55 insertions(+), 55 deletions(-)
client/tests/kvm_runtest_2/kvm_guest_wizard.py +4 -4
@@ -133,16 +133,16 @@ def barrier_2(vm, words, fail_if_stuck_for, stuck_detection_history, output_dir, def run_steps(test, params, env): vm = kvm_utils.env_get_vm(env, params.get("main_vm")) if not vm: - raise error.TestError, "VM object not found in environment" + raise error.TestError("VM object not found in environment") if not vm.is_alive(): - raise error.TestError, "VM seems to be dead; Guestwizard requires a living VM" + raise error.TestError("VM seems to be dead; Guestwizard requires a living VM") steps_filename = params.get("steps") if not steps_filename: - raise error.TestError, "Steps filename not specified" + raise error.TestError("Steps filename not specified") steps_filename = os.path.join(test.bindir, "steps", steps_filename) if not os.path.exists(steps_filename): - raise error.TestError, "Steps file not found: %s" % steps_filename + raise error.TestError("Steps file not found: %s" % steps_filename) fail_if_stuck_for = params.get("fail_if_stuck_for") if fail_if_stuck_for:
client/tests/kvm_runtest_2/kvm_install.py +9 -9
@@ -36,11 +36,11 @@ def run_kvm_install(test, params, env): if not repo: message = "KVM git repository path not specified" logging.error(message) - raise error.TestError, message + raise error.TestError(message) if not user_repo: message = "KVM user git repository path not specified" logging.error(message) - raise error.TestError, message + raise error.TestError(message) __install_kvm_from_git(test, srcdir, repo, user_repo, branch, tag, user_tag, lbranch)
@@ -51,7 +51,7 @@ def run_kvm_install(test, params, env): if not release_dir: message = "Release dir not specified" logging.error(message) - raise error.TestError, message + raise error.TestError(message) __install_kvm_release(test, srcdir, release_dir, release_tag) # install from snapshot
@@ -61,7 +61,7 @@ def run_kvm_install(test, params, env): if not snapshot_dir: message = "Snapshot dir not specified" logging.error(message) - raise error.TestError, message + raise error.TestError(message) __install_kvm_from_snapshot(test, srcdir, snapshot_dir, snapshot_date) # install from tarball
@@ -70,7 +70,7 @@ def run_kvm_install(test, params, env): if not tarball: message = "Local tarball filename not specified" logging.error(message) - raise error.TestError, message + raise error.TestError(message) __install_kvm_from_local_tarball(test, srcdir, tarball) # install from local sources
@@ -81,7 +81,7 @@ def run_kvm_install(test, params, env): else: message = "Invalid installation mode: '%s'" % install_mode logging.error(message) - raise error.TestError, message + raise error.TestError(message) # load kvm modules (unless requested not to) if params.get('load_modules', "yes") == "yes":
@@ -95,7 +95,7 @@ def __cleanup_dir(dir): if dirs or files: message = "Directory \'%s\' is not empty" % dir logging.error(message) - raise error.TestError, message + raise error.TestError(message) def __install_kvm_release(test, srcdir, release_dir, release_tag): if not release_tag:
@@ -208,7 +208,7 @@ def __load_kvm_modules(): if utils.system("grep kvm /proc/modules 1>/dev/null", ignore_status=True) == 0: message = "Failed to remove old KVM modules" logging.error(message) - raise error.TestError, message + raise error.TestError(message) logging.info("Loading new KVM modules...") os.chdir("kernel")
@@ -224,7 +224,7 @@ def __load_kvm_modules(): if utils.system("grep kvm_%s /proc/modules 1>/dev/null" %(vendor), ignore_status=True) != 0: message = "Failed to load KVM modules" logging.error(message) - raise error.TestError, message + raise error.TestError(message) def __install_kvm(test, srcdir): # create destination dir
client/tests/kvm_runtest_2/kvm_preprocessing.py +2 -2
@@ -35,7 +35,7 @@ def preprocess_image(test, params): if not kvm_vm.create_image(params, qemu_img_path, image_dir): message = "Could not create image" logging.error(message) - raise error.TestError, message + raise error.TestError(message) def preprocess_vm(test, params, env, name):
@@ -84,7 +84,7 @@ def preprocess_vm(test, params, env, name): if not vm.create(name, params, qemu_path, image_dir, iso_dir, for_migration): message = "Could not start VM" logging.error(message) - raise error.TestError, message + raise error.TestError(message) scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name) vm.send_monitor_cmd("screendump %s" % scrdump_filename)
client/tests/kvm_runtest_2/kvm_runtest_2.py +1 -1
@@ -77,7 +77,7 @@ class kvm_runtest_2(test.test): if not routine_obj: message = "Unsupported test type: %s" % type logging.error(message) - raise error.TestError, message + raise error.TestError(message) # If we don't have the test routine yet... if not routine_obj.routine: # Dynamically import the module
client/tests/kvm_runtest_2/kvm_tests.py +35 -35
240 lines not on this page · raw message
client/tests/kvm_runtest_2/stepmaker.py +4 -4
@@ -323,16 +323,16 @@ class StepMaker(stepeditor.StepMakerWindow): def run_stepmaker(test, params, env): vm = kvm_utils.env_get_vm(env, params.get("main_vm")) if not vm: - raise error.TestError, "VM object not found in environment" + raise error.TestError("VM object not found in environment") if not vm.is_alive(): - raise error.TestError, "VM seems to be dead; Step Maker requires a living VM" + raise error.TestError("VM seems to be dead; Step Maker requires a living VM") steps_filename = params.get("steps") if not steps_filename: - raise error.TestError, "Steps filename not specified" + raise error.TestError("Steps filename not specified") steps_filename = os.path.join(test.bindir, "steps", steps_filename) if os.path.exists(steps_filename): - raise error.TestError, "Steps file %s already exists" % steps_filename + raise error.TestError("Steps file %s already exists" % steps_filename) StepMaker(vm, steps_filename, test.debugdir, params) gtk.main()
Signature · 1 line
1.6.2.2
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 4/5 Sanitizing strings before passing them to the logging system.
The logging system encodes messages using the utf-8 encoding by default. So sometimes it's necessary to re-encode lines when non unicode characters are thrown up by the command outputs.
This patch re-encodes lines of text that will be passed to the logging system on the track_process function on kvm_utils.
--- client/tests/kvm_runtest_2/kvm_utils.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
client/tests/kvm_runtest_2/kvm_utils.py +3 -0
@@ -755,6 +755,9 @@ def track_process(sub, status_output=None, term_func=None, stdout_func=None, # Call stdout_func with the returned text if stdout_func: text = prefix + text.strip() + # We need to sanitize the text before passing it to the logging + # system + text = text.decode('utf-8', 'replace') stdout_func(text)
Signature · 1 line
1.6.2.2