Fix checks and return values for image test.
authorIgor Stoppa <igor.stoppa@intel.com>
Thu, 15 Jan 2015 13:16:40 +0000 (15:16 +0200)
committerXu Chang <changx.xu@intel.com>
Tue, 20 Jan 2015 08:48:37 +0000 (16:48 +0800)
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

index 92efd09..933a1c7 100755 (executable)
@@ -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