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 Yardstick project
14 # a new method format_<Test_case>_for_dashboard(results)
15 # v0.1: basic example with methods for Ping, Iperf, Netperf, Pktgen,
16 # Fio, Lmbench, Perf, Cyclictest.
19 def get_yardstick_cases():
21 get the list of the supported test cases
22 TODO: update the list when adding a new test case for the dashboard
24 return ["Ping", "Iperf", "Netperf", "Pktgen", "Fio", "Lmbench",
28 def format_yardstick_for_dashboard(case, results):
30 generic method calling the method corresponding to the test case
31 check that the testcase is properly declared first
32 then build the call to the specific method
34 if check_yardstick_case_exist(case):
35 cmd = "format_" + case + "_for_dashboard"
36 res = globals()[cmd](results)
39 print "Test cases not declared"
43 def check_yardstick_case_exist(case):
45 check if the testcase exists
46 if the test case is not defined or not declared in the list
49 yardstick_cases = get_yardstick_cases()
51 if (case is None or case not in yardstick_cases):
57 def _get_test_status_bar(results):
63 records = [record for record in data['details']
64 if "benchmark" in record
65 and record["benchmark"]["errors"] != ""]
68 return nbTest, nbTestOk
71 def format_Ping_for_dashboard(results):
73 Post processing for the Ping test case
75 test_data = [{'description': 'Ping results for Dashboard'}]
77 # Graph 1: Test_Duration = f(time)
78 # ********************************
81 records = [record["benchmark"]["data"]["rtt"]
82 for record in data['details']
83 if "benchmark" in record]
85 avg_rtt = sum(records) / len(records)
86 new_element.append({'x': data['start_date'],
89 test_data.append({'name': "ping duration",
90 'info': {'type': "graph",
92 'ylabel': 'duration (s)'},
93 'data_set': new_element})
97 nbTest, nbTestOk = _get_test_status_bar(results)
99 test_data.append({'name': "ping status",
100 'info': {"type": "bar"},
101 'data_set': [{'Nb tests': nbTest,
102 'Nb Success': nbTestOk}]})
107 def format_iperf_for_dashboard(results):
109 Post processing for the Iperf test case
111 test_data = [{'description': 'Iperf results for Dashboard'}]
115 def format_netperf_for_dashboard(results):
117 Post processing for the Netperf test case
119 test_data = [{'description': 'Netperf results for Dashboard'}]
123 def format_pktgen_for_dashboard(results):
125 Post processing for the Pktgen test case
127 test_data = [{'description': 'Pktgen results for Dashboard'}]
131 def format_fio_for_dashboard(results):
133 Post processing for the Fio test case
135 test_data = [{'description': 'Fio results for Dashboard'}]
139 def format_lmbench_for_dashboard(results):
141 Post processing for the Lmbench test case
143 test_data = [{'description': 'Lmbench results for Dashboard'}]
147 def format_perf_for_dashboard(results):
149 Post processing for the Perf test case
151 test_data = [{'description': 'Perf results for Dashboard'}]
155 def format_cyclictest_for_dashboard(results):
157 Post processing for the Cyclictest test case
159 test_data = [{'description': 'Cyclictest results for Dashboard'}]
163 ############################ For local test ################################
168 def _read_sample_output(filename):
169 curr_path = os.path.dirname(os.path.abspath(__file__))
170 output = os.path.join(curr_path, filename)
171 with open(output) as f:
172 sample_output = f.read()
174 result = json.loads(sample_output)
177 # Copy form functest/testcases/Dashboard/dashboard_utils.py
178 # and did some minor modification for local test.
179 def _get_results(db_url, test_criteria):
181 test_project = test_criteria["project"]
182 testcase = test_criteria["testcase"]
185 headers = {'Content-Type': 'application/json'}
188 # if criteria is all => remove criteria
189 url = db_url + "/results?project=" + test_project + "&case=" + testcase
191 # Send Request to Test DB
192 myData = requests.get(url, headers=headers)
194 # Get result as a json object
195 myNewData = json.loads(myData.text)
198 myDataResults = myNewData['test_results']
203 db_url = "http://213.77.62.197"
204 result = _get_results(db_url,
205 {"project": "yardstick", "testcase": "Ping"})
206 print format_ping_for_dashboard(result)
208 if __name__ == '__main__':