Make a black list for yardstick reporting
[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 requests
12 import sys
13 import time
14 import yaml
15
16 import reportingUtils as utils
17 import reportingConf as conf
18 import scenarioResult as sr
19 from scenarios import config as cf
20
21 # Logger
22 logger = utils.getLogger("Yardstick-Status")
23
24 logger.info("*******************************************")
25 logger.info("*   Generating reporting scenario status  *")
26 logger.info("*   Data retention = %s days              *" % conf.PERIOD)
27 logger.info("*                                         *")
28 logger.info("*******************************************")
29
30
31 # For all the versions
32 for version in conf.versions:
33     # For all the installers
34     for installer in conf.installers:
35         # get scenarios results data
36         scenario_results = utils.getScenarioStatus(installer, version)
37         if 'colorado' == version:
38             stable_result = utils.getScenarioStatus(installer, 'stable/colorado')
39             for k,v in stable_result.items():
40                 if not scenario_results.has_key(k):
41                     scenario_results[k] = []
42                 scenario_results[k] += stable_result[k]
43         scenario_result_criteria = {}
44
45         for s in scenario_results.keys():
46             if cf.has_key(installer) and cf[installer].has_key(s):
47                 scenario_results.pop(s)
48
49         # From each scenarios get results list
50         for s, s_result in scenario_results.items():
51             logger.info("---------------------------------")
52             logger.info("installer %s, version %s, scenario %s:" % (installer, version, s))
53
54             ten_criteria = len(s_result)
55             ten_score = 0
56             for v in s_result:
57                 ten_score += v
58
59             four_result = s_result[:conf.LASTEST_TESTS]
60             four_criteria = len(four_result)
61             four_score = 0
62             for v in four_result:
63                 four_score += v
64
65             s_status = str(utils.get_status(four_result, s_result))
66             s_four_score = str(four_score) + '/' + str(four_criteria)
67             s_ten_score = str(ten_score) + '/' + str(ten_criteria)
68             scenario_result_criteria[s] = sr.ScenarioResult(s_status, s_four_score, s_ten_score)
69
70             if '100' == s_status:
71                 logger.info(">>>>> scenario OK, save the information")
72             else:
73                 logger.info(">>>> scenario not OK, last 4 iterations = %s, last 10 days = %s" % (s_four_score, s_ten_score))
74             logger.info("--------------------------")
75
76         templateLoader = jinja2.FileSystemLoader(conf.REPORTING_PATH)
77         templateEnv = jinja2.Environment(loader=templateLoader, autoescape=True)
78
79         TEMPLATE_FILE = "/template/index-status-tmpl.html"
80         template = templateEnv.get_template(TEMPLATE_FILE)
81
82         outputText = template.render(scenario_results=scenario_result_criteria,
83                                      installer=installer,
84                                      period=conf.PERIOD,
85                                      version=version)
86
87         with open(conf.REPORTING_PATH + "/release/" + version +
88                   "/index-status-" + installer + ".html", "wb") as fh:
89             fh.write(outputText)