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(runner_conf, out_file="yardstick.out", **parameter_info):
58 cidr = "/home/opnfv/repos/yardstick/" + \
59 runner_conf["yardstick_test_dir"] + \
60 runner_conf["yardstick_testcase"]
61 cmd = yardstick_task.yardstick_command_parser(debug=runner_DEBUG,
64 parameter=parameter_info)
68 def do_test(runner_conf, test_config, Use_Dashboard, context_conf):
69 yardstick_container = docker_env.yardstick_info['container']
70 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
71 cmd = testcase_parser(runner_conf, 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")
87 # data = json.load(output)
89 save_data = config_to_result(test_config, data)
90 if Use_Dashboard is True:
91 print("use dashboard")
92 # DashBoard.dashboard_send_data(context_conf, save_data)
94 # return save_data["data_body"]
99 load_config = test_config["load_manager"]
100 scenarios_conf = load_config["scenarios"]
101 runner_conf = test_config["runners"]
102 Use_Dashboard = False
105 if test_config["contexts"]["yardstick_ip"] is None:
106 load_config["contexts"]["yardstick_ip"] =\
107 conf_parser.ip_parser("yardstick_test_ip")
109 if "dashboard" in test_config["contexts"].keys():
110 if test_config["contexts"]["dashboard_ip"] is None:
111 test_config["contexts"]["dashboard_ip"] =\
112 conf_parser.ip_parser("dashboard")
113 LOG.info("Create Dashboard data")
115 # DashBoard.dashboard_system_bandwidth(test_config["contexts"])
117 tenants_conf = conf_parser.str_to_list(scenarios_conf["tenants"])
119 load_config["result_file"] = os.path.dirname(
120 os.path.abspath(__file__)) + "/test_case/result"
124 for tenants in tenants_conf:
125 case_config = {"tenants": tenants}
127 data_reply = do_test(runner_conf, case_config,
128 Use_Dashboard, test_config["contexts"])
129 result.append(data_reply)
131 LOG.info("Finished bottlenecks testcase")
132 LOG.info("The result data is %s", result)