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
12 from urllib2 import Request, urlopen, URLError
16 import reporting.utils.reporting_utils as rp_utils
18 LOGGER = rp_utils.getLogger("vIMS")
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')
24 LOGGER.info("****************************************")
25 LOGGER.info("* Generating reporting vIMS *")
26 LOGGER.info("* Data retention = %s days *", PERIOD)
28 LOGGER.info("****************************************")
30 INSTALLERS = rp_utils.get_config('general.installers')
31 STEP_ORDER = ["initialisation", "orchestrator", "vnf", "test_vnf"]
32 LOGGER.info("Start vIMS reporting processing....")
34 # For all the versions
35 for version in VERSIONS:
36 for installer in INSTALLERS:
38 # get nb of supported architecture (x86, aarch64)
40 scenario_results = rp_utils.getScenarios("functest",
45 architectures = rp_utils.getArchitectures(scenario_results)
46 LOGGER.info("Supported architectures: %s", architectures)
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,
54 scenario_stats = rp_utils.getScenarioStats(filter_results)
56 scenario_result_criteria = {}
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
64 LOGGER.info("Search vIMS results for installer: %s, version: %s",
66 request = Request("http://" + URL_BASE + '?case=cloudify_ims&'
67 'installer=' + installer + '&version=' + version)
69 response = urlopen(request)
71 results = json.loads(k)
72 except URLError as err:
73 LOGGER.error("Error code: %s", err)
75 test_results = results['results']
77 # LOGGER.debug("Results found: %s" % test_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)
85 # LOGGER.debug("scenario result: %s" % scenario_results)
87 for s, s_result in scenario_results.items():
88 scenario_results[s] = s_result[0:5]
89 for result in scenario_results[s]:
91 format_result = result['details']['test_vnf']['result']
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)
102 result['details']['orchestrator']['duration']
103 res_vnf = result['details']['vnf']['duration']
105 result['details']['test_vnf']['duration']
107 result['details']['test_vnf']['result']['failures']
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"
114 LOGGER.debug("All signalig tests PASS")
115 result['details']['test_vnf']['status'] = "PASS"
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("----------------------------------------")
127 templateLoader = jinja2.FileSystemLoader(".")
128 templateEnv = jinja2.Environment(loader=templateLoader,
131 TEMPLATE_FILE = "./reporting/functest/template/index-vims-tmpl.html"
132 template = templateEnv.get_template(TEMPLATE_FILE)
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:
142 LOGGER.info("vIMS report succesfully generated")