cloudify_ims reporting fixes
[releng.git] / utils / test / reporting / reporting / functest / reporting-vims.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 """
10 vIMS reporting status
11 """
12 from urllib2 import Request, urlopen, URLError
13 import json
14 import jinja2
15
16 import reporting.utils.reporting_utils as rp_utils
17
18 LOGGER = rp_utils.getLogger("vIMS")
19
20 PERIOD = rp_utils.get_config('general.period')
21 VERSIONS = rp_utils.get_config('general.versions')
22 URL_BASE = rp_utils.get_config('testapi.url')
23
24 LOGGER.info("****************************************")
25 LOGGER.info("*   Generating reporting vIMS          *")
26 LOGGER.info("*   Data retention = %s days           *", PERIOD)
27 LOGGER.info("*                                      *")
28 LOGGER.info("****************************************")
29
30 INSTALLERS = rp_utils.get_config('general.installers')
31 STEP_ORDER = ["initialisation", "orchestrator", "vnf", "test_vnf"]
32 LOGGER.info("Start vIMS reporting processing....")
33
34 # For all the versions
35 for version in VERSIONS:
36     for installer in INSTALLERS:
37
38         # get nb of supported architecture (x86, aarch64)
39         # get scenarios
40         scenario_results = rp_utils.getScenarios("functest",
41                                                  "cloudify_ims",
42                                                  installer,
43                                                  version)
44
45         architectures = rp_utils.getArchitectures(scenario_results)
46         LOGGER.info("Supported architectures: %s", architectures)
47
48         for architecture in architectures:
49             LOGGER.info("Architecture: %s", architecture)
50             # Consider only the results for the selected architecture
51             # i.e drop x86 for aarch64 and vice versa
52             filter_results = rp_utils.filterArchitecture(scenario_results,
53                                                          architecture)
54             scenario_stats = rp_utils.getScenarioStats(filter_results)
55             items = {}
56             scenario_result_criteria = {}
57
58             # in case of more than 1 architecture supported
59             # precise the architecture
60             installer_display = installer
61             if "fuel" in installer:
62                 installer_display = installer + "@" + architecture
63
64             LOGGER.info("Search vIMS results for installer: %s, version: %s",
65                         installer, version)
66             request = Request("http://" + URL_BASE + '?case=cloudify_ims&'
67                               'installer=' + installer + '&version=' + version)
68             try:
69                 response = urlopen(request)
70                 k = response.read()
71                 results = json.loads(k)
72             except URLError as err:
73                 LOGGER.error("Error code: %s", err)
74
75             test_results = results['results']
76
77             # LOGGER.debug("Results found: %s" % test_results)
78
79             scenario_results = {}
80             for r in test_results:
81                 if not r['scenario'] in scenario_results.keys():
82                     scenario_results[r['scenario']] = []
83                 scenario_results[r['scenario']].append(r)
84
85             # LOGGER.debug("scenario result: %s" % scenario_results)
86
87             for s, s_result in scenario_results.items():
88                 scenario_results[s] = s_result[0:5]
89                 for result in scenario_results[s]:
90                     try:
91                         format_result = result['details']['test_vnf']['result']
92
93                         # round durations of the different steps
94                         result['details']['orchestrator']['duration'] = round(
95                             result['details']['orchestrator']['duration'], 1)
96                         result['details']['vnf']['duration'] = round(
97                             result['details']['vnf']['duration'], 1)
98                         result['details']['test_vnf']['duration'] = round(
99                             result['details']['test_vnf']['duration'], 1)
100
101                         res_orch = \
102                             result['details']['orchestrator']['duration']
103                         res_vnf = result['details']['vnf']['duration']
104                         res_test_vnf = \
105                             result['details']['test_vnf']['duration']
106                         res_signaling = \
107                             result['details']['test_vnf']['result']['failures']
108
109                         # Manage test result status
110                         if res_signaling != 0:
111                             LOGGER.debug("At least 1 signalig test FAIL")
112                             result['details']['test_vnf']['status'] = "FAIL"
113                         else:
114                             LOGGER.debug("All signalig tests PASS")
115                             result['details']['test_vnf']['status'] = "PASS"
116
117                         LOGGER.debug("Scenario %s, Installer %s",
118                                      s_result[1]['scenario'], installer)
119                         LOGGER.debug("Orchestrator deployment: %ss", res_orch)
120                         LOGGER.debug("vIMS deployment: %ss", res_vnf)
121                         LOGGER.debug("VNF testing: %ss", res_test_vnf)
122                         LOGGER.debug("VNF testing results: %s", format_result)
123                     except Exception as err:  # pylint: disable=broad-except
124                         LOGGER.error("Uncomplete data %s", err)
125                     LOGGER.debug("----------------------------------------")
126
127         templateLoader = jinja2.FileSystemLoader(".")
128         templateEnv = jinja2.Environment(loader=templateLoader,
129                                          autoescape=True)
130
131         TEMPLATE_FILE = "./reporting/functest/template/index-vims-tmpl.html"
132         template = templateEnv.get_template(TEMPLATE_FILE)
133
134         outputText = template.render(scenario_results=scenario_results,
135                                      step_order=STEP_ORDER,
136                                      installer=installer_display)
137         LOGGER.debug("Generate html page for %s", installer_display)
138         with open("./display/" + version + "/functest/vims-" +
139                   installer_display + ".html", "wb") as fh:
140             fh.write(outputText)
141
142 LOGGER.info("vIMS report succesfully generated")