12f42ca317c444c19ff89f102d1164a835dd6dd3
[releng.git] / utils / test / reporting / yardstick / 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 import utils.scenarioResult as sr
14 from scenarios import config as cf
15
16 # manage conf
17 import utils.reporting_utils as rp_utils
18
19 installers = rp_utils.get_config('general.installers')
20 versions = rp_utils.get_config('general.versions')
21 PERIOD = rp_utils.get_config('general.period')
22
23 # Logger
24 logger = rp_utils.getLogger("Yardstick-Status")
25 reportingDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
26
27 logger.info("*******************************************")
28 logger.info("*   Generating reporting scenario status  *")
29 logger.info("*   Data retention = %s days              *" % PERIOD)
30 logger.info("*                                         *")
31 logger.info("*******************************************")
32
33
34 # For all the versions
35 for version in versions:
36     # For all the installers
37     for installer in installers:
38         # get scenarios results data
39         scenario_results = rp_utils.getScenarioStatus(installer, version)
40         if 'colorado' == version:
41             stable_result = rp_utils.getScenarioStatus(installer,
42                                                        'stable/colorado')
43             for k, v in stable_result.items():
44                 if k not in scenario_results.keys():
45                     scenario_results[k] = []
46                 scenario_results[k] += stable_result[k]
47         scenario_result_criteria = {}
48
49         for s in scenario_results.keys():
50             if installer in cf.keys() and s in cf[installer].keys():
51                 scenario_results.pop(s)
52
53         # From each scenarios get results list
54         for s, s_result in scenario_results.items():
55             logger.info("---------------------------------")
56             logger.info("installer %s, version %s, scenario %s", installer,
57                         version, s)
58
59             ten_criteria = len(s_result)
60             ten_score = 0
61             for v in s_result:
62                 ten_score += v
63
64             LASTEST_TESTS = rp_utils.get_config(
65                 'general.nb_iteration_tests_success_criteria')
66             four_result = s_result[:LASTEST_TESTS]
67             four_criteria = len(four_result)
68             four_score = 0
69             for v in four_result:
70                 four_score += v
71
72             s_status = str(rp_utils.get_percent(four_result, s_result))
73             s_four_score = str(four_score) + '/' + str(four_criteria)
74             s_ten_score = str(ten_score) + '/' + str(ten_criteria)
75             s_score_percent = rp_utils.get_percent(four_result, s_result)
76
77             if '100' == s_status:
78                 logger.info(">>>>> scenario OK, save the information")
79             else:
80                 logger.info(">>>> scenario not OK, last 4 iterations = %s, \
81                             last 10 days = %s" % (s_four_score, s_ten_score))
82
83             # Save daily results in a file
84             path_validation_file = ("./display/" + version +
85                                     "/yardstick/scenario_history.txt")
86
87             if not os.path.exists(path_validation_file):
88                 with open(path_validation_file, 'w') as f:
89                     info = 'date,scenario,installer,details,score\n'
90                     f.write(info)
91
92             with open(path_validation_file, "a") as f:
93                 info = (reportingDate + "," + s + "," + installer +
94                         "," + s_ten_score + "," +
95                         str(s_score_percent) + "\n")
96                 f.write(info)
97
98             scenario_result_criteria[s] = sr.ScenarioResult(s_status,
99                                                             s_four_score,
100                                                             s_ten_score,
101                                                             s_score_percent)
102
103             logger.info("--------------------------")
104
105         templateLoader = jinja2.FileSystemLoader(".")
106         templateEnv = jinja2.Environment(loader=templateLoader,
107                                          autoescape=True)
108
109         TEMPLATE_FILE = "./yardstick/template/index-status-tmpl.html"
110         template = templateEnv.get_template(TEMPLATE_FILE)
111
112         outputText = template.render(scenario_results=scenario_result_criteria,
113                                      installer=installer,
114                                      period=PERIOD,
115                                      version=version,
116                                      date=reportingDate)
117
118         with open("./display/" + version +
119                   "/yardstick/status-" + installer + ".html", "wb") as fh:
120             fh.write(outputText)