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."""
15 import utils.logger as log
20 from utils.parser import Parser as conf_parser
21 import utils.env_prepare.quota_prepare as quota_prepare
22 import utils.env_prepare.stack_prepare as stack_prepare
24 import utils.infra_setup.runner.docker_env as docker_env
25 import utils.infra_setup.runner.yardstick as yardstick_task
26 # --------------------------------------------------
27 # logging configuration
28 # --------------------------------------------------
29 LOG = log.Logger(__name__).getLogger()
32 testcase_name = ("tc_heat_rfc2544_ipv4_1rule_"
33 "1flow_64B_trex_correlated_traffic_scale_out")
34 testfile = os.path.basename(__file__)
35 testcase, file_format = os.path.splitext(testfile)
36 cidr = ("/home/opnfv/repos/yardstick/samples/vnf_samples/nsut/acl/"
37 "tc_heat_rfc2544_ipv4_1rule_1flow_64B_trex_correlated_"
38 "traffic_scale_out.yaml")
42 def env_pre(test_config):
43 test_yardstick = False
44 if "yardstick" in test_config["contexts"].keys():
47 stack_prepare._prepare_env_daemon(test_yardstick)
48 quota_prepare.quota_env_prepare()
49 cmd = ('yardstick env prepare')
50 LOG.info("yardstick environment prepare!")
51 print docker_env.yardstick_info['container']
52 if(test_config["contexts"]['yardstick_envpre']):
53 yardstick_container = docker_env.yardstick_info['container']
54 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
58 def config_to_result(test_config, test_result):
61 out_data = test_result["result"]["testcases"]
62 test_data = out_data[testcase_name]["tc_data"]
63 for result in test_data:
65 testdata["sequence"] = result["sequence"]
66 traffic_result = result["data"]["tg__0"]
68 testdata["RxThroughput"] = traffic_result["RxThroughput"]
69 testdata["TxThroughput"] = traffic_result["TxThroughput"]
70 testdata["DropPercentage"] = traffic_result["DropPercentage"]
71 final_data.append(testdata)
75 def testcase_parser(out_file="yardstick.out", **parameter_info):
76 cmd = yardstick_task.yardstick_command_parser(debug=runner_DEBUG,
79 parameter=parameter_info)
83 def do_test(test_config, Use_Dashboard, context_conf):
84 yardstick_container = docker_env.yardstick_info['container']
85 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
86 cmd = testcase_parser(out_file=out_file, **test_config)
88 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
91 while loop_value < 60:
93 loop_value = loop_value + 1
94 with open(out_file) as f:
96 if data["status"] == 1:
97 LOG.info("yardstick run success")
99 elif data["status"] == 2:
100 LOG.error("yardstick error exit")
102 # data = json.load(output)
104 save_data = config_to_result(test_config, data)
105 print("^^^^^^^^^^^^^^^^^^^^^^^^^")
107 if Use_Dashboard is True:
108 print("use dashboard")
109 # DashBoard.dashboard_send_data(context_conf, save_data)
111 # return save_data["data_body"]
115 def run(test_config):
117 load_config = test_config["load_manager"]
118 scenarios_conf = load_config["scenarios"]
121 if test_config["contexts"]["yardstick_ip"] is None:
122 load_config["contexts"]["yardstick_ip"] =\
123 conf_parser.ip_parser("yardstick_test_ip")
125 if "dashboard" in test_config["contexts"].keys():
126 if test_config["contexts"]["dashboard_ip"] is None:
127 test_config["contexts"]["dashboard_ip"] =\
128 conf_parser.ip_parser("dashboard")
129 LOG.info("Create Dashboard data")
132 num_vnfs = conf_parser.str_to_list(scenarios_conf["number_vnfs"])
133 iterations = scenarios_conf["iterations"]
134 interval = scenarios_conf["interval"]
135 load_config["result_file"] = os.path.dirname(
136 os.path.abspath(__file__)) + "/test_case/result"
140 for i in range(0, len(num_vnfs)):
142 case_config = {"num_vnfs": int(num_vnfs[i]),
143 "iterations": iterations,
144 "interval": interval}
145 data_reply = do_test(case_config, Use_Dashboard,
146 test_config["contexts"])
147 result.append(data_reply)
149 LOG.info("Finished bottlenecks testcase")
150 LOG.info("The result data is %s", result)