ed5dab044d02fcebb81c45b94373e53851468724
[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
20 # Logger
21 logger = utils.getLogger("Yardstick-Status")
22
23 logger.info("*******************************************")
24 logger.info("*   Generating reporting scenario status  *")
25 logger.info("*   Data retention = %s days              *" % conf.PERIOD)
26 logger.info("*                                         *")
27 logger.info("*******************************************")
28
29 # For all the versions
30 for version in conf.versions:
31     # For all the installers
32     for installer in conf.installers:
33         # get scenarios results data
34         scenario_results = utils.getScenarioStatus(installer, version)
35         scenario_result_criteria = {}
36
37         # From each scenarios get results list
38         for s, s_result in scenario_results.items():
39             logger.info("---------------------------------")
40             logger.info("installer %s, version %s, scenario %s:" % (installer, version, s))
41
42             s_status = 'KO'
43             scenario_criteria = len(s_result)
44             scenario_score = 0
45
46             for v in s_result:
47                 if v['details'] == 'SUCCESS':
48                     scenario_score += 1
49
50             if scenario_score == scenario_criteria:
51                 s_status = 'OK'
52                 logger.info(">>>>> scenario OK, save the information")
53             else:
54                 logger.info(">>>> scenario not OK, score = %s/%s" % (scenario_score, scenario_criteria))
55
56             s_score = str(scenario_score) + '/' + str(scenario_criteria)
57             scenario_result_criteria[s] = sr.ScenarioResult(s_status, s_score)
58
59             logger.info("--------------------------")
60
61         templateLoader = jinja2.FileSystemLoader(conf.REPORTING_PATH)
62         templateEnv = jinja2.Environment(loader=templateLoader)
63
64         TEMPLATE_FILE = "/template/index-status-tmpl.html"
65         template = templateEnv.get_template(TEMPLATE_FILE)
66
67         outputText = template.render(scenario_results=scenario_result_criteria,
68                                      installer=installer,
69                                      period=conf.PERIOD,
70                                      version=version)
71
72         with open(conf.REPORTING_PATH + "/release/" + version +
73                   "/index-status-" + installer + ".html", "wb") as fh:
74             fh.write(outputText)