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
7 # http://www.apache.org/licenses/LICENSE-2.0
14 from reporting.utils.scenarioResult import ScenarioResult
15 from reporting.utils import reporting_utils as utils
16 from scenarios import config as blacklist
20 LOG = utils.getLogger("Yardstick-Status")
23 def get_scenario_data(version, installer):
24 scenarios = utils.getScenarioStatus(installer, version)
26 if 'colorado' == version:
27 data = utils.getScenarioStatus(installer, 'stable/colorado')
28 for archi, value in data.items():
29 for k, v in value.items():
30 if k not in scenarios[archi]:
31 scenarios[archi][k] = []
32 scenarios[archi][k].extend(data[archi][k])
34 for archi, value in scenarios.items():
35 for scenario in value:
36 if installer in blacklist and scenario in blacklist[installer]:
37 scenarios[archi].pop(scenario)
42 def write_history_data(version, scenario, installer, ten_score, percent):
43 # Save daily results in a file
44 history_file = './display/{}/yardstick/scenario_history.txt'.format(
47 if not os.path.exists(history_file):
48 with open(history_file, 'w') as f:
49 f.write('date,scenario,installer,details,score\n')
51 date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
52 with open(history_file, "a") as f:
53 info = '{},{},{},{},{}\n'.format(date,
61 def generate_page(scenario_data, installer, period, version, architecture):
62 date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
64 templateLoader = jinja2.FileSystemLoader(".")
65 template_env = jinja2.Environment(loader=templateLoader,
68 template_file = "./reporting/yardstick/template/index-status-tmpl.html"
69 template = template_env.get_template(template_file)
71 if installer == 'fuel':
72 installer = '{}@{}'.format(installer, architecture)
74 output_text = template.render(scenario_results=scenario_data,
80 page_file = './display/{}/yardstick/status-{}.html'.format(version,
82 with open(page_file, 'wb') as f:
86 def do_statistic(data):
91 last_count = utils.get_config(
92 'general.nb_iteration_tests_success_criteria')
93 last_data = data[:last_count]
98 percent = utils.get_percent(last_data, data)
100 last_score = '{}/{}'.format(last_score, len(last_data))
101 ten_score = '{}/{}'.format(ten_score, len(data))
104 LOG.info(">>>>> scenario OK, save the information")
106 LOG.info(">>>> scenario not OK, last 4 iterations = %s, \
107 last 10 days = %s" % (last_score, ten_score))
109 return last_score, ten_score, percent, status
112 def generate_reporting_page(version, installer, archi, scenarios, period):
115 # From each scenarios get results list
116 for scenario, data in scenarios.items():
117 LOG.info("---------------------------------")
119 LOG.info("installer %s, version %s, scenario %s",
123 last_score, ten_score, percent, status = do_statistic(data)
124 write_history_data(version, scenario, installer, ten_score, percent)
125 scenario_data[scenario] = ScenarioResult(status,
130 LOG.info("--------------------------")
132 generate_page(scenario_data, installer, period, version, archi)
136 installers = utils.get_config('general.installers')
137 versions = utils.get_config('general.versions')
138 period = utils.get_config('general.period')
140 LOG.info("*******************************************")
141 LOG.info("* Generating reporting scenario status *")
142 LOG.info("* Data retention = %s days *" % period)
144 LOG.info("*******************************************")
146 # For all the versions
147 for version in versions:
148 # For all the installers
149 for installer in installers:
150 # get scenarios results data
151 scenarios = get_scenario_data(version, installer)
152 for k, v in scenarios.items():
153 generate_reporting_page(version, installer, k, v, period)
156 if __name__ == '__main__':