Add ONOS and ODL in dashboard
[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 import re
18 import datetime
19
20 def get_functest_cases():
21     """
22     get the list of the supported test cases
23     TODO: update the list when adding a new test case for the dashboard
24     """
25     return ["status", "vPing", "vPing_userdata", "vIMS", "Tempest", "ODL", "ONOS", "Rally"]
26
27
28 def format_functest_for_dashboard(case, results):
29     """
30     generic method calling the method corresponding to the test case
31     check that the testcase is properly declared first
32     then build the call to the specific method
33     """
34     if check_functest_case_exist(case):
35         cmd = "format_" + case + "_for_dashboard(results)"
36         res = eval(cmd)
37     else:
38         res = []
39         print "Test cases not declared"
40     return res
41
42
43 def check_functest_case_exist(case):
44     """
45     check if the testcase exists
46     if the test case is not defined or not declared in the list
47     return False
48     """
49     functest_cases = get_functest_cases()
50
51     if (case is None or case not in functest_cases):
52         return False
53     else:
54         return True
55
56
57 def format_status_for_dashboard(results):
58     test_data = [{'description': 'Functest status'}]
59
60     # define magic equation for the status....
61     # 5 suites: vPing, odl, Tempest, vIMS, Rally
62     # Which overall KPI make sense...
63
64     # TODO to be done and discussed
65     testcases = get_functest_cases()
66     test_data.append({'nb test suite(s) run': len(testcases)-1})
67     test_data.append({'vPing': '100%'})
68     test_data.append({'VIM status': '82%'})
69     test_data.append({'SDN Controllers': {'odl':'92%', 'onos':'95%', 'opencontrail':'93%'}})
70     test_data.append({'VNF deployment': '95%'})
71
72     return test_data
73
74
75 def format_vIMS_for_dashboard(results):
76     """
77     Post processing for the vIMS test case
78     """
79     test_data = [{'description': 'vIMS results for Dashboard'}]
80
81     # Graph 1: (duration_deployment_orchestrator,
82     #            duration_deployment_vnf,
83     #             duration_test) = f(time)
84     # ********************************
85     new_element = []
86
87     for data in results:
88         new_element.append({'x': data['creation_date'],
89                             'y1': data['details']['orchestrator']['duration'],
90                             'y2': data['details']['vIMS']['duration'],
91                             'y3': data['details']['sig_test']['duration']})
92
93     test_data.append({'name': "vIMS orchestrator/VNF/test duration",
94                       'info': {'type': "graph",
95                                'xlabel': 'time',
96                                'y1label': 'orchestation deployment duration',
97                                'y2label': 'vIMS deployment duration',
98                                'y3label': 'vIMS test duration'},
99                       'data_set': new_element})
100
101     # Graph 2: (Nb test, nb failure, nb skipped)=f(time)
102     # **************************************************
103     new_element = []
104
105     for data in results:
106         # Retrieve all the tests
107         nbTests = 0
108         nbFailures = 0
109         nbSkipped = 0
110         vIMS_test = data['details']['sig_test']['result']
111
112         for data_test in vIMS_test:
113             # Calculate nb of tests run and nb of tests failed
114             # vIMS_results = get_vIMSresults(vIMS_test)
115             # print vIMS_results
116             if data_test['result'] == "Passed":
117                 nbTests += 1
118             elif data_test['result'] == "Failed":
119                 nbFailures += 1
120             elif data_test['result'] == "Skipped":
121                 nbSkipped += 1
122
123         new_element.append({'x': data['creation_date'],
124                             'y1': nbTests,
125                             'y2': nbFailures,
126                             'y3': nbSkipped})
127
128     test_data.append({'name': "vIMS nb tests passed/failed/skipped",
129                       'info': {'type': "graph",
130                                'xlabel': 'time',
131                                'y1label': 'Number of tests passed',
132                                'y2label': 'Number of tests failed',
133                                'y3label': 'Number of tests skipped'},
134                       'data_set': new_element})
135
136     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
137     # ********************************************************
138     nbTests = 0
139     nbFailures = 0
140
141     for data in results:
142         vIMS_test = data['details']['sig_test']['result']
143
144         for data_test in vIMS_test:
145             nbTestsOK = 0
146             nbTestsKO = 0
147
148             if data_test['result'] == "Passed":
149                 nbTestsOK += 1
150             elif data_test['result'] == "Failed":
151                 nbTestsKO += 1
152
153             nbTests += nbTestsOK + nbTestsKO
154             nbFailures += nbTestsKO
155
156     test_data.append({'name': "Total number of tests run/failure tests",
157                       'info': {"type": "bar"},
158                       'data_set': [{'Run': nbTests,
159                                     'Failed': nbFailures}]})
160
161     return test_data
162
163
164 def format_Tempest_for_dashboard(results):
165     """
166     Post processing for the Tempest test case
167     """
168     test_data = [{'description': 'Tempest results for Dashboard'}]
169
170     # Graph 1: Test_Duration = f(time)
171     # ********************************
172     new_element = []
173     for data in results:
174         new_element.append({'x': data['creation_date'],
175                             'y': data['details']['duration']})
176
177     test_data.append({'name': "Tempest duration",
178                       'info': {'type': "graph",
179                                'xlabel': 'time',
180                                'ylabel': 'duration (s)'},
181                       'data_set': new_element})
182
183     # Graph 2: (Nb test, nb failure)=f(time)
184     # ***************************************
185     new_element = []
186     for data in results:
187         new_element.append({'x': data['creation_date'],
188                             'y1': data['details']['tests'],
189                             'y2': data['details']['failures']})
190
191     test_data.append({'name': "Tempest nb tests/nb failures",
192                       'info': {'type': "graph",
193                                'xlabel': 'time',
194                                'y1label': 'Number of tests',
195                                'y2label': 'Number of failures'},
196                       'data_set': new_element})
197
198     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
199     # ********************************************************
200     nbTests = 0
201     nbFailures = 0
202
203     for data in results:
204         nbTests += data['details']['tests']
205         nbFailures += data['details']['failures']
206
207     test_data.append({'name': "Total number of tests run/failure tests",
208                       'info': {"type": "bar"},
209                       'data_set': [{'Run': nbTests,
210                                     'Failed': nbFailures}]})
211
212     return test_data
213
214
215 def format_ODL_for_dashboard(results):
216     """
217     Post processing for the ODL test case
218     """
219     test_data = [{'description': 'ODL results for Dashboard'}]
220
221     # Graph 1: (Nb test, nb failure)=f(time)
222     # ***************************************
223     new_element = []
224
225     for data in results:
226         odl_results = data['details']['details']
227         nbFailures = 0
228         for odl in odl_results:
229             if (odl['test_status']['@status'] == "FAIL"):
230                  nbFailures+=1
231         new_element.append({'x': data['creation_date'],
232                             'y1': len(odl_results),
233                             'y2': nbFailures})
234
235     test_data.append({'name': "ODL nb tests/nb failures",
236                       'info': {'type': "graph",
237                                'xlabel': 'time',
238                                'y1label': 'Number of tests',
239                                'y2label': 'Number of failures'},
240                       'data_set': new_element})
241     return test_data
242
243
244 def format_ONOS_for_dashboard(results):
245     """
246     Post processing for the odl test case
247     """
248     test_data = [{'description': 'ONOS results for Dashboard'}]
249     # Graph 1: (duration)=f(time)
250     # ***************************************
251     new_element = []
252
253     # default duration 0:00:08.999904
254     # consider only seconds => 09
255     for data in results:
256         t = data['details']['duration']
257         h,m,s = re.split(':',t)
258         s = round(float(s))
259         new_duration = int(datetime.timedelta(hours=int(h),minutes=int(m),seconds=int(s)).total_seconds())
260         new_element.append({'x': data['creation_date'],
261                             'y': new_duration})
262
263     test_data.append({'name': "ONOS duration",
264                       'info': {'type': "graph",
265                                'xlabel': 'time (s)',
266                                'ylabel': 'duration (s)'},
267                       'data_set': new_element})
268     return test_data
269
270
271 def format_Rally_for_dashboard(results):
272     """
273     Post processing for the Rally test case
274     """
275     test_data = [{'description': 'Rally results for Dashboard'}]
276     return test_data
277
278
279 def format_vPing_for_dashboard(results):
280     """
281     Post processing for the vPing test case
282     """
283     test_data = [{'description': 'vPing results for Dashboard'}]
284
285     # Graph 1: Test_Duration = f(time)
286     # ********************************
287     new_element = []
288     for data in results:
289         new_element.append({'x': data['creation_date'],
290                             'y': data['details']['duration']})
291
292     test_data.append({'name': "vPing duration",
293                       'info': {'type': "graph",
294                                'xlabel': 'time',
295                                'ylabel': 'duration (s)'},
296                       'data_set': new_element})
297
298     # Graph 2: bar
299     # ************
300     nbTest = 0
301     nbTestOk = 0
302
303     for data in results:
304         nbTest += 1
305         if data['details']['status'] == "OK":
306             nbTestOk += 1
307
308     test_data.append({'name': "vPing status",
309                       'info': {"type": "bar"},
310                       'data_set': [{'Nb tests': nbTest,
311                                     'Nb Success': nbTestOk}]})
312
313     return test_data
314
315 def format_vPing_userdata_for_dashboard(results):
316     """
317     Post processing for the vPing_userdata test case
318     """
319     test_data = [{'description': 'vPing_userdata results for Dashboard'}]
320
321     # Graph 1: Test_Duration = f(time)
322     # ********************************
323     new_element = []
324     for data in results:
325         new_element.append({'x': data['creation_date'],
326                             'y': data['details']['duration']})
327
328     test_data.append({'name': "vPing_userdata duration",
329                       'info': {'type': "graph",
330                                'xlabel': 'time',
331                                'ylabel': 'duration (s)'},
332                       'data_set': new_element})
333
334     # Graph 2: bar
335     # ************
336     nbTest = 0
337     nbTestOk = 0
338
339     for data in results:
340         nbTest += 1
341         if data['details']['status'] == "OK":
342             nbTestOk += 1
343
344     test_data.append({'name': "vPing_userdata status",
345                       'info': {"type": "bar"},
346                       'data_set': [{'Nb tests': nbTest,
347                                     'Nb Success': nbTestOk}]})
348
349     return test_data