6 import functest.utils.functest_logger as ft_logger
7 import functest.utils.functest_utils as ft_utils
16 # If we run from CI (Jenkins) we will push the results to the DB
17 # and then we can print the url to the specific test result
21 logger = ft_logger.Logger("generate_report").getLogger()
24 def init(tiers_to_run):
26 for tier in tiers_to_run:
27 for test in tier.get_tests():
28 test_cases_arr.append({'test_name': test.get_name(),
29 'tier_name': tier.get_name(),
30 'result': 'Not executed',
36 def get_results_from_db():
37 url = ft_utils.get_db_url() + '/results?build_tag=' + BUILD_TAG
38 logger.debug("Query to rest api: %s" % url)
40 data = json.load(urllib2.urlopen(url))
41 return data['results']
43 logger.error("Cannot read content from the url: %s" % url)
47 def get_data(test, results):
48 test_result = test['result']
50 for test_db in results:
51 if test['test_name'] in test_db['case_name']:
53 url = ft_utils.get_db_url() + '/results/' + id
54 test_result = test_db['criteria']
56 return {"url": url, "result": test_result}
59 def print_line(w1, w2='', w3='', w4='', w5=''):
60 str = ('| ' + w1.ljust(COL_1_LEN - 1) +
61 '| ' + w2.ljust(COL_2_LEN - 1) +
62 '| ' + w3.ljust(COL_3_LEN - 1) +
63 '| ' + w4.ljust(COL_4_LEN - 1))
65 str += ('| ' + w5.ljust(COL_5_LEN - 1))
70 def print_line_no_columns(str):
71 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2
73 TOTAL_LEN += COL_5_LEN + 1
74 return ('| ' + str.ljust(TOTAL_LEN) + "|\n")
77 def print_separator(char="=", delimiter="+"):
78 str = ("+" + char * COL_1_LEN +
79 delimiter + char * COL_2_LEN +
80 delimiter + char * COL_3_LEN +
81 delimiter + char * COL_4_LEN)
83 str += (delimiter + char * COL_5_LEN)
89 global BUILD_TAG, IS_CI_RUN
90 executed_test_cases = args
92 BUILD_TAG = os.getenv("BUILD_TAG")
93 if BUILD_TAG is not None:
97 results = get_results_from_db()
98 if results is not None:
99 for test in executed_test_cases:
100 data = get_data(test, results)
101 test.update({"url": data['url'],
102 "result": data['result']})
104 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
106 TOTAL_LEN += COL_5_LEN
109 INSTALLER = os.getenv('INSTALLER_TYPE', 'unknown')
110 CI_LOOP = os.getenv('CI_LOOP')
111 SCENARIO = os.getenv('DEPLOY_SCENARIO')
113 if BUILD_TAG is not None:
114 if re.search("daily", BUILD_TAG) is not None:
120 str += print_separator('=', delimiter="=")
121 str += print_line_no_columns(' ' * (MID - 8) + 'FUNCTEST REPORT')
122 str += print_separator('=', delimiter="=")
123 str += print_line_no_columns(' ')
124 str += print_line_no_columns(" Deployment description:")
125 str += print_line_no_columns(" INSTALLER: %s" % INSTALLER)
126 if SCENARIO is not None:
127 str += print_line_no_columns(" SCENARIO: %s" % SCENARIO)
128 if BUILD_TAG is not None:
129 str += print_line_no_columns(" BUILD TAG: %s" % BUILD_TAG)
130 if CI_LOOP is not None:
131 str += print_line_no_columns(" CI LOOP: %s" % CI_LOOP)
132 str += print_line_no_columns(' ')
133 str += print_separator('=')
135 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL')
137 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT')
138 str += print_separator('=')
139 for test in executed_test_cases:
140 str += print_line(test['test_name'],
145 str += print_separator('-')
147 logger.info("\n\n\n%s" % str)
150 if __name__ == '__main__':