Merge "Clone the proper branches in the dockerfile"
[functest.git] / ci / generate_report.py
old mode 100644 (file)
new mode 100755 (executable)
index 16962fe..d2e09eb
@@ -3,12 +3,13 @@ import os
 import re
 import urllib2
 import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as ft_utils
 
 
 COL_1_LEN = 25
 COL_2_LEN = 15
 COL_3_LEN = 12
-COL_4_LEN = 10
+COL_4_LEN = 15
 COL_5_LEN = 75
 
 # If we run from CI (Jenkins) we will push the results to the DB
@@ -32,11 +33,14 @@ def init(tiers_to_run):
 
 
 def get_results_from_db():
-    url = 'http://testresults.opnfv.org/test/api/v1/results?build_tag=' + \
-        BUILD_TAG
+    url = ft_utils.get_db_url() + '/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):
@@ -45,7 +49,7 @@ def get_data(test, results):
     for test_db in results:
         if test['test_name'] in test_db['case_name']:
             id = test_db['_id']
-            url = 'http://testresults.opnfv.org/test/api/v1/results/' + id
+            url = ft_utils.get_db_url() + '/results/' + id
             test_result = test_db['criteria']
 
     return {"url": url, "result": test_result}
@@ -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: