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 utils.infra_setup.runner.docker_env as docker_env
23 import utils.infra_setup.runner.yardstick as yardstick_task
25 # --------------------------------------------------
26 # logging configuration
27 # --------------------------------------------------
28 LOG = log.Logger(__name__).getLogger()
30 testfile = os.path.basename(__file__)
31 testcase, file_format = os.path.splitext(testfile)
32 cidr = "/home/opnfv/repos/yardstick/samples/pvp_throughput_bottlenecks.yaml"
37 LOG.info("yardstick environment prepare!")
38 stack_prepare._prepare_env_daemon(True)
41 def config_to_result(test_config, test_result):
44 out_data = test_result["result"]["testcases"]
45 test_data = out_data["pvp_throughput_bottlenecks"]["tc_data"]
46 for result in test_data:
48 testdata["vcpu"] = test_config["vcpu"]
49 testdata["memory"] = test_config["memory"]
50 testdata["nrFlows"] = result["data"]["nrFlows"]
51 testdata["packet_size"] = result["data"]["packet_size"]
52 testdata["throughput"] = result["data"]["throughput_rx_mbps"]
53 final_data.append(testdata)
57 def testcase_parser(out_file="yardstick.out", **parameter_info):
58 cmd = yardstick_task.yardstick_command_parser(debug=runner_DEBUG,
61 parameter=parameter_info)
65 def do_test(test_config, Use_Dashboard, context_conf):
66 yardstick_container = docker_env.yardstick_info['container']
67 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
68 cmd = testcase_parser(out_file=out_file, **test_config)
70 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
73 while loop_value < 60:
75 loop_value = loop_value + 1
76 with open(out_file) as f:
78 if data["status"] == 1:
79 LOG.info("yardstick run success")
81 elif data["status"] == 2:
82 LOG.error("yardstick error exit")
85 save_data = config_to_result(test_config, data)
86 if Use_Dashboard is True:
87 print("use dashboard")
92 load_config = test_config["load_manager"]
93 scenarios_conf = load_config["scenarios"]
97 if test_config["contexts"]["yardstick_ip"] is None:
98 load_config["contexts"]["yardstick_ip"] =\
99 conf_parser.ip_parser("yardstick_test_ip")
101 if "dashboard" in test_config["contexts"].keys():
102 if test_config["contexts"]["dashboard_ip"] is None:
103 test_config["contexts"]["dashboard_ip"] =\
104 conf_parser.ip_parser("dashboard")
105 LOG.info("Create Dashboard data")
108 cpus = conf_parser.str_to_list(scenarios_conf["cpus"])
109 mems = conf_parser.str_to_list(scenarios_conf["mems"])
110 pkt_size = conf_parser.str_to_list(scenarios_conf["pkt_size"])
111 multistream = conf_parser.str_to_list(scenarios_conf["multistream"])
112 search_interval = scenarios_conf["search_interval"]
114 load_config["result_file"] = os.path.dirname(
115 os.path.abspath(__file__)) + "/test_case/result"
117 if len(cpus) != len(mems):
118 LOG.error("the cpus and mems config data number is not same!")
123 for i in range(0, len(cpus)):
124 case_config = {"vcpu": cpus[i],
125 "memory": int(mems[i]) * 1024,
126 "multistreams": multistream,
128 "search_interval": search_interval}
130 data_reply = do_test(case_config, Use_Dashboard,
131 test_config["contexts"])
132 result.append(data_reply)
134 LOG.info("Finished bottlenecks testcase")
135 LOG.info("The result data is %s", result)