323d3915c439a508322227c77c1e8fbf5c4b9f48
[releng.git] / utils / test / result_collection_api / dashboard / vsperf2Dashboard.py
1 #!/usr/bin/python
2
3 # Copyright 2015 Intel Corporation.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"),
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 def get_vsperf_cases():
18     """
19     get the list of the supported test cases
20     TODO: update the list when adding a new test case for the dashboard
21     """
22     return ["tput_ovsdpdk", "tput_ovs",
23             "b2b_ovsdpdk", "b2b_ovs",
24             "tput_mod_vlan_ovsdpdk", "tput_mod_vlan_ovs",
25             "cont_ovsdpdk", "cont_ovs",
26             "pvp_cont_ovsdpdkuser", "pvp_cont_ovsdpdkcuse", "pvp_cont_ovsvirtio",
27             "pvvp_cont_ovsdpdkuser", "pvvp_cont_ovsdpdkcuse", "pvvp_cont_ovsvirtio",
28             "scalability_ovsdpdk", "scalability_ovs",
29             "pvp_tput_ovsdpdkuser", "pvp_tput_ovsdpdkcuse", "pvp_tput_ovsvirtio",
30             "pvp_b2b_ovsdpdkuser", "pvp_b2b_ovsdpdkcuse", "pvp_b2b_ovsvirtio",
31             "pvvp_tput_ovsdpdkuser", "pvvp_tput_ovsdpdkcuse", "pvvp_tput_ovsvirtio",
32             "pvvp_b2b_ovsdpdkuser", "pvvp_b2b_ovsdpdkcuse", "pvvp_b2b_ovsvirtio",
33             "cpu_load_ovsdpdk", "cpu_load_ovs",
34             "mem_load_ovsdpdk", "mem_load_ovs"]
35
36
37 def check_vsperf_case_exist(case):
38     """
39     check if the testcase exists
40     if the test case is not defined or not declared in the list
41     return False
42     """
43     vsperf_cases = get_vsperf_cases()
44  
45     if (case is None or case not in vsperf_cases):
46         return False
47     else:
48         return True
49
50
51 def format_vsperf_for_dashboard(case, results):
52     """
53     generic method calling the method corresponding to the test case
54     check that the testcase is properly declared first
55     then build the call to the specific method
56     """
57     if check_vsperf_case_exist(case):
58         res = format_common_for_dashboard(case, results)
59     else:
60         res = []
61         print "Test cases not declared"
62     return res
63
64
65 def format_common_for_dashboard(case, results):
66     """
67     Common post processing
68     """
69     test_data_description = case + " results for Dashboard"
70     test_data = [{'description': test_data_description}]
71
72     graph_name = ''
73     if "b2b" in case:
74         graph_name = "B2B frames"
75     else:
76         graph_name = "Rx frames per second"
77
78     # Graph 1: Rx fps = f(time)
79     # ********************************
80     new_element = []
81     for data in results:
82         new_element.append({'x': data['creation_date'],
83                             'y1': data['details']['64'],
84                             'y2': data['details']['128'],
85                             'y3': data['details']['512'],
86                             'y4': data['details']['1024'],
87                             'y5': data['details']['1518']})
88
89     test_data.append({'name': graph_name,
90                       'info': {'type': "graph",
91                                'xlabel': 'time',
92                                'y1label': 'frame size 64B',
93                                'y2label': 'frame size 128B',
94                                'y3label': 'frame size 512B',
95                                'y4label': 'frame size 1024B',
96                                'y5label': 'frame size 1518B'},
97                       'data_set': new_element})
98
99     return test_data
100
101
102
103
104 ############################  For local test  ################################
105 import os
106
107 def _test():
108     ans = [{'creation_date': '2015-09-12', 'project_name': 'vsperf', 'version': 'ovs_master', 'pod_name': 'pod1-vsperf', 'case_name': 'tput_ovsdpdk', 'installer': 'build_sie', 'details': {'64': '26.804', '1024': '1097.284', '512': '178.137', '1518': '12635.860', '128': '100.564'}},
109            {'creation_date': '2015-09-33', 'project_name': 'vsperf', 'version': 'ovs_master', 'pod_name': 'pod1-vsperf', 'case_name': 'tput_ovsdpdk', 'installer': 'build_sie', 'details': {'64': '16.804', '1024': '1087.284', '512': '168.137', '1518': '12625.860', '128': '99.564'}}]
110
111     result = format_vsperf_for_dashboard("pvp_cont_ovsdpdkcuse", ans)
112     print result
113
114     result = format_vsperf_for_dashboard("b2b_ovsdpdk", ans)
115     print result
116
117     result = format_vsperf_for_dashboard("non_existing", ans)
118     print result
119
120 if __name__ == '__main__':
121     _test()