c1d11611261f74eef656b1b07b5df461b0cc16db
[releng.git] / utils / test / result_collection_api / dashboard / functest2Dashboard.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2015 Orange
4 # morgan.richomme@orange.com
5 #
6 # This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # This script is used to build dashboard ready json results
13 # It may be used for all the test case of the Functest project
14 # a new method format_<Test_case>_for_dashboard(results)
15 # v0.1: basic example with methods for odl, Tempest, Rally and vPing
16 #
17
18 def get_functest_cases():
19     """
20     get the list of the supported test cases
21     TODO: update the list when adding a new test case for the dashboard
22     """
23     return ["status", "vPing", "vPing_userdata", "vIMS", "Tempest", "odl", "Rally"]
24
25
26 def format_functest_for_dashboard(case, results):
27     """
28     generic method calling the method corresponding to the test case
29     check that the testcase is properly declared first
30     then build the call to the specific method
31     """
32     if check_functest_case_exist(case):
33         cmd = "format_" + case + "_for_dashboard(results)"
34         res = eval(cmd)
35     else:
36         res = []
37         print "Test cases not declared"
38     return res
39
40
41 def check_functest_case_exist(case):
42     """
43     check if the testcase exists
44     if the test case is not defined or not declared in the list
45     return False
46     """
47     functest_cases = get_functest_cases()
48
49     if (case is None or case not in functest_cases):
50         return False
51     else:
52         return True
53
54
55 def format_status_for_dashboard(results):
56     test_data = [{'description': 'Functest status'}]
57
58     # define magic equation for the status....
59     # 5 suites: vPing, odl, Tempest, vIMS, Rally
60     # Which overall KPI make sense...
61
62     # TODO to be done and discussed
63     testcases = get_functest_cases()
64     test_data.append({'nb test suite(s) run': len(testcases)-1})
65     test_data.append({'vPing': '100%'})
66     test_data.append({'VIM status': '82%'})
67     test_data.append({'SDN Controllers': {'odl':'92%', 'onos':'95%', 'opencontrail':'93%'}})
68     test_data.append({'VNF deployment': '95%'})
69
70     return test_data
71
72
73 def format_vIMS_for_dashboard(results):
74     """
75     Post processing for the vIMS test case
76     """
77     test_data = [{'description': 'vIMS results for Dashboard'}]
78
79     # Graph 1: (duration_deployment_orchestrator,
80     #            duration_deployment_vnf,
81     #             duration_test) = f(time)
82     # ********************************
83     new_element = []
84
85     for data in results:
86         new_element.append({'x': data['creation_date'],
87                             'y1': data['details']['orchestrator']['duration'],
88                             'y2': data['details']['vIMS']['duration'],
89                             'y3': data['details']['sig_test']['duration']})
90
91     test_data.append({'name': "vIMS orchestrator/VNF/test duration",
92                       'info': {'type': "graph",
93                                'xlabel': 'time',
94                                'y1label': 'orchestation deployment duration',
95                                'y2label': 'vIMS deployment duration',
96                                'y3label': 'vIMS test duration'},
97                       'data_set': new_element})
98
99     # Graph 2: (Nb test, nb failure, nb skipped)=f(time)
100     # **************************************************
101     new_element = []
102
103     for data in results:
104         # Retrieve all the tests
105         nbTests = 0
106         nbFailures = 0
107         nbSkipped = 0
108         vIMS_test = data['details']['sig_test']['result']
109
110         for data_test in vIMS_test:
111             # Calculate nb of tests run and nb of tests failed
112             # vIMS_results = get_vIMSresults(vIMS_test)
113             # print vIMS_results
114             if data_test['result'] == "Passed":
115                 nbTests += 1
116             elif data_test['result'] == "Failed":
117                 nbFailures += 1
118             elif data_test['result'] == "Skipped":
119                 nbSkipped += 1
120
121         new_element.append({'x': data['creation_date'],
122                             'y1': nbTests,
123                             'y2': nbFailures,
124                             'y3': nbSkipped})
125
126     test_data.append({'name': "vIMS nb tests passed/failed/skipped",
127                       'info': {'type': "graph",
128                                'xlabel': 'time',
129                                'y1label': 'Number of tests passed',
130                                'y2label': 'Number of tests failed',
131                                'y3label': 'Number of tests skipped'},
132                       'data_set': new_element})
133
134     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
135     # ********************************************************
136     nbTests = 0
137     nbFailures = 0
138
139     for data in results:
140         vIMS_test = data['details']['sig_test']['result']
141
142         for data_test in vIMS_test:
143             nbTestsOK = 0
144             nbTestsKO = 0
145
146             if data_test['result'] == "Passed":
147                 nbTestsOK += 1
148             elif data_test['result'] == "Failed":
149                 nbTestsKO += 1
150
151             nbTests += nbTestsOK + nbTestsKO
152             nbFailures += nbTestsKO
153
154     test_data.append({'name': "Total number of tests run/failure tests",
155                       'info': {"type": "bar"},
156                       'data_set': [{'Run': nbTests,
157                                     'Failed': nbFailures}]})
158
159     return test_data
160
161
162 def format_Tempest_for_dashboard(results):
163     """
164     Post processing for the Tempest test case
165     """
166     test_data = [{'description': 'Tempest results for Dashboard'}]
167
168     # Graph 1: Test_Duration = f(time)
169     # ********************************
170     new_element = []
171     for data in results:
172         new_element.append({'x': data['creation_date'],
173                             'y': data['details']['duration']})
174
175     test_data.append({'name': "Tempest duration",
176                       'info': {'type': "graph",
177                                'xlabel': 'time',
178                                'ylabel': 'duration (s)'},
179                       'data_set': new_element})
180
181     # Graph 2: (Nb test, nb failure)=f(time)
182     # ***************************************
183     new_element = []
184     for data in results:
185         new_element.append({'x': data['creation_date'],
186                             'y1': data['details']['tests'],
187                             'y2': data['details']['failures']})
188
189     test_data.append({'name': "Tempest nb tests/nb failures",
190                       'info': {'type': "graph",
191                                'xlabel': 'time',
192                                'y1label': 'Number of tests',
193                                'y2label': 'Number of failures'},
194                       'data_set': new_element})
195
196     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
197     # ********************************************************
198     nbTests = 0
199     nbFailures = 0
200
201     for data in results:
202         nbTests += data['details']['tests']
203         nbFailures += data['details']['failures']
204
205     test_data.append({'name': "Total number of tests run/failure tests",
206                       'info': {"type": "bar"},
207                       'data_set': [{'Run': nbTests,
208                                     'Failed': nbFailures}]})
209
210     return test_data
211
212
213 def format_odl_for_dashboard(results):
214     """
215     Post processing for the odl test case
216     """
217     test_data = [{'description': 'odl results for Dashboard'}]
218     return test_data
219
220
221 def format_Rally_for_dashboard(results):
222     """
223     Post processing for the Rally test case
224     """
225     test_data = [{'description': 'Rally results for Dashboard'}]
226     return test_data
227
228
229 def format_vPing_for_dashboard(results):
230     """
231     Post processing for the vPing test case
232     """
233     test_data = [{'description': 'vPing results for Dashboard'}]
234
235     # Graph 1: Test_Duration = f(time)
236     # ********************************
237     new_element = []
238     for data in results:
239         new_element.append({'x': data['creation_date'],
240                             'y': data['details']['duration']})
241
242     test_data.append({'name': "vPing duration",
243                       'info': {'type': "graph",
244                                'xlabel': 'time',
245                                'ylabel': 'duration (s)'},
246                       'data_set': new_element})
247
248     # Graph 2: bar
249     # ************
250     nbTest = 0
251     nbTestOk = 0
252
253     for data in results:
254         nbTest += 1
255         if data['details']['status'] == "OK":
256             nbTestOk += 1
257
258     test_data.append({'name': "vPing status",
259                       'info': {"type": "bar"},
260                       'data_set': [{'Nb tests': nbTest,
261                                     'Nb Success': nbTestOk}]})
262
263     return test_data
264
265 def format_vPing_userdata_for_dashboard(results):
266     """
267     Post processing for the vPing_userdata test case
268     """
269     test_data = [{'description': 'vPing_userdata results for Dashboard'}]
270
271     # Graph 1: Test_Duration = f(time)
272     # ********************************
273     new_element = []
274     for data in results:
275         new_element.append({'x': data['creation_date'],
276                             'y': data['details']['duration']})
277
278     test_data.append({'name': "vPing_userdata duration",
279                       'info': {'type': "graph",
280                                'xlabel': 'time',
281                                'ylabel': 'duration (s)'},
282                       'data_set': new_element})
283
284     # Graph 2: bar
285     # ************
286     nbTest = 0
287     nbTestOk = 0
288
289     for data in results:
290         nbTest += 1
291         if data['details']['status'] == "OK":
292             nbTestOk += 1
293
294     test_data.append({'name': "vPing_userdata status",
295                       'info': {"type": "bar"},
296                       'data_set': [{'Nb tests': nbTest,
297                                     'Nb Success': nbTestOk}]})
298
299     return test_data