2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 '''This file realize the function of run systembandwidth script.
11 for example this contain two part first run_script,
12 second is algorithm, this part is about how to judge the bottlenecks.
13 This test is using yardstick as a tool to begin test.'''
19 import utils.logger as log
20 from utils.parser import Parser as conf_parser
21 import utils.env_prepare.stack_prepare as stack_prepare
22 import testsuites.posca.testcase_dashboard.system_bandwidth as DashBoard
23 import utils.infra_setup.runner.docker_env as docker_env
24 # --------------------------------------------------
25 # logging configuration
26 # --------------------------------------------------
27 LOG = log.Logger(__name__).getLogger()
30 "action": "runTestCase",
35 "testcase": "netperf_bottlenecks"
38 testfile = os.path.basename(__file__)
39 testcase, file_format = os.path.splitext(testfile)
43 LOG.info("yardstick environment prepare!")
44 stack_prepare._prepare_env_daemon(True)
47 def config_to_result(test_config, test_result):
49 parser_result = test_result["benchmark"]["data"]
50 test_result.update(test_config)
51 test_result.update(parser_result)
52 test_result["throughput"] = float(test_result["throughput"])
53 test_result["remote_cpu_util"] = float(test_result["remote_cpu_util"])
54 test_result["local_cpu_util"] = float(test_result["local_cpu_util"])
55 test_result["mean_latency"] = float(test_result["mean_latency"])
56 testdata["data_body"] = test_result
57 testdata["testcase"] = testcase
61 def testcase_parser(out_file="yardstick.out", **parameter_info):
62 cmd = ('yardstick task start /home/opnfv/repos/yardstick/'
63 'samples/netperf_bottlenecks.yaml --output-file ' + out_file)
64 cmd = cmd + " --task-args " + '"' + str(parameter_info) + '"'
65 LOG.info("yardstick test cmd is: %s" % cmd)
69 def do_test(test_config, Use_Dashboard, context_conf):
70 yardstick_container = docker_env.yardstick_info['container']
71 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
72 cmd = testcase_parser(out_file=out_file, **test_config)
73 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
76 while loop_value < 60:
78 loop_value = loop_value + 1
79 with open(out_file) as f:
81 if data["status"] == 1:
82 LOG.info("yardstick run success")
84 elif data["status"] == 2:
85 LOG.error("yardstick error exit")
88 save_data = config_to_result(test_config, data['result'][1])
89 if Use_Dashboard is True:
90 DashBoard.dashboard_send_data(context_conf, save_data)
92 return save_data["data_body"]
96 con_dic = test_config["load_manager"]
99 if test_config["contexts"]["yardstick_ip"] is None:
100 con_dic["contexts"]["yardstick_ip"] =\
101 conf_parser.ip_parser("yardstick_test_ip")
103 if "dashboard" in test_config["contexts"].keys():
104 if test_config["contexts"]["dashboard_ip"] is None:
105 test_config["contexts"]["dashboard_ip"] =\
106 conf_parser.ip_parser("dashboard")
107 LOG.info("Create Dashboard data")
109 DashBoard.dashboard_system_bandwidth(test_config["contexts"])
112 rx_pkt_a = con_dic['scenarios']['rx_pkt_sizes'].split(',')
113 tx_pkt_a = con_dic['scenarios']['tx_pkt_sizes'].split(',')
114 data["rx_pkt_sizes"] = rx_pkt_a
115 data["tx_pkt_sizes"] = tx_pkt_a
116 con_dic["result_file"] = os.path.dirname(
117 os.path.abspath(__file__)) + "/test_case/result"
123 data_return["throughput"] = 1
125 for test_x in data["tx_pkt_sizes"]:
126 data_max["throughput"] = 1
128 for test_y in data["rx_pkt_sizes"]:
130 "tx_msg_size": float(test_x),
131 "rx_msg_size": float(test_y),
132 "test_time": con_dic['scenarios']['test_times'],
133 "pod_info": conf_parser.bottlenecks_config["pod_info"]
135 data_reply = do_test(case_config, Use_Dashboard,
136 test_config["contexts"])
138 conf_parser.result_to_file(data_reply, test_config["out_file"])
139 bandwidth = data_reply["throughput"]
140 if (data_max["throughput"] < bandwidth):
141 data_max = data_reply
142 if (abs(bandwidth_tmp - bandwidth) / bandwidth_tmp < 0.025):
143 LOG.info("this group of data has reached top output")
146 pre_reply = data_reply
147 bandwidth_tmp = bandwidth
148 cur_role_result = float(pre_reply["throughput"])
149 if (abs(pre_role_result - cur_role_result) / pre_role_result < 0.025):
150 LOG.info("The performance increases slowly")
151 if data_return["throughput"] < data_max["throughput"]:
152 data_return = data_max
153 pre_role_result = cur_role_result
154 LOG.info("Find bottlenecks of this config")
155 LOG.info("The max data is %d", data_return["throughput"])