From bb3419f192cafe4090753e5568f1e14071069dd2 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Sun, 31 Jul 2016 22:15:44 +0200 Subject: Wrap call to the rest api with try-except while generating report 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 --- ci/generate_report.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ci') diff --git a/ci/generate_report.py b/ci/generate_report.py index 53aef0c9e..3ca2847bd 100644 --- a/ci/generate_report.py +++ b/ci/generate_report.py @@ -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: -- cgit 1.2.3-korg