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
14 import functest.utils.functest_utils as ft_utils
15 from functest.utils.constants import CONST
23 # If we run from CI (Jenkins) we will push the results to the DB
24 # and then we can print the url to the specific test result
27 logger = logging.getLogger(__name__)
30 def init(tiers_to_run=[]):
32 for tier in tiers_to_run:
33 for test in tier.get_tests():
34 test_cases_arr.append({'test_name': test.get_name(),
35 'tier_name': tier.get_name(),
36 'result': 'Not executed',
42 def get_results_from_db():
43 url = "%s/results?build_tag=%s" % (ft_utils.get_db_url(),
45 logger.debug("Query to rest api: %s" % url)
47 data = json.load(urllib2.urlopen(url))
48 return data['results']
50 logger.error("Cannot read content from the url: %s" % url)
54 def get_data(test, results):
55 test_result = test['result']
57 for test_db in results:
58 if test['test_name'] in test_db['case_name']:
60 url = ft_utils.get_db_url() + '/results/' + id
61 test_result = test_db['criteria']
63 return {"url": url, "result": test_result}
66 def print_line(w1, w2='', w3='', w4='', w5=''):
67 str = ('| ' + w1.ljust(COL_1_LEN - 1) +
68 '| ' + w2.ljust(COL_2_LEN - 1) +
69 '| ' + w3.ljust(COL_3_LEN - 1) +
70 '| ' + w4.ljust(COL_4_LEN - 1))
72 str += ('| ' + w5.ljust(COL_5_LEN - 1))
77 def print_line_no_columns(str):
78 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN + 2
80 TOTAL_LEN += COL_5_LEN + 1
81 return ('| ' + str.ljust(TOTAL_LEN) + "|\n")
84 def print_separator(char="=", delimiter="+"):
85 str = ("+" + char * COL_1_LEN +
86 delimiter + char * COL_2_LEN +
87 delimiter + char * COL_3_LEN +
88 delimiter + char * COL_4_LEN)
90 str += (delimiter + char * COL_5_LEN)
96 executed_test_cases = args
99 results = get_results_from_db()
100 if results is not None:
101 for test in executed_test_cases:
102 data = get_data(test, results)
103 test.update({"url": data['url'],
104 "result": data['result']})
106 TOTAL_LEN = COL_1_LEN + COL_2_LEN + COL_3_LEN + COL_4_LEN
108 TOTAL_LEN += COL_5_LEN
111 if CONST.BUILD_TAG is not None:
112 if re.search("daily", CONST.BUILD_TAG) is not None:
113 CONST.CI_LOOP = "daily"
115 CONST.CI_LOOP = "weekly"
118 str += print_separator('=', delimiter="=")
119 str += print_line_no_columns(' ' * (MID - 8) + 'FUNCTEST REPORT')
120 str += print_separator('=', delimiter="=")
121 str += print_line_no_columns(' ')
122 str += print_line_no_columns(" Deployment description:")
123 str += print_line_no_columns(" INSTALLER: %s"
124 % CONST.INSTALLER_TYPE)
125 if CONST.DEPLOY_SCENARIO is not None:
126 str += print_line_no_columns(" SCENARIO: %s"
127 % CONST.DEPLOY_SCENARIO)
128 if CONST.BUILD_TAG is not None:
129 str += print_line_no_columns(" BUILD TAG: %s"
131 if CONST.CI_LOOP is not None:
132 str += print_line_no_columns(" CI LOOP: %s"
134 str += print_line_no_columns(' ')
135 str += print_separator('=')
137 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT', 'URL')
139 str += print_line('TEST CASE', 'TIER', 'DURATION', 'RESULT')
140 str += print_separator('=')
141 for test in executed_test_cases:
142 str += print_line(test['test_name'],
147 str += print_separator('-')
149 logger.info("\n\n\n%s" % str)
152 if __name__ == '__main__':
153 logging.basicConfig()