1 from urllib2 import Request, urlopen, URLError
4 import reportingConf as conf
5 import reportingUtils as utils
7 logger = utils.getLogger("vIMS")
10 def sig_test_format(sig_test):
14 for data_test in sig_test:
15 if data_test['result'] == "Passed":
17 elif data_test['result'] == "Failed":
19 elif data_test['result'] == "Skipped":
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
27 logger.info("****************************************")
28 logger.info("* Generating reporting vIMS *")
29 logger.info("* Data retention = %s days *" % conf.PERIOD)
31 logger.info("****************************************")
33 installers = conf.installers
34 step_order = ["initialisation", "orchestrator", "vIMS", "sig_test"]
35 logger.info("Start processing....")
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)
46 response = urlopen(request)
48 results = json.loads(k)
50 logger.error("Error code: %s" % e)
52 test_results = results['results']
54 logger.debug("Results found: %s" % test_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)
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
74 nb_step = len(result['details'])
76 for step_name, step_result in result['details'].items():
77 if step_result['duration'] != 0:
79 m, s = divmod(step_result['duration'], 60)
82 m_display += str(int(m)) + "m "
84 step_result['duration_display'] = m_display + str(int(s)) + "s"
86 result['pr_step_ok'] = 0
88 result['pr_step_ok'] = (float(nb_step_ok)/nb_step)*100
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"
101 logger.error("Data badly formatted")
102 logger.debug("----------------------------------------")
104 templateLoader = jinja2.FileSystemLoader(conf.REPORTING_PATH)
105 templateEnv = jinja2.Environment(loader=templateLoader)
107 TEMPLATE_FILE = "/template/index-vims-tmpl.html"
108 template = templateEnv.get_template(TEMPLATE_FILE)
110 outputText = template.render(scenario_results=scenario_results,
111 step_order=step_order,
114 with open(conf.REPORTING_PATH +
115 "/release/" + version + "/index-vims-" +
116 installer + ".html", "wb") as fh:
119 logger.info("vIMS report succesfully generated")