5 import functest.utils.functest_logger as ft_logger
6 import functest.utils.functest_utils as ft_utils
7 import functest.utils.functest_constants as ft_constants
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
20 class GlobalVariables:
21 IS_CI_RUN = ft_constants.IS_CI_RUN
22 BUILD_TAG = ft_constants.CI_BUILD_TAG
23 INSTALLER = ft_constants.CI_INSTALLER_TYPE
24 CI_LOOP = ft_constants.CI_LOOP
25 SCENARIO = ft_constants.CI_SCENARIO
28 logger = ft_logger.Logger("generate_report").getLogger()
31 def init(tiers_to_run):
33 for tier in tiers_to_run:
34 for test in tier.get_tests():
35 test_cases_arr.append({'test_name': test.get_name(),
36 'tier_name': tier.get_name(),
37 'result': 'Not executed',
43 def get_results_from_db():
44 url = "%s/results?build_tag=%s" % (ft_utils.get_db_url(),
45 GlobalVariables.BUILD_TAG)
46 logger.debug("Query to rest api: %s" % url)
48 data = json.load(urllib2.urlopen(url))
49 return data['results']
51 logger.error("Cannot read content from the url: %s" % url)
55 def get_data(test, results):
56 test_result = test['result']
58 for test_db in results:
59 if test['test_name'] in test_db['case_name']:
61 url = ft_utils.get_db_url() + '/results/' + id
62 test_result = test_db['criteria']
64 return {"url": url, "result": test_result}
67 def print_line(w1, w2='', w3='', w4='', w5=''):
68 str = ('| ' + w1.ljust(COL_1_LEN - 1) +
69 '| ' + w2.ljust(COL_2_LEN - 1) +
70 '| ' + w3.ljust(COL_3_LEN - 1) +
71 '| ' + w4.ljust(COL_4_LEN - 1))
72 if GlobalVariables.IS_CI_RUN:
73 str += ('| ' + w5.ljust(COL_5_LEN - 1))
78 def print_line_no_columns(str):
79 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2
80 if GlobalVariables.IS_CI_RUN:
81 TOTAL_LEN += COL_5_LEN + 1
82 return ('| ' + str.ljust(TOTAL_LEN) + "|\n")
85 def print_separator(char="=", delimiter="+"):
86 str = ("+" + char * COL_1_LEN +
87 delimiter + char * COL_2_LEN +
88 delimiter + char * COL_3_LEN +
89 delimiter + char * COL_4_LEN)
90 if GlobalVariables.IS_CI_RUN:
91 str += (delimiter + char * COL_5_LEN)
97 executed_test_cases = args
99 if GlobalVariables.IS_CI_RUN:
100 results = get_results_from_db()
101 if results is not None:
102 for test in executed_test_cases:
103 data = get_data(test, results)
104 test.update({"url": data['url'],
105 "result": data['result']})
107 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
108 if GlobalVariables.IS_CI_RUN:
109 TOTAL_LEN += COL_5_LEN
112 if GlobalVariables.BUILD_TAG is not None:
113 if re.search("daily", GlobalVariables.BUILD_TAG) is not None:
114 GlobalVariables.CI_LOOP = "daily"
116 GlobalVariables.CI_LOOP = "weekly"
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"
125 % GlobalVariables.INSTALLER)
126 if GlobalVariables.SCENARIO is not None:
127 str += print_line_no_columns(" SCENARIO: %s"
128 % GlobalVariables.SCENARIO)
129 if GlobalVariables.BUILD_TAG is not None:
130 str += print_line_no_columns(" BUILD TAG: %s"
131 % GlobalVariables.BUILD_TAG)
132 if GlobalVariables.CI_LOOP is not None:
133 str += print_line_no_columns(" CI LOOP: %s"
134 % GlobalVariables.CI_LOOP)
135 str += print_line_no_columns(' ')
136 str += print_separator('=')
137 if GlobalVariables.IS_CI_RUN:
138 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL')
140 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT')
141 str += print_separator('=')
142 for test in executed_test_cases:
143 str += print_line(test['test_name'],
148 str += print_separator('-')
150 logger.info("\n\n\n%s" % str)
153 if __name__ == '__main__':