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