3 # Copyright (c) 2017 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 # SPDX-license-identifier: Apache-2.0
11 from urllib2 import Request, urlopen, URLError
12 from datetime import datetime
18 import utils.reporting_utils as rp_utils
20 installers = rp_utils.get_config('general.installers')
21 items = ["tests", "Success rate", "duration"]
23 CURRENT_DIR = os.getcwd()
25 PERIOD = rp_utils.get_config('general.period')
26 criteria_nb_test = 165
27 criteria_duration = 1800
28 criteria_success_rate = 90
30 logger = rp_utils.getLogger("Tempest")
31 logger.info("************************************************")
32 logger.info("* Generating reporting Tempest_smoke_serial *")
33 logger.info("* Data retention = %s days *" % PERIOD)
35 logger.info("************************************************")
37 logger.info("Success criteria:")
38 logger.info("nb tests executed > %s s " % criteria_nb_test)
39 logger.info("test duration < %s s " % criteria_duration)
40 logger.info("success rate > %s " % criteria_success_rate)
42 # For all the versions
43 for version in rp_utils.get_config('general.versions'):
44 for installer in installers:
45 # we consider the Tempest results of the last PERIOD days
46 url = ("http://" + rp_utils.get_config('testapi.url') +
47 "?case=tempest_smoke_serial")
48 request = Request(url + '&period=' + str(PERIOD) +
49 '&installer=' + installer +
50 '&version=' + version)
51 logger.info("Search tempest_smoke_serial results for installer %s"
53 % (installer, version))
55 response = urlopen(request)
57 results = json.loads(k)
59 logger.error("Error code: %s" % e)
61 test_results = results['results']
67 for r in test_results:
68 # Retrieve all the scenarios per installer
69 # In Brahmaputra use version
70 # Since Colorado use scenario
71 if not r['scenario'] in scenario_results.keys():
72 scenario_results[r['scenario']] = []
73 scenario_results[r['scenario']].append(r)
75 for s, s_result in scenario_results.items():
76 scenario_results[s] = s_result[0:5]
77 # For each scenario, we build a result object to deal with
78 # results, criteria and error handling
79 for result in scenario_results[s]:
80 result["start_date"] = result["start_date"].split(".")[0]
84 nb_tests_run = result['details']['tests']
85 nb_tests_failed = result['details']['failures']
87 success_rate = 100 * ((int(nb_tests_run) -
88 int(nb_tests_failed)) /
93 result['details']["tests"] = nb_tests_run
94 result['details']["Success rate"] = str(success_rate) + "%"
102 # Expect that at least 165 tests are run
103 if nb_tests_run >= criteria_nb_test:
106 # Expect that at least 90% of success
107 if success_rate >= criteria_success_rate:
110 # Expect that the suite duration is inferior to 30m
111 stop_date = datetime.strptime(result['stop_date'],
113 start_date = datetime.strptime(result['start_date'],
116 delta = stop_date - start_date
117 if (delta.total_seconds() < criteria_duration):
120 result['criteria'] = {'tests': crit_tests,
121 'Success rate': crit_rate,
122 'duration': crit_time}
124 logger.debug("Scenario %s, Installer %s"
125 % (s_result[1]['scenario'], installer))
126 logger.debug("Nb Test run: %s" % nb_tests_run)
127 logger.debug("Test duration: %s"
128 % result['details']['duration'])
129 logger.debug("Success rate: %s" % success_rate)
131 logger.error("Data format error")
136 errors = result['details']['errors']
137 result['errors'] = errors.replace('{0}', '')
139 logger.error("Error field not present (Brahamputra runs?)")
141 templateLoader = jinja2.FileSystemLoader(".")
142 templateEnv = jinja2.Environment(loader=templateLoader,
145 TEMPLATE_FILE = "./reporting/functest/template/index-tempest-tmpl.html"
146 template = templateEnv.get_template(TEMPLATE_FILE)
148 outputText = template.render(scenario_results=scenario_results,
152 with open("./display/" + version +
153 "/functest/tempest-" + installer + ".html", "wb") as fh:
155 logger.info("Tempest automatic reporting succesfully generated.")