Stop disabling selinux
[releng.git] / utils / test / reporting / functest / reporting-vims.py
1 from urllib2 import Request, urlopen, URLError
2 import json
3 import jinja2
4 import reportingConf as conf
5 import reportingUtils as utils
6
7 logger = utils.getLogger("vIMS")
8
9
10 def sig_test_format(sig_test):
11     nbPassed = 0
12     nbFailures = 0
13     nbSkipped = 0
14     for data_test in sig_test:
15         if data_test['result'] == "Passed":
16             nbPassed += 1
17         elif data_test['result'] == "Failed":
18             nbFailures += 1
19         elif data_test['result'] == "Skipped":
20             nbSkipped += 1
21     total_sig_test_result = {}
22     total_sig_test_result['passed'] = nbPassed
23     total_sig_test_result['failures'] = nbFailures
24     total_sig_test_result['skipped'] = nbSkipped
25     return total_sig_test_result
26
27 logger.info("****************************************")
28 logger.info("*   Generating reporting vIMS          *")
29 logger.info("*   Data retention = %s days           *" % conf.PERIOD)
30 logger.info("*                                      *")
31 logger.info("****************************************")
32
33 installers = conf.installers
34 step_order = ["initialisation", "orchestrator", "vIMS", "sig_test"]
35 logger.info("Start processing....")
36
37 # For all the versions
38 for version in conf.versions:
39     for installer in installers:
40         logger.info("Search vIMS results for installer: %s, version: %s"
41                     % (installer, version))
42         request = Request(conf.URL_BASE + '?case=vims&installer=' +
43                           installer + '&version=' + version)
44
45         try:
46             response = urlopen(request)
47             k = response.read()
48             results = json.loads(k)
49         except URLError, e:
50             logger.error("Error code: %s" % e)
51
52         test_results = results['results']
53
54         logger.debug("Results found: %s" % test_results)
55
56         scenario_results = {}
57         for r in test_results:
58             if not r['scenario'] in scenario_results.keys():
59                 scenario_results[r['scenario']] = []
60             scenario_results[r['scenario']].append(r)
61
62         for s, s_result in scenario_results.items():
63             scenario_results[s] = s_result[0:5]
64             logger.debug("Search for success criteria")
65             for result in scenario_results[s]:
66                 result["start_date"] = result["start_date"].split(".")[0]
67                 sig_test = result['details']['sig_test']['result']
68                 if not sig_test == "" and isinstance(sig_test, list):
69                     format_result = sig_test_format(sig_test)
70                     if format_result['failures'] > format_result['passed']:
71                         result['details']['sig_test']['duration'] = 0
72                     result['details']['sig_test']['result'] = format_result
73                 nb_step_ok = 0
74                 nb_step = len(result['details'])
75
76                 for step_name, step_result in result['details'].items():
77                     if step_result['duration'] != 0:
78                         nb_step_ok += 1
79                     m, s = divmod(step_result['duration'], 60)
80                     m_display = ""
81                     if int(m) != 0:
82                         m_display += str(int(m)) + "m "
83
84                     step_result['duration_display'] = m_display + str(int(s)) + "s"
85
86                 result['pr_step_ok'] = 0
87                 if nb_step != 0:
88                     result['pr_step_ok'] = (float(nb_step_ok)/nb_step)*100
89                 try:
90                     logger.debug("Scenario %s, Installer %s"
91                                  % (s_result[1]['scenario'], installer))
92                     logger.debug("Orchestrator deployment: %s s"
93                                  % result['details']['orchestrator']['duration'])
94                     logger.debug("vIMS deployment: %s s"
95                                  % result['details']['vIMS']['duration'])
96                     logger.debug("Signaling testing: %s s"
97                                  % result['details']['sig_test']['duration'])
98                     logger.debug("Signaling testing results: %s"
99                                  % format_result)
100                 except:
101                     logger.error("Data badly formatted")
102                 logger.debug("----------------------------------------")
103
104         templateLoader = jinja2.FileSystemLoader(conf.REPORTING_PATH)
105         templateEnv = jinja2.Environment(loader=templateLoader)
106
107         TEMPLATE_FILE = "/template/index-vims-tmpl.html"
108         template = templateEnv.get_template(TEMPLATE_FILE)
109
110         outputText = template.render(scenario_results=scenario_results,
111                                      step_order=step_order,
112                                      installer=installer)
113
114         with open(conf.REPORTING_PATH +
115                   "/release/" + version + "/index-vims-" +
116                   installer + ".html", "wb") as fh:
117             fh.write(outputText)
118
119 logger.info("vIMS report succesfully generated")