3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
6 # All rights reserved. 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 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # This script is used to build dashboard ready json results
13 # It may be used for all the test case of the Bottlenecks project
14 # a new method format_<Test_case>_for_dashboard(results)
15 # v0.1: basic example with methods for Rubbos.
22 def get_bottlenecks_cases():
24 get the list of the supported test cases
25 TODO: update the list when adding a new test case for the dashboard
27 return ["rubbos", "tu1", "tu3"]
30 def check_bottlenecks_case_exist(case):
32 check if the testcase exists
33 if the test case is not defined or not declared in the list
36 bottlenecks_cases = get_bottlenecks_cases()
38 if case is None or case not in bottlenecks_cases:
44 def format_bottlenecks_for_dashboard(case, results):
46 generic method calling the method corresponding to the test case
47 check that the testcase is properly declared first
48 then build the call to the specific method
50 if check_bottlenecks_case_exist(case):
51 cmd = "format_" + case + "_for_dashboard(results)"
55 print "Test cases not declared"
59 def format_rubbos_for_dashboard(results):
61 Post processing for the Rubbos test case
63 test_data = [{'description': 'Rubbos results'}]
65 # Graph 1:Rubbos maximal throughput
66 # ********************************
68 #for each_result in results:
69 # throughput_data = [record['throughput'] for record in each_result['details']]
70 # new_element.append({'x': each_result['start_date'],
71 # 'y': max(throughput_data)})
73 #test_data.append({'name': "Rubbos max throughput",
74 # 'info': {'type': "graph",
76 # 'ylabel': 'maximal throughput'},
77 # 'data_set': new_element})
79 # Graph 2: Rubbos last record
80 # ********************************
82 latest_result = results[-1]["details"]
83 for data in latest_result:
84 client_num = int(data["client"])
85 throughput = int(data["throughput"])
86 new_element.append({'x': client_num,
88 test_data.append({'name': "Rubbos throughput vs client number",
89 'info': {'type': "graph",
90 'xlabel': 'client number',
91 'ylabel': 'throughput'},
92 'data_set': new_element})
97 def format_tu1_for_dashboard(results):
98 test_data = [{'description': 'Tu-1 performance result'}]
101 last_result = results[-1]["details"]
102 for key in sorted(last_result):
103 bandwith = last_result[key]["Bandwidth"]
105 line_element.append({'x': pktsize,
106 'y': bandwith * 1000})
107 bar_element[key] = bandwith * 1000
109 test_data.append({'name': "VM2VM max single directional throughput",
110 'info': {'type': "graph",
112 'ylabel': 'bandwith(kpps)'},
113 'data_set': line_element})
115 test_data.append({'name': "VM2VM max single directional throughput",
116 'info': {"type": "bar"},
117 'data_set': bar_element})
121 def format_tu3_for_dashboard(results):
122 test_data = [{'description': 'Tu-3 performance result'}]
125 last_result = results[-1]["details"]
126 for key in sorted(last_result):
127 bandwith = last_result[key]["Bandwidth"]
129 new_element.append({'x': pktsize,
130 'y': bandwith * 1000})
131 bar_element[key] = bandwith * 1000
133 test_data.append({'name': "VM2VM max bidirectional throughput",
134 'info': {'type': "graph",
136 'ylabel': 'bandwith(kpps)'},
137 'data_set': new_element})
139 test_data.append({'name': "VM2VM max single directional throughput",
140 'info': {"type": "bar"},
141 'data_set': bar_element})
145 ############################ For local test ################################
147 def _read_sample_output(filename):
148 curr_path = os.path.dirname(os.path.abspath(__file__))
149 output = os.path.join(curr_path, filename)
150 with open(output) as f:
151 sample_output = f.read()
153 result = json.loads(sample_output)
157 # Copy form functest/testcases/Dashboard/dashboard_utils.py
158 # and did some minor modification for local test.
159 def _get_results(db_url, test_criteria):
160 test_project = test_criteria["project"]
161 testcase = test_criteria["testcase"]
164 headers = {'Content-Type': 'application/json'}
167 # if criteria is all => remove criteria
168 url = db_url + "/results?project=" + test_project + "&case=" + testcase
170 # Send Request to Test DB
171 myData = requests.get(url, headers=headers)
173 # Get result as a json object
174 myNewData = json.loads(myData.text)
177 myDataResults = myNewData['test_results']
182 db_url = "http://testresults.opnfv.org/testapi"
183 results = _get_results(db_url, {"project": "bottlenecks", "testcase": "rubbos"})
184 test_result = format_rubbos_for_dashboard(results)
185 print json.dumps(test_result, indent=4)
187 results = _get_results(db_url, {"project": "bottlenecks", "testcase": "tu1"})
188 #results = _read_sample_output("sample")
189 #print json.dumps(results, indent=4)
190 test_result = format_tu1_for_dashboard(results)
191 print json.dumps(test_result, indent=4)
192 results = _get_results(db_url, {"project": "bottlenecks", "testcase": "tu3"})
193 test_result = format_tu3_for_dashboard(results)
194 print json.dumps(test_result, indent=4)
197 if __name__ == '__main__':