3e7eefe7e65f01081d26a9284e65c49062059cfc
[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
19 def get_functest_cases():
20     """
21     get the list of the supported test cases
22     TODO: update the list when adding a new test case for the dashboard
23     """
24     return ["status", "vPing", "vIMS", "Tempest", "odl", "Rally"]
25
26
27 def format_functest_for_dashboard(case, results):
28     """
29     generic method calling the method corresponding to the test case
30     check that the testcase is properly declared first
31     then build the call to the specific method
32     """
33     if check_functest_case_exist(case):
34         cmd = "format_" + case + "_for_dashboard(results)"
35         res = eval(cmd)
36     else:
37         res = []
38         print "Test cases not declared"
39     return res
40
41
42 def check_functest_case_exist(case):
43     """
44     check if the testcase exists
45     if the test case is not defined or not declared in the list
46     return False
47     """
48     functest_cases = get_functest_cases()
49
50     if (case is None or case not in functest_cases):
51         return False
52     else:
53         return True
54
55
56 def format_status_for_dashboard(results):
57     test_data = [{'description': 'Functest status'}]
58
59     # define magic equation for the status....
60     # 5 suites: vPing, odl, Tempest, vIMS, Rally
61     # Which overall KPI make sense...
62
63     # TODO to be done and discussed
64     testcases = get_functest_cases()
65     test_data.append({'nb test suite(s) run': len(testcases)-1})
66     test_data.append({'vPing': '100%'})
67     test_data.append({'VIM status': '82%'})
68     test_data.append({'SDN Controllers': {'odl':'92%', 'onos':'95%', 'opencontrail':'93%'}})
69     test_data.append({'VNF deployment': '95%'})
70
71     return test_data
72
73
74 def format_vIMS_for_dashboard(results):
75     """
76     Post processing for the vIMS test case
77     """
78     test_data = [{'description': 'vIMS results for Dashboard'}]
79
80     # Graph 1: (duration_deployment_orchestrator,
81     #            duration_deployment_vnf,
82     #             duration_test) = f(time)
83     # ********************************
84     new_element = []
85
86     for data in results:
87         new_element.append({'x': data['creation_date'],
88                             'y1': data['details']['orchestrator']['duration'],
89                             'y2': data['details']['vIMS']['duration'],
90                             'y3': data['details']['sig_test']['duration']})
91
92     test_data.append({'name': "Tempest nb tests/nb failures",
93                       'info': {'type': "graph",
94                                'xlabel': 'time',
95                                'y1label': 'orchestation deployment duration',
96                                'y2label': 'vIMS deployment duration',
97                                'y3label': 'vIMS test duration'},
98                       'data_set': new_element})
99
100     # Graph 2: (Nb test, nb failure, nb skipped)=f(time)
101     # **************************************************
102     new_element = []
103
104     for data in results:
105         # Retrieve all the tests
106         nbTests = 0
107         nbFailures = 0
108         nbSkipped = 0
109         vIMS_test = data['details']['sig_test']['result']
110
111         for data_test in vIMS_test:
112             # Calculate nb of tests run and nb of tests failed
113             # vIMS_results = get_vIMSresults(vIMS_test)
114             # print vIMS_results
115             if data_test['result'] == "Passed":
116                 nbTests += 1
117             elif data_test['result'] == "Failed":
118                 nbFailures += 1
119             elif data_test['result'] == "Skipped":
120                 nbSkipped += 1
121
122         new_element.append({'x': data['creation_date'],
123                             'y1': nbTests,
124                             'y2': nbFailures,
125                             'y3': nbSkipped})
126
127     test_data.append({'name': "vIMS nb tests passed/failed/skipped",
128                       'info': {'type': "graph",
129                                'xlabel': 'time',
130                                'y1label': 'Number of tests passed',
131                                'y2label': 'Number of tests failed',
132                                'y3label': 'Number of tests skipped'},
133                       'data_set': new_element})
134
135     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
136     # ********************************************************
137     nbTests = 0
138     nbFailures = 0
139
140     for data in results:
141         vIMS_test = data['details']['sig_test']['result']
142
143         for data_test in vIMS_test:
144             nbTestsOK = 0
145             nbTestsKO = 0
146
147             if data_test['result'] == "Passed":
148                 nbTestsOK += 1
149             elif data_test['result'] == "Failed":
150                 nbTestsKO += 1
151
152             nbTests += nbTestsOK + nbTestsKO
153             nbFailures += nbTestsKO
154
155     test_data.append({'name': "Total number of tests run/failure tests",
156                       'info': {"type": "bar"},
157                       'data_set': [{'Run': nbTests,
158                                     'Failed': nbFailures}]})
159
160     return test_data
161
162
163 def format_Tempest_for_dashboard(results):
164     """
165     Post processing for the Tempest test case
166     """
167     test_data = [{'description': 'Tempest results for Dashboard'}]
168
169     # Graph 1: Test_Duration = f(time)
170     # ********************************
171     new_element = []
172     for data in results:
173         new_element.append({'x': data['creation_date'],
174                             'y': data['details']['duration']})
175
176     test_data.append({'name': "Tempest duration",
177                       'info': {'type': "graph",
178                                'xlabel': 'time',
179                                'ylabel': 'duration (s)'},
180                       'data_set': new_element})
181
182     # Graph 2: (Nb test, nb failure)=f(time)
183     # ***************************************
184     new_element = []
185     for data in results:
186         new_element.append({'x': data['creation_date'],
187                             'y1': data['details']['tests'],
188                             'y2': data['details']['failures']})
189
190     test_data.append({'name': "Tempest nb tests/nb failures",
191                       'info': {'type': "graph",
192                                'xlabel': 'time',
193                                'y1label': 'Number of tests',
194                                'y2label': 'Number of failures'},
195                       'data_set': new_element})
196
197     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
198     # ********************************************************
199     nbTests = 0
200     nbFailures = 0
201
202     for data in results:
203         nbTests += data['details']['tests']
204         nbFailures += data['details']['failures']
205
206     test_data.append({'name': "Total number of tests run/failure tests",
207                       'info': {"type": "bar"},
208                       'data_set': [{'Run': nbTests,
209                                     'Failed': nbFailures}]})
210
211     return test_data
212
213
214 def format_odl_for_dashboard(results):
215     """
216     Post processing for the odl test case
217     """
218     test_data = [{'description': 'odl results for Dashboard'}]
219     return test_data
220
221
222 def format_Rally_for_dashboard(results):
223     """
224     Post processing for the Rally test case
225     """
226     test_data = [{'description': 'Rally results for Dashboard'}]
227     return test_data
228
229
230 def format_vPing_for_dashboard(results):
231     """
232     Post processing for the vPing test case
233     """
234     test_data = [{'description': 'vPing results for Dashboard'}]
235
236     # Graph 1: Test_Duration = f(time)
237     # ********************************
238     new_element = []
239     for data in results:
240         new_element.append({'x': data['creation_date'],
241                             'y': data['details']['duration']})
242
243     test_data.append({'name': "vPing duration",
244                       'info': {'type': "graph",
245                                'xlabel': 'time',
246                                'ylabel': 'duration (s)'},
247                       'data_set': new_element})
248
249     # Graph 2: bar
250     # ************
251     nbTest = 0
252     nbTestOk = 0
253
254     for data in results:
255         nbTest += 1
256         if data['details']['status'] == "OK":
257             nbTestOk += 1
258
259     test_data.append({'name': "vPing status",
260                       'info': {"type": "bar"},
261                       'data_set': [{'Nb tests': nbTest,
262                                     'Nb Success': nbTestOk}]})
263
264     return test_data