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 if version != 'master':
41 new_version = "stable/{}".format(version)
44 scenario_results = rp_utils.getScenarios("bottlenecks",
48 LOGGER.info("scenario_results: %s", scenario_results)
50 scenario_stats = rp_utils.getScenarioStats(scenario_results)
51 LOGGER.info("scenario_stats: %s", scenario_stats)
53 scenario_result_criteria = {}
55 # From each scenarios get results list
56 for s, s_result in scenario_results.items():
57 LOGGER.info("---------------------------------")
58 LOGGER.info("installer %s, version %s, scenario %s", installer,
60 ten_criteria = len(s_result)
64 if "PASS" in v['criteria']:
67 LOGGER.info("ten_score: %s / %s", (ten_score, ten_criteria))
71 LASTEST_TESTS = rp_utils.get_config(
72 'general.nb_iteration_tests_success_criteria')
73 s_result.sort(key=lambda x: x['start_date'])
74 four_result = s_result[-LASTEST_TESTS:]
75 LOGGER.debug("four_result: {}".format(four_result))
76 LOGGER.debug("LASTEST_TESTS: {}".format(LASTEST_TESTS))
77 # logger.debug("four_result: {}".format(four_result))
78 four_criteria = len(four_result)
80 if "PASS" in v['criteria']:
82 LOGGER.info("4 Score: %s / %s ", (four_score,
85 LOGGER.error("Impossible to retrieve the four_score")
88 s_status = (four_score * 100) / four_criteria
91 LOGGER.info("Score percent = %s", str(s_status))
92 s_four_score = str(four_score) + '/' + str(four_criteria)
93 s_ten_score = str(ten_score) + '/' + str(ten_criteria)
94 s_score_percent = str(s_status)
96 LOGGER.debug(" s_status: %s", s_status)
98 LOGGER.info(">>>>> scenario OK, save the information")
100 LOGGER.info(">>>> scenario not OK, last 4 iterations = %s, \
101 last 10 days = %s", (s_four_score, s_ten_score))
104 if len(s_result) > 0:
105 build_tag = s_result[len(s_result)-1]['build_tag']
106 LOGGER.debug("Build tag: %s", build_tag)
107 s_url = s_url = rp_utils.getJenkinsUrl(build_tag)
108 LOGGER.info("last jenkins url: %s", s_url)
110 # Save daily results in a file
111 path_validation_file = ("./display/" + version +
112 "/bottlenecks/scenario_history.txt")
114 if not os.path.exists(path_validation_file):
115 with open(path_validation_file, 'w') as f:
116 info = 'date,scenario,installer,details,score\n'
119 with open(path_validation_file, "a") as f:
120 info = (reportingDate + "," + s + "," + installer +
121 "," + s_ten_score + "," +
122 str(s_score_percent) + "\n")
125 scenario_result_criteria[s] = sr.ScenarioResult(s_status,
131 LOGGER.info("--------------------------")
133 templateLoader = jinja2.FileSystemLoader(".")
134 templateEnv = jinja2.Environment(loader=templateLoader,
137 TEMPLATE_FILE = ("./reporting/bottlenecks/template"
138 "/index-status-tmpl.html")
139 template = templateEnv.get_template(TEMPLATE_FILE)
141 outputText = template.render(scenario_results=scenario_result_criteria,
147 with open("./display/" + version +
148 "/bottlenecks/status-" + installer + ".html", "wb") as fh: