5 import functest.utils.functest_logger as ft_logger
14 # If we run from CI (Jenkins) we will push the results to the DB
15 # and then we can print the url to the specific test result
19 logger = ft_logger.Logger("generate_report").getLogger()
22 def init(tiers_to_run):
24 for tier in tiers_to_run:
25 for test in tier.get_tests():
26 test_cases_arr.append({'test_name': test.get_name(),
27 'tier_name': tier.get_name(),
28 'result': 'Not executed',
34 def get_results_from_db():
35 url = 'http://testresults.opnfv.org/test/api/v1/results?build_tag=' + \
37 logger.debug("Query to rest api: %s" % url)
39 data = json.load(urllib2.urlopen(url))
40 return data['results']
42 logger.error("Cannot read content from the url: %s" % url)
46 def get_data(test, results):
47 test_result = test['result']
49 for test_db in results:
50 if test['test_name'] in test_db['case_name']:
52 url = 'http://testresults.opnfv.org/test/api/v1/results/' + id
53 test_result = test_db['criteria']
55 return {"url": url, "result": test_result}
58 def print_line(w1, w2='', w3='', w4='', w5=''):
59 str = ('| ' + w1.ljust(COL_1_LEN - 1) +
60 '| ' + w2.ljust(COL_2_LEN - 1) +
61 '| ' + w3.ljust(COL_3_LEN - 1) +
62 '| ' + w4.ljust(COL_4_LEN - 1))
64 str += ('| ' + w5.ljust(COL_5_LEN - 1))
69 def print_line_no_columns(str):
70 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2
72 TOTAL_LEN += COL_5_LEN + 1
73 return ('| ' + str.ljust(TOTAL_LEN) + "|\n")
76 def print_separator(char="=", delimiter="+"):
77 str = ("+" + char * COL_1_LEN +
78 delimiter + char * COL_2_LEN +
79 delimiter + char * COL_3_LEN +
80 delimiter + char * COL_4_LEN)
82 str += (delimiter + char * COL_5_LEN)
88 global BUILD_TAG, IS_CI_RUN
89 executed_test_cases = args
91 BUILD_TAG = os.getenv("BUILD_TAG")
92 if BUILD_TAG is not None:
96 results = get_results_from_db()
97 if results is not None:
98 for test in executed_test_cases:
99 data = get_data(test, results)
100 test.update({"url": data['url'],
101 "result": data['result']})
103 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
105 TOTAL_LEN += COL_5_LEN
108 INSTALLER = os.getenv('INSTALLER_TYPE', 'unknown')
109 CI_LOOP = os.getenv('CI_LOOP')
110 SCENARIO = os.getenv('DEPLOY_SCENARIO')
112 if BUILD_TAG is not None:
113 if re.search("daily", BUILD_TAG) is not None:
119 str += print_separator('=', delimiter="=")
120 str += print_line_no_columns(' ' * (MID - 8) + 'FUNCTEST REPORT')
121 str += print_separator('=', delimiter="=")
122 str += print_line_no_columns(' ')
123 str += print_line_no_columns(" Deployment description:")
124 str += print_line_no_columns(" INSTALLER: %s" % INSTALLER)
125 if SCENARIO is not None:
126 str += print_line_no_columns(" SCENARIO: %s" % SCENARIO)
127 if BUILD_TAG is not None:
128 str += print_line_no_columns(" BUILD TAG: %s" % BUILD_TAG)
129 if CI_LOOP is not None:
130 str += print_line_no_columns(" CI LOOP: %s" % CI_LOOP)
131 str += print_line_no_columns(' ')
132 str += print_separator('=')
134 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL')
136 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT')
137 str += print_separator('=')
138 for test in executed_test_cases:
139 str += print_line(test['test_name'],
144 str += print_separator('-')
146 logger.info("\n\n\n%s" % str)
149 if __name__ == '__main__':