3 # 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
7 # http://www.apache.org/licenses/LICENSE-2.0
16 import scenarioResult as sr
19 import utils.reporting_utils as rp_utils
21 """Functest reporting status"""
24 logger = rp_utils.getLogger("Functest-Status")
29 reportingDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
31 # init just connection_check to get the list of scenarios
32 # as all the scenarios run connection_check
33 healthcheck = tc.TestCase("connection_check", "functest", -1)
35 # Retrieve the Functest configuration to detect which tests are relevant
36 # according to the installer, scenario
37 cf = rp_utils.get_config('functest.test_conf')
38 period = rp_utils.get_config('general.period')
39 versions = rp_utils.get_config('general.versions')
40 installers = rp_utils.get_config('general.installers')
41 blacklist = rp_utils.get_config('functest.blacklist')
42 log_level = rp_utils.get_config('general.log.log_level')
43 exclude_noha = rp_utils.get_config('functest.exclude_noha')
44 exclude_virtual = rp_utils.get_config('functest.exclude_virtual')
46 functest_yaml_config = rp_utils.getFunctestConfig()
48 logger.info("*******************************************")
50 logger.info("* Generating reporting scenario status *")
51 logger.info("* Data retention: %s days *" % period)
52 logger.info("* Log level: %s *" % log_level)
54 logger.info("* Virtual PODs exluded: %s *" % exclude_virtual)
55 logger.info("* NOHA scenarios excluded: %s *" % exclude_noha)
57 logger.info("*******************************************")
59 # Retrieve test cases of Tier 1 (smoke)
60 config_tiers = functest_yaml_config.get("tiers")
62 # we consider Tier 0 (Healthcheck), Tier 1 (smoke),2 (features)
63 # to validate scenarios
64 # Tier > 2 are not used to validate scenarios but we display the results anyway
65 # tricky thing for the API as some tests are Functest tests
66 # other tests are declared directly in the feature projects
67 for tier in config_tiers:
68 if tier['order'] >= 0 and tier['order'] < 2:
69 for case in tier['testcases']:
70 if case['case_name'] not in blacklist:
71 testValid.append(tc.TestCase(case['case_name'],
73 case['dependencies']))
74 elif tier['order'] == 2:
75 for case in tier['testcases']:
76 if case['case_name'] not in blacklist:
77 testValid.append(tc.TestCase(case['case_name'],
79 case['dependencies']))
80 elif tier['order'] > 2:
81 for case in tier['testcases']:
82 if case['case_name'] not in blacklist:
83 otherTestCases.append(tc.TestCase(case['case_name'],
85 case['dependencies']))
87 logger.debug("Functest reporting start")
89 # For all the versions
90 for version in versions:
91 # For all the installers
92 scenario_directory = "./display/" + version + "/functest/"
93 scenario_file_name = scenario_directory + "scenario_history.txt"
95 # check that the directory exists, if not create it
96 # (first run on new version)
97 if not os.path.exists(scenario_directory):
98 os.makedirs(scenario_directory)
100 # initiate scenario file if it does not exist
101 if not os.path.isfile(scenario_file_name):
102 with open(scenario_file_name, "a") as my_file:
103 logger.debug("Create scenario file: %s" % scenario_file_name)
104 my_file.write("date,scenario,installer,detail,score\n")
106 for installer in installers:
109 scenario_results = rp_utils.getScenarios(healthcheck,
112 # get nb of supported architecture (x86, aarch64)
113 architectures = rp_utils.getArchitectures(scenario_results)
114 logger.info("Supported architectures: {}".format(architectures))
116 for architecture in architectures:
117 logger.info("architecture: {}".format(architecture))
118 # Consider only the results for the selected architecture
119 # i.e drop x86 for aarch64 and vice versa
120 filter_results = rp_utils.filterArchitecture(scenario_results,
122 scenario_stats = rp_utils.getScenarioStats(filter_results)
124 scenario_result_criteria = {}
126 # in case of more than 1 architecture supported
127 # precise the architecture
128 installer_display = installer
129 if "fuel" in installer:
130 installer_display = installer + "@" + architecture
132 # For all the scenarios get results
133 for s, s_result in filter_results.items():
134 logger.info("---------------------------------")
135 logger.info("installer %s, version %s, scenario %s:" %
136 (installer, version, s))
137 logger.debug("Scenario results: %s" % s_result)
139 # Green or Red light for a given scenario
140 nb_test_runnable_for_this_scenario = 0
142 # url of the last jenkins log corresponding to a given
145 if len(s_result) > 0:
146 build_tag = s_result[len(s_result)-1]['build_tag']
147 logger.debug("Build tag: %s" % build_tag)
148 s_url = rp_utils.getJenkinsUrl(build_tag)
150 s_url = "http://testresultS.opnfv.org/reporting"
151 logger.info("last jenkins url: %s" % s_url)
152 testCases2BeDisplayed = []
153 # Check if test case is runnable / installer, scenario
154 # for the test case used for Scenario validation
156 # 1) Manage the test cases for the scenario validation
157 # concretely Tiers 0-3
158 for test_case in testValid:
159 test_case.checkRunnable(installer, s,
160 test_case.getConstraints())
161 logger.debug("testcase %s (%s) is %s" %
162 (test_case.getDisplayName(),
164 test_case.isRunnable))
166 if test_case.isRunnable:
167 name = test_case.getName()
168 displayName = test_case.getDisplayName()
169 project = test_case.getProject()
170 nb_test_runnable_for_this_scenario += 1
171 logger.info(" Searching results for case %s " %
173 result = rp_utils.getResult(name, installer,
175 # if no result set the value to 0
178 logger.info(" >>>> Test score = " + str(result))
179 test_case.setCriteria(result)
180 test_case.setIsRunnable(True)
181 testCases2BeDisplayed.append(tc.TestCase(name,
187 scenario_score = scenario_score + result
189 # 2) Manage the test cases for the scenario qualification
190 # concretely Tiers > 3
191 for test_case in otherTestCases:
192 test_case.checkRunnable(installer, s,
193 test_case.getConstraints())
194 logger.debug("testcase %s (%s) is %s" %
195 (test_case.getDisplayName(),
197 test_case.isRunnable))
199 if test_case.isRunnable:
200 name = test_case.getName()
201 displayName = test_case.getDisplayName()
202 project = test_case.getProject()
203 logger.info(" Searching results for case %s " %
205 result = rp_utils.getResult(name, installer,
207 # at least 1 result for the test
209 test_case.setCriteria(result)
210 test_case.setIsRunnable(True)
211 testCases2BeDisplayed.append(tc.TestCase(
219 logger.debug("No results found")
221 items[s] = testCases2BeDisplayed
223 logger.error("Error: installer %s, version %s, scenario %s"
224 % (installer, version, s))
225 logger.error("No data available: %s" % (sys.exc_info()[0]))
227 # **********************************************
228 # Evaluate the results for scenario validation
229 # **********************************************
230 # the validation criteria = nb runnable tests x 3
231 # because each test case = 0,1,2 or 3
232 scenario_criteria = nb_test_runnable_for_this_scenario * 3
233 # if 0 runnable tests set criteria at a high value
234 if scenario_criteria < 1:
235 scenario_criteria = 50 # conf.MAX_SCENARIO_CRITERIA
237 s_score = str(scenario_score) + "/" + str(scenario_criteria)
238 s_score_percent = rp_utils.getScenarioPercent(
243 if scenario_score < scenario_criteria:
244 logger.info(">>>> scenario not OK, score = %s/%s" %
245 (scenario_score, scenario_criteria))
248 logger.info(">>>>> scenario OK, save the information")
250 path_validation_file = ("./display/" + version +
252 "validated_scenario_history.txt")
253 with open(path_validation_file, "a") as f:
254 time_format = "%Y-%m-%d %H:%M"
255 info = (datetime.datetime.now().strftime(time_format) +
256 ";" + installer_display + ";" + s + "\n")
259 # Save daily results in a file
260 with open(scenario_file_name, "a") as f:
261 info = (reportingDate + "," + s + "," + installer_display +
262 "," + s_score + "," +
263 str(round(s_score_percent)) + "\n")
266 scenario_result_criteria[s] = sr.ScenarioResult(
271 logger.info("--------------------------")
273 templateLoader = jinja2.FileSystemLoader(".")
274 templateEnv = jinja2.Environment(
275 loader=templateLoader, autoescape=True)
277 TEMPLATE_FILE = ("./reporting/functest/template"
278 "/index-status-tmpl.html")
279 template = templateEnv.get_template(TEMPLATE_FILE)
281 outputText = template.render(
282 scenario_stats=scenario_stats,
283 scenario_results=scenario_result_criteria,
285 installer=installer_display,
290 with open("./display/" + version +
291 "/functest/status-" +
292 installer_display + ".html", "wb") as fh:
295 logger.info("Manage export CSV & PDF")
296 rp_utils.export_csv(scenario_file_name, installer_display, version)
297 logger.error("CSV generated...")
299 # Generate outputs for export
301 # TODO Change once web site updated...use the current one
302 # to test pdf production
303 url_pdf = rp_utils.get_config('general.url')
304 pdf_path = ("./display/" + version +
305 "/functest/status-" + installer_display + ".html")
306 pdf_doc_name = ("./display/" + version +
307 "/functest/status-" + installer_display + ".pdf")
308 rp_utils.export_pdf(pdf_path, pdf_doc_name)
309 logger.info("PDF generated...")