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.
20 def get_yardstick_cases():
22 get the list of the supported test cases
23 TODO: update the list when adding a new test case for the dashboard
25 return ["Ping", "Iperf", "Netperf", "Pktgen", "Fio", "Lmbench",
29 def format_yardstick_for_dashboard(case, results):
31 generic method calling the method corresponding to the test case
32 check that the testcase is properly declared first
33 then build the call to the specific method
35 if check_yardstick_case_exist(case):
36 cmd = "format_" + case + "_for_dashboard(results)"
40 print "Test cases not declared"
44 def check_yardstick_case_exist(case):
46 check if the testcase exists
47 if the test case is not defined or not declared in the list
50 yardstick_cases = get_yardstick_cases()
52 if (case is None or case not in yardstick_cases):
58 def _get_test_status_bar(results):
64 records = [record for record in data['details']
65 if "benchmark" in record
66 and record["benchmark"]["errors"] != ""]
69 return nbTest, nbTestOk
72 def format_Ping_for_dashboard(results):
74 Post processing for the Ping test case
76 test_data = [{'description': 'Ping results for Dashboard'}]
78 # Graph 1: Test_Duration = f(time)
79 # ********************************
82 records = [record["benchmark"]["data"]["rtt"]
83 for record in data['details']
84 if "benchmark" in record]
86 avg_rtt = sum(records) / len(records)
87 new_element.append({'x': data['start_date'],
90 test_data.append({'name': "ping duration",
91 'info': {'type': "graph",
93 'ylabel': 'duration (s)'},
94 'data_set': new_element})
98 nbTest, nbTestOk = _get_test_status_bar(results)
100 test_data.append({'name': "ping status",
101 'info': {"type": "bar"},
102 'data_set': [{'Nb tests': nbTest,
103 'Nb Success': nbTestOk}]})
108 def format_iperf_for_dashboard(results):
110 Post processing for the Iperf test case
112 test_data = [{'description': 'Iperf results for Dashboard'}]
116 def format_netperf_for_dashboard(results):
118 Post processing for the Netperf test case
120 test_data = [{'description': 'Netperf results for Dashboard'}]
124 def format_pktgen_for_dashboard(results):
126 Post processing for the Pktgen test case
128 test_data = [{'description': 'Pktgen results for Dashboard'}]
132 def format_fio_for_dashboard(results):
134 Post processing for the Fio test case
136 test_data = [{'description': 'Fio results for Dashboard'}]
140 def format_lmbench_for_dashboard(results):
142 Post processing for the Lmbench test case
144 test_data = [{'description': 'Lmbench results for Dashboard'}]
148 def format_perf_for_dashboard(results):
150 Post processing for the Perf test case
152 test_data = [{'description': 'Perf results for Dashboard'}]
156 def format_cyclictest_for_dashboard(results):
158 Post processing for the Cyclictest test case
160 test_data = [{'description': 'Cyclictest results for Dashboard'}]
164 ############################ For local test ################################
169 def _read_sample_output(filename):
170 curr_path = os.path.dirname(os.path.abspath(__file__))
171 output = os.path.join(curr_path, filename)
172 with open(output) as f:
173 sample_output = f.read()
175 result = json.loads(sample_output)
178 # Copy form functest/testcases/Dashboard/dashboard_utils.py
179 # and did some minor modification for local test.
180 def _get_results(db_url, test_criteria):
182 test_project = test_criteria["project"]
183 testcase = test_criteria["testcase"]
186 headers = {'Content-Type': 'application/json'}
189 # if criteria is all => remove criteria
190 url = db_url + "/results?project=" + test_project + "&case=" + testcase
192 # Send Request to Test DB
193 myData = requests.get(url, headers=headers)
195 # Get result as a json object
196 myNewData = json.loads(myData.text)
199 myDataResults = myNewData['test_results']
204 db_url = "http://213.77.62.197"
205 result = _get_results(db_url,
206 {"project": "yardstick", "testcase": "Ping"})
207 print format_ping_for_dashboard(result)
209 if __name__ == '__main__':