Wrap call to the rest api with try-except while generating report 63/17863/1
authorjose.lausuch <jose.lausuch@ericsson.com>
Sun, 31 Jul 2016 20:15:44 +0000 (22:15 +0200)
committerjose.lausuch <jose.lausuch@ericsson.com>
Sun, 31 Jul 2016 20:15:44 +0000 (22:15 +0200)
When the Rest api is not available for some reason
(see associated JIRA), the script fails and it gives also a false
output to Jenkins.

JIRA: FUNCTEST-399

Change-Id: I81622a2e22661889afcf49526c2421af257920a4
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
ci/generate_report.py

index 53aef0c..3ca2847 100644 (file)
@@ -35,8 +35,12 @@ def get_results_from_db():
     url = 'http://testresults.opnfv.org/test/api/v1/results?build_tag=' + \
         BUILD_TAG
     logger.debug("Query to rest api: %s" % url)
-    data = json.load(urllib2.urlopen(url))
-    return data['results']
+    try:
+        data = json.load(urllib2.urlopen(url))
+        return data['results']
+    except:
+        logger.error("Cannot read content from the url: %s" % url)
+        return None
 
 
 def get_data(test, results):
@@ -90,10 +94,11 @@ def main(args):
 
     if IS_CI_RUN:
         results = get_results_from_db()
-        for test in executed_test_cases:
-            data = get_data(test, results)
-            test.update({"url": data['url'],
-                         "result": data['result']})
+        if results is not None:
+            for test in executed_test_cases:
+                data = get_data(test, results)
+                test.update({"url": data['url'],
+                             "result": data['result']})
 
     TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
     if IS_CI_RUN: