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
14 import reporting.utils.reporting_utils as rp_utils
15 import reporting.utils.scenarioResult as sr
17 INSTALLERS = rp_utils.get_config('general.installers')
18 VERSIONS = rp_utils.get_config('general.versions')
19 PERIOD = rp_utils.get_config('general.period')
22 LOGGER = rp_utils.getLogger("Bottlenecks-Status")
23 reportingDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
25 LOGGER.info("*******************************************")
26 LOGGER.info("* Generating reporting scenario status *")
27 LOGGER.info("* Data retention = %s days *", PERIOD)
29 LOGGER.info("*******************************************")
31 # retrieve the list of bottlenecks tests
32 BOTTLENECKS_TESTS = rp_utils.get_config('bottlenecks.test_list')
33 LOGGER.info("Bottlenecks tests: %s", BOTTLENECKS_TESTS)
35 # For all the versions
36 for version in VERSIONS:
37 # For all the installers
38 for installer in INSTALLERS:
39 # get scenarios results data
40 scenario_results = rp_utils.getScenarios("bottlenecks",
44 LOGGER.info("scenario_results: %s", scenario_results)
46 scenario_stats = rp_utils.getScenarioStats(scenario_results)
47 LOGGER.info("scenario_stats: %s", scenario_stats)
49 scenario_result_criteria = {}
51 # From each scenarios get results list
52 for s, s_result in scenario_results.items():
53 LOGGER.info("---------------------------------")
54 LOGGER.info("installer %s, version %s, scenario %s", installer,
56 ten_criteria = len(s_result)
60 if "PASS" in v['criteria']:
63 LOGGER.info("ten_score: %s / %s", (ten_score, ten_criteria))
67 LASTEST_TESTS = rp_utils.get_config(
68 'general.nb_iteration_tests_success_criteria')
69 s_result.sort(key=lambda x: x['start_date'])
70 four_result = s_result[-LASTEST_TESTS:]
71 LOGGER.debug("four_result: {}".format(four_result))
72 LOGGER.debug("LASTEST_TESTS: {}".format(LASTEST_TESTS))
73 # logger.debug("four_result: {}".format(four_result))
74 four_criteria = len(four_result)
76 if "PASS" in v['criteria']:
78 LOGGER.info("4 Score: %s / %s ", (four_score,
81 LOGGER.error("Impossible to retrieve the four_score")
84 s_status = (four_score * 100) / four_criteria
87 LOGGER.info("Score percent = %s", str(s_status))
88 s_four_score = str(four_score) + '/' + str(four_criteria)
89 s_ten_score = str(ten_score) + '/' + str(ten_criteria)
90 s_score_percent = str(s_status)
92 LOGGER.debug(" s_status: %s", s_status)
94 LOGGER.info(">>>>> scenario OK, save the information")
96 LOGGER.info(">>>> scenario not OK, last 4 iterations = %s, \
97 last 10 days = %s", (s_four_score, s_ten_score))
100 if len(s_result) > 0:
101 build_tag = s_result[len(s_result)-1]['build_tag']
102 LOGGER.debug("Build tag: %s", build_tag)
103 s_url = s_url = rp_utils.getJenkinsUrl(build_tag)
104 LOGGER.info("last jenkins url: %s", s_url)
106 # Save daily results in a file
107 path_validation_file = ("./display/" + version +
108 "/bottlenecks/scenario_history.txt")
110 if not os.path.exists(path_validation_file):
111 with open(path_validation_file, 'w') as f:
112 info = 'date,scenario,installer,details,score\n'
115 with open(path_validation_file, "a") as f:
116 info = (reportingDate + "," + s + "," + installer +
117 "," + s_ten_score + "," +
118 str(s_score_percent) + "\n")
121 scenario_result_criteria[s] = sr.ScenarioResult(s_status,
127 LOGGER.info("--------------------------")
129 templateLoader = jinja2.FileSystemLoader(".")
130 templateEnv = jinja2.Environment(loader=templateLoader,
133 TEMPLATE_FILE = ("./reporting/bottlenecks/template"
134 "/index-status-tmpl.html")
135 template = templateEnv.get_template(TEMPLATE_FILE)
137 outputText = template.render(scenario_results=scenario_result_criteria,
143 with open("./display/" + version +
144 "/bottlenecks/status-" + installer + ".html", "wb") as fh: