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)
38 data = json.load(urllib2.urlopen(url))
39 return data['results']
42 def get_data(test, results):
43 test_result = test['result']
45 for test_db in results:
46 if test['test_name'] in test_db['case_name']:
48 url = 'http://testresults.opnfv.org/test/api/v1/results/' + id
49 test_result = test_db['criteria']
51 return {"url": url, "result": test_result}
54 def print_line(w1, w2='', w3='', w4='', w5=''):
55 str = ('| ' + w1.ljust(COL_1_LEN - 1) +
56 '| ' + w2.ljust(COL_2_LEN - 1) +
57 '| ' + w3.ljust(COL_3_LEN - 1) +
58 '| ' + w4.ljust(COL_4_LEN - 1))
60 str += ('| ' + w5.ljust(COL_5_LEN - 1))
65 def print_line_no_columns(str):
66 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2
68 TOTAL_LEN += COL_5_LEN + 1
69 return ('| ' + str.ljust(TOTAL_LEN) + "|\n")
72 def print_separator(char="=", delimiter="+"):
73 str = ("+" + char * COL_1_LEN +
74 delimiter + char * COL_2_LEN +
75 delimiter + char * COL_3_LEN +
76 delimiter + char * COL_4_LEN)
78 str += (delimiter + char * COL_5_LEN)
84 global BUILD_TAG, IS_CI_RUN
85 executed_test_cases = args
87 BUILD_TAG = os.getenv("BUILD_TAG")
88 if BUILD_TAG is not None:
92 results = get_results_from_db()
93 for test in executed_test_cases:
94 data = get_data(test, results)
95 test.update({"url": data['url'],
96 "result": data['result']})
98 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
100 TOTAL_LEN += COL_5_LEN
103 INSTALLER = os.getenv('INSTALLER_TYPE', 'unknown')
104 CI_LOOP = os.getenv('CI_LOOP')
105 SCENARIO = os.getenv('DEPLOY_SCENARIO')
107 if BUILD_TAG is not None:
108 if re.search("daily", BUILD_TAG) is not None:
114 str += print_separator('=', delimiter="=")
115 str += print_line_no_columns(' ' * (MID - 8) + 'FUNCTEST REPORT')
116 str += print_separator('=', delimiter="=")
117 str += print_line_no_columns(' ')
118 str += print_line_no_columns(" Deployment description:")
119 str += print_line_no_columns(" INSTALLER: %s" % INSTALLER)
120 if SCENARIO is not None:
121 str += print_line_no_columns(" SCENARIO: %s" % SCENARIO)
122 if BUILD_TAG is not None:
123 str += print_line_no_columns(" BUILD TAG: %s" % BUILD_TAG)
124 if CI_LOOP is not None:
125 str += print_line_no_columns(" CI LOOP: %s" % CI_LOOP)
126 str += print_line_no_columns(' ')
127 str += print_separator('=')
129 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL')
131 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT')
132 str += print_separator('=')
133 for test in executed_test_cases:
134 str += print_line(test['test_name'],
139 str += print_separator('-')
141 logger.info("\n\n\n%s" % str)
144 if __name__ == '__main__':