3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
12 import functest.utils.functest_logger as ft_logger
13 import functest.utils.functest_utils as ft_utils
14 from functest.utils.constants import CONST
22 # If we run from CI (Jenkins) we will push the results to the DB
23 # and then we can print the url to the specific test result
26 logger = ft_logger.Logger("generate_report").getLogger()
29 def init(tiers_to_run=[]):
31 for tier in tiers_to_run:
32 for test in tier.get_tests():
33 test_cases_arr.append({'test_name': test.get_name(),
34 'tier_name': tier.get_name(),
35 'result': 'Not executed',
41 def get_results_from_db():
42 url = "%s/results?build_tag=%s" % (ft_utils.get_db_url(),
44 logger.debug("Query to rest api: %s" % url)
46 data = json.load(urllib2.urlopen(url))
47 return data['results']
49 logger.error("Cannot read content from the url: %s" % url)
53 def get_data(test, results):
54 test_result = test['result']
56 for test_db in results:
57 if test['test_name'] in test_db['case_name']:
59 url = ft_utils.get_db_url() + '/results/' + id
60 test_result = test_db['criteria']
62 return {"url": url, "result": test_result}
65 def print_line(w1, w2='', w3='', w4='', w5=''):
66 str = ('| ' + w1.ljust(COL_1_LEN - 1) +
67 '| ' + w2.ljust(COL_2_LEN - 1) +
68 '| ' + w3.ljust(COL_3_LEN - 1) +
69 '| ' + w4.ljust(COL_4_LEN - 1))
71 str += ('| ' + w5.ljust(COL_5_LEN - 1))
76 def print_line_no_columns(str):
77 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2
79 TOTAL_LEN += COL_5_LEN + 1
80 return ('| ' + str.ljust(TOTAL_LEN) + "|\n")
83 def print_separator(char="=", delimiter="+"):
84 str = ("+" + char * COL_1_LEN +
85 delimiter + char * COL_2_LEN +
86 delimiter + char * COL_3_LEN +
87 delimiter + char * COL_4_LEN)
89 str += (delimiter + char * COL_5_LEN)
95 executed_test_cases = args
98 results = get_results_from_db()
99 if results is not None:
100 for test in executed_test_cases:
101 data = get_data(test, results)
102 test.update({"url": data['url'],
103 "result": data['result']})
105 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
107 TOTAL_LEN += COL_5_LEN
110 if CONST.BUILD_TAG is not None:
111 if re.search("daily", CONST.BUILD_TAG) is not None:
112 CONST.CI_LOOP = "daily"
114 CONST.CI_LOOP = "weekly"
117 str += print_separator('=', delimiter="=")
118 str += print_line_no_columns(' ' * (MID - 8) + 'FUNCTEST REPORT')
119 str += print_separator('=', delimiter="=")
120 str += print_line_no_columns(' ')
121 str += print_line_no_columns(" Deployment description:")
122 str += print_line_no_columns(" INSTALLER: %s"
123 % CONST.INSTALLER_TYPE)
124 if CONST.DEPLOY_SCENARIO is not None:
125 str += print_line_no_columns(" SCENARIO: %s"
126 % CONST.DEPLOY_SCENARIO)
127 if CONST.BUILD_TAG is not None:
128 str += print_line_no_columns(" BUILD TAG: %s"
130 if CONST.CI_LOOP is not None:
131 str += print_line_no_columns(" CI LOOP: %s"
133 str += print_line_no_columns(' ')
134 str += print_separator('=')
136 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL')
138 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT')
139 str += print_separator('=')
140 for test in executed_test_cases:
141 str += print_line(test['test_name'],
146 str += print_separator('-')
148 logger.info("\n\n\n%s" % str)
151 if __name__ == '__main__':