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'}]
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['creation_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})
81 def format_tu1_for_dashboard(results):
82 test_data = [{'description': 'Tu-1 performance result'}]
85 last_result = results[-1]["details"]
86 for key in sorted(last_result):
87 bandwith = last_result[key]["Bandwidth"]
89 line_element.append({'x': pktsize,
90 'y': bandwith * 1000})
91 bar_element[key] = bandwith * 1000
93 test_data.append({'name': "VM2VM max single directional throughput",
94 'info': {'type': "graph",
96 'ylabel': 'bandwith(kpps)'},
97 'data_set': line_element})
99 test_data.append({'name': "VM2VM max single directional throughput",
100 'info': {"type": "bar"},
101 'data_set': bar_element})
105 def format_tu3_for_dashboard(results):
106 test_data = [{'description': 'Tu-3 performance result'}]
109 last_result = results[-1]["details"]
110 for key in sorted(last_result):
111 bandwith = last_result[key]["Bandwidth"]
113 new_element.append({'x': pktsize,
114 'y': bandwith * 1000})
115 bar_element[key] = bandwith * 1000
117 test_data.append({'name': "VM2VM max bidirectional throughput",
118 'info': {'type': "graph",
120 'ylabel': 'bandwith(kpps)'},
121 'data_set': new_element})
123 test_data.append({'name': "VM2VM max single directional throughput",
124 'info': {"type": "bar"},
125 'data_set': bar_element})
129 ############################ For local test ################################
131 def _read_sample_output(filename):
132 curr_path = os.path.dirname(os.path.abspath(__file__))
133 output = os.path.join(curr_path, filename)
134 with open(output) as f:
135 sample_output = f.read()
137 result = json.loads(sample_output)
141 # Copy form functest/testcases/Dashboard/dashboard_utils.py
142 # and did some minor modification for local test.
143 def _get_results(db_url, test_criteria):
144 test_project = test_criteria["project"]
145 testcase = test_criteria["testcase"]
148 headers = {'Content-Type': 'application/json'}
151 # if criteria is all => remove criteria
152 url = db_url + "/results?project=" + test_project + "&case=" + testcase
154 # Send Request to Test DB
155 myData = requests.get(url, headers=headers)
157 # Get result as a json object
158 myNewData = json.loads(myData.text)
161 myDataResults = myNewData['test_results']
166 db_url = "http://213.77.62.197"
167 results = _get_results(db_url, {"project": "bottlenecks", "testcase": "rubbos"})
168 test_result = format_rubbos_for_dashboard(results)
169 print json.dumps(test_result, indent=4)
171 results = _get_results(db_url, {"project": "bottlenecks", "testcase": "tu1"})
172 #results = _read_sample_output("sample")
173 #print json.dumps(results, indent=4)
174 test_result = format_tu1_for_dashboard(results)
175 print json.dumps(test_result, indent=4)
176 results = _get_results(db_url, {"project": "bottlenecks", "testcase": "tu3"})
177 test_result = format_tu3_for_dashboard(results)
178 print json.dumps(test_result, indent=4)
181 if __name__ == '__main__':