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.'''
20 import multiprocessing
21 import utils.logger as log
22 from utils.parser import Parser as conf_parser
23 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
27 # --------------------------------------------------
28 # logging configuration
29 # --------------------------------------------------
30 LOG = log.Logger(__name__).getLogger()
32 testfile = os.path.basename(__file__)
33 testcase, file_format = os.path.splitext(testfile)
34 # cidr = "/home/opnfv/repos/yardstick/samples/pvp_throughput_bottlenecks.yaml"
40 LOG.info("yardstick environment prepare!")
41 stack_prepare._prepare_env_daemon(True)
44 def config_to_result(test_config, test_result):
47 out_data = test_result["result"]["testcases"]
48 test_data = out_data["pvp_throughput_bottlenecks"]["tc_data"]
49 for result in test_data:
51 testdata["vcpu"] = test_config["vcpu"]
52 testdata["memory"] = test_config["memory"]
53 testdata["nrFlows"] = result["data"]["nrFlows"]
54 testdata["packet_size"] = result["data"]["packet_size"]
55 testdata["throughput"] = result["data"]["throughput_rx_mbps"]
56 final_data.append(testdata)
60 def testcase_parser(runner_conf, out_file="yardstick.out", **parameter_info):
61 cidr = "/home/opnfv/repos/yardstick/" + \
62 runner_conf["yardstick_test_dir"] + \
63 runner_conf["yardstick_testcase"]
64 cmd = yardstick_task.yardstick_command_parser(debug=runner_DEBUG,
67 parameter=parameter_info)
71 def do_test(runner_conf, test_config, Use_Dashboard, context_conf):
72 yardstick_container = docker_env.yardstick_info['container']
73 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
74 cmd = testcase_parser(runner_conf, out_file=out_file, **test_config)
76 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
79 while loop_value < 60:
81 loop_value = loop_value + 1
82 with open(out_file) as f:
84 if data["status"] == 1:
85 LOG.info("yardstick run success")
87 elif data["status"] == 2:
88 LOG.error("yardstick error exit")
90 # data = json.load(output)
92 save_data = config_to_result(test_config, data)
93 if Use_Dashboard is True:
94 print("use dashboard")
95 # DashBoard.dashboard_send_data(context_conf, save_data)
97 # return save_data["data_body"]
101 def run(test_config):
102 load_config = test_config["load_manager"]
103 scenarios_conf = load_config["scenarios"]
104 runner_conf = test_config["runners"]
105 Use_Dashboard = False
108 if test_config["contexts"]["yardstick_ip"] is None:
109 load_config["contexts"]["yardstick_ip"] =\
110 conf_parser.ip_parser("yardstick_test_ip")
112 if "dashboard" in test_config["contexts"].keys():
113 if test_config["contexts"]["dashboard_ip"] is None:
114 test_config["contexts"]["dashboard_ip"] =\
115 conf_parser.ip_parser("dashboard")
116 LOG.info("Create Dashboard data")
118 # DashBoard.dashboard_system_bandwidth(test_config["contexts"])
120 resources = conf_parser.str_to_list(scenarios_conf["resources"])
121 initial = conf_parser.str_to_list(scenarios_conf["initial"])
122 threshhold = conf_parser.str_to_list(scenarios_conf["threshhold"])
123 timeout = conf_parser.str_to_list(scenarios_conf["timeout"])
124 SLA = conf_parser.str_to_list(scenarios_conf["SLA"])
125 case_config = {"SLA": SLA,
126 "resources": resources}
128 process_queue = Queue.Queue()
130 load_config["result_file"] = os.path.dirname(
131 os.path.abspath(__file__)) + "/test_case/result"
136 tenant_number = threshhold
138 tenant_number = initial
140 while runner_switch is True:
141 for tenant in range(0, tenant_number):
142 process = multiprocessing.Process(target=do_test,
146 test_config["contexts"],
149 process_queue.put(process)
151 result = result + tenant_number
152 tenant_number = threshhold
155 while process_queue.qsize():
156 process = process_queue.get()
159 if result is initial:
162 result = result - threshhold
164 LOG.info("Finished bottlenecks testcase")
165 LOG.info("The result data is %s", result)