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