create post processing for Tempest test
[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 ["vPing", "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_Tempest_for_dashboard(results):
57     """
58     Post processing for the Tempest test case
59     """
60     test_data = [{'description': 'Tempest results for Dashboard'}]
61
62     # Graph 1: Test_Duration = f(time)
63     # ********************************
64     new_element = []
65     for data in results:
66         new_element.append({'x': data['creation_date'],
67                             'y': data['details']['duration']})
68
69     test_data.append({'name': "Tempest duration",
70                       'info': {'type': "graph",
71                                'xlabel': 'time',
72                                'ylabel': 'duration (s)'},
73                       'data_set': new_element})
74
75     # Graph 2: (Nb test, nb failure)=f(time)
76     # ***************************************
77     new_element = []
78     for data in results:
79         new_element.append({'x': data['creation_date'],
80                             'y1': data['details']['tests'],
81                             'y2': data['details']['failures']})
82
83     test_data.append({'name': "Tempest nb tests/nb failures",
84                       'info': {'type': "graph",
85                                'xlabel': 'time',
86                                'y1label': 'Number of tests',
87                                'y2label': 'Number of failures'},
88                       'data_set': new_element})
89
90     # Graph 3: bar graph Summ(nb tests run), Sum (nb tests failed)
91     # ********************************************************
92     nbTests = 0
93     nbFailures = 0
94
95     for data in results:
96         nbTests += data['details']['tests']
97         nbFailures += data['details']['failures']
98
99     test_data.append({'name': "Total number of tests run/failure tests",
100                       'info': {"type": "bar"},
101                       'data_set': [{'Run': nbTests,
102                                     'Failed': nbFailures}]})
103
104     return test_data
105
106
107 def format_odl_for_dashboard(results):
108     """
109     Post processing for the odl test case
110     """
111     test_data = [{'description': 'odl results for Dashboard'}]
112     return test_data
113
114
115 def format_Rally_for_dashboard(results):
116     """
117     Post processing for the Rally test case
118     """
119     test_data = [{'description': 'Rally results for Dashboard'}]
120     return test_data
121
122
123 def format_vPing_for_dashboard(results):
124     """
125     Post processing for the vPing test case
126     """
127     test_data = [{'description': 'vPing results for Dashboard'}]
128
129     # Graph 1: Test_Duration = f(time)
130     # ********************************
131     new_element = []
132     for data in results:
133         new_element.append({'x': data['creation_date'],
134                             'y': data['details']['duration']})
135
136     test_data.append({'name': "vPing duration",
137                       'info': {'type': "graph",
138                                'xlabel': 'time',
139                                'ylabel': 'duration (s)'},
140                       'data_set': new_element})
141
142     # Graph 2: bar
143     # ************
144     nbTest = 0
145     nbTestOk = 0
146
147     for data in results:
148         nbTest += 1
149         if data['details']['status'] == "OK":
150             nbTestOk += 1
151
152     test_data.append({'name': "vPing status",
153                       'info': {"type": "bar"},
154                       'data_set': [{'Nb tests': nbTest,
155                                     'Nb Success': nbTestOk}]})
156
157     return test_data