From 7f6920c82b35770df06ebb82b66a0f9f3e27c2fe Mon Sep 17 00:00:00 2001 From: Igor Stoppa Date: Thu, 15 Jan 2015 15:16:40 +0200 Subject: [PATCH] Fix checks and return values for image test. In case of image either missing or not supported, the test is wrong and the image name is not propagated. Change-Id: Iff91d15c0e0c3ba5fe8b51c4a1299c6642a231a5 --- job_test_build.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/job_test_build.py b/job_test_build.py index 92efd09..933a1c7 100755 --- a/job_test_build.py +++ b/job_test_build.py @@ -41,7 +41,7 @@ def fetch_image(url): 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] + image = glob.glob("*.bz2")[0] logging.info("Image retrieved successfully.") return image except (IndexError, ValueError, subprocess.CalledProcessError, @@ -65,8 +65,8 @@ def test_image(image): "Error: {0}".format(error)) except (ValueError, subprocess.CalledProcessError) as error: result = "FAIL" - logging.error("Either the device didn't boot." + - "Error: {0}".format(error)) + logging.critical("The device is not reachable." + + "Error: {0}".format(error)) else: result = "PASS" logging.info("The device can boot and all the tests were run." + @@ -152,6 +152,7 @@ def propagate_results(fields, image): """ Store results to file and trigger publishing job. """ + logging.info("Packing results and triggering next job.") with open("Results.ENV", "w") as results: results.write("TEST_RESULT=" + fields["test_result"] + "\n") results.write("IMAGE=" + image + "\n") @@ -178,29 +179,35 @@ def main(): fields = trigger_info(os.getenv("TRIGGER_INFO")) try: - file_name = ET.fromstring(fields["image_xml"])\ - .find("storage").find("disk").get("file") + file_name = "" + xml = ET.fromstring(fields["image_xml"]) + logging.info("Extracted xml from environment {0}".format(xml)) + storage = xml.find("storage") + logging.info("Storage {0}".format(storage)) + disk = storage.find("disk") + logging.info("Disk {0}".format(disk)) + file_name = disk.get("file") logging.info("Image to test: {0}".format(file_name)) - except AttributeError as e: - logging.error("Error: {0}".format(e)) + except AttributeError as error: + logging.critical("Error: {0}".format(error)) fields["test_result"] = "PARAMETERS_ERRORS" - propagate_results(image="", fields=fields); + propagate_results(image=file_name, fields=fields) return 0 if not image_supported(file_name): logging.info("Image not supported by the tester.") fields["test_result"] = "IMAGE_NOT_SUPPORTED" - propagate_results(image="", fields=fields) + propagate_results(image=file_name, fields=fields) return 0 image = fetch_image(fields["url"]) - if image == "": + if image is "": fields["test_result"] = "IMAGE_NOT_FOUND" - propagate_results(image="", fields=fields) + propagate_results(image=file_name, fields=fields) return 0 fields["test_result"] = test_image(image) - propagate_results(image=image, fields=fields) + propagate_results(image=file_name, fields=fields) return 0 -- 2.7.4