Merge "Add functest-healthcheck alpine to xci-verify-healthcheck-macro"
[releng.git] / utils / test / reporting / reporting / vsperf / reporting-status.py
1 #!/usr/bin/python
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 import datetime
10 import os
11
12 import jinja2
13
14 import reporting.utils.reporting_utils as rp_utils
15 import reporting.utils.scenarioResult as sr
16
17 installers = rp_utils.get_config('general.installers')
18 PERIOD = rp_utils.get_config('general.period')
19
20 # Logger
21 logger = rp_utils.getLogger("Storperf-Status")
22 reportingDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
23
24 logger.info("*******************************************")
25 logger.info("*   Generating reporting scenario status  *")
26 logger.info("*   Data retention = %s days              *" % PERIOD)
27 logger.info("*                                         *")
28 logger.info("*******************************************")
29
30 # retrieve the list of storperf tests
31 versions = {'master'}
32
33 # For all the versions
34 for version in versions:
35     # For all the installers
36     for installer in installers:
37         scenario_results = rp_utils.getScenarios("vsperf",
38                                                  None,
39                                                  installer,
40                                                  None)
41         items = {}
42         scenario_result_criteria = {}
43         logger.info("installer %s, version %s, scenario ", installer, version)
44
45         # From each scenarios get results list
46         for s, s_result in scenario_results.items():
47             logger.info("---------------------------------")
48             logger.info("installer %s, version %s, scenario %s", installer,
49                         version, s)
50             ten_criteria = len(s_result)
51
52             ten_score = 0
53             for v in s_result:
54                 if "PASS" in v['criteria']:
55                     ten_score += 1
56
57             logger.info("ten_score: %s / %s" % (ten_score, ten_criteria))
58
59             four_score = 0
60             try:
61                 LASTEST_TESTS = rp_utils.get_config(
62                     'general.nb_iteration_tests_success_criteria')
63                 s_result.sort(key=lambda x: x['start_date'])
64                 four_result = s_result[-LASTEST_TESTS:]
65                 logger.debug("four_result: {}".format(four_result))
66                 logger.debug("LASTEST_TESTS: {}".format(LASTEST_TESTS))
67                 # logger.debug("four_result: {}".format(four_result))
68                 four_criteria = len(four_result)
69                 for v in four_result:
70                     if "PASS" in v['criteria']:
71                         four_score += 1
72                 logger.info("4 Score: %s / %s " % (four_score,
73                                                    four_criteria))
74             except Exception:
75                 logger.error("Impossible to retrieve the four_score")
76
77             try:
78                 s_status = (four_score * 100) / four_criteria
79             except ZeroDivisionError:
80                 s_status = 0
81             logger.info("Score percent = %s" % str(s_status))
82             s_four_score = str(four_score) + '/' + str(four_criteria)
83             s_ten_score = str(ten_score) + '/' + str(ten_criteria)
84             s_score_percent = str(s_status)
85
86             logger.debug(" s_status: {}".format(s_status))
87             if s_status == 100:
88                 logger.info(">>>>> scenario OK, save the information")
89             else:
90                 logger.info(">>>> scenario not OK, last 4 iterations = %s, \
91                              last 10 days = %s" % (s_four_score, s_ten_score))
92
93             s_url = ""
94             if len(s_result) > 0:
95                 build_tag = s_result[len(s_result)-1]['build_tag']
96                 logger.debug("Build tag: %s" % build_tag)
97                 s_url = s_url = rp_utils.getJenkinsUrl(build_tag)
98                 logger.info("last jenkins url: %s" % s_url)
99
100             # Save daily results in a file
101             path_validation_file = ("./display/" + version +
102                                     "/vsperf/scenario_history.txt")
103
104             if not os.path.exists(path_validation_file):
105                 with open(path_validation_file, 'w') as f:
106                     info = 'date,scenario,installer,details,score\n'
107                     f.write(info)
108
109             with open(path_validation_file, "a") as f:
110                 info = (reportingDate + "," + s + "," + installer +
111                         "," + s_ten_score + "," +
112                         str(s_score_percent) + "\n")
113                 f.write(info)
114
115             scenario_result_criteria[s] = sr.ScenarioResult(s_status,
116                                                             s_four_score,
117                                                             s_ten_score,
118                                                             s_score_percent,
119                                                             s_url)
120
121             logger.info("--------------------------")
122
123         templateLoader = jinja2.FileSystemLoader(".")
124         templateEnv = jinja2.Environment(loader=templateLoader,
125                                          autoescape=True)
126
127         TEMPLATE_FILE = "./reporting/vsperf/template/index-status-tmpl.html"
128         template = templateEnv.get_template(TEMPLATE_FILE)
129
130         outputText = template.render(scenario_results=scenario_result_criteria,
131                                      installer=installer,
132                                      period=PERIOD,
133                                      version=version,
134                                      date=reportingDate)
135
136         with open("./display/" + version +
137                   "/vsperf/status-" + installer + ".html", "wb") as fh:
138             fh.write(outputText)