From d62529c532e25309a4ba9a9e07d5b61f077cc745 Mon Sep 17 00:00:00 2001 From: Igor Stoppa Date: Tue, 4 Nov 2014 15:31:11 +0200 Subject: [PATCH] Transition to logging facility. Use logging library. Change-Id: I4331d7b1ac08f6d8c16e95899b1b4e1d4179e5c0 --- job_test_build.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/job_test_build.py b/job_test_build.py index 7acc1e2..7dedbd5 100755 --- a/job_test_build.py +++ b/job_test_build.py @@ -5,6 +5,7 @@ import os import sys import glob +import logging import tarfile import subprocess from lxml import etree @@ -13,7 +14,10 @@ from common.buildtrigger import trigger_info, trigger_next def dump_result(outcome="TESTER_FAILURE", image="Not found"): """"Saves the results to a file, for injection""" - assert outcome in {"TESTER_FAILURE", "PASS", "FAIL"} + if outcome not in {"TESTER_FAILURE", "PASS", "FAIL"}: + logging.critical("Unexpected result '{0}' - forcing FAILURE."\ + .format(outcome)) + outcome = "TESTER_FAILURE" with open("Results.ENV", "w") as results: results.write("TEST_RESULT=" + outcome + "\n") results.write("IMAGE=" + image + "\n") @@ -21,18 +25,19 @@ def dump_result(outcome="TESTER_FAILURE", image="Not found"): def fetch_image(url): """Tries to download locally the image that will be tested.""" - print "Attempt retrieving flashable image from %s ..." % url, + logging.info("Attempt retrieving flashable image from {0} ."\ + .format(url)) try: command = ["/usr/bin/wget", "-r", "-l1", "-np", "-nd", "-q", "-A", os.getenv("TESTABLE_IMAGE_DOWNLOADABLES"), url] subprocess.check_output(command) image = glob.glob(os.getenv("TESTABLE_IMAGE_FILTER"))[0] - print "done." + logging.info("Image retrieved successfully.") return image except (IndexError, ValueError, subprocess.CalledProcessError, OSError) as error: - print "failed." - print error + logging.critical("Failure retrieving the image.") + logging.critical(error) dump_result("TESTER_FAILURE") return None @@ -44,31 +49,31 @@ def test_image(image): output = subprocess.check_output(command) except OSError as error: result = "TESTER_FAILURE" - print "Failed to flash the image." - print error + logging.critical("Failed to flash the image.\n" + + "Error: {0}".format(error)) except (ValueError, subprocess.CalledProcessError) as error: result = "FAIL" - print "Either the device didn't boot or some test failed." - print error + logging.error("Either the device didn't boot." + + "Error: {0}".format(error)) else: - print output result = "PASS" - print "The device can boot and all the tests succeeded." + logging.info("The device can boot and all the tests were run." + + "Output: {0}".format(output)) return result def pack_results(results_folder): """Creates a tarball containing the test results""" if not results_folder: return - print "Packing test results ... ", + logging.info("Packing test results.") try: tar = tarfile.open("results.tar.gz", "w:gz") tar.add(results_folder) except (ValueError, OSError) as error: - print "failed." - print error + logging.critical("Failed packing test results." + + "Error: {0}".format(error)) else: - print "done." + logging.info("Completed packing test results.") def xml_tree_to_dict(tree): """Converts junit xml file to a dictionary""" -- 2.7.4