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 posca ping stress test script
11 This file contain several part:
12 Frist is create a script to realize several threading run'''
14 import utils.logger as log
23 from utils.parser import Parser as conf_parser
24 import utils.env_prepare.quota_prepare as quota_prepare
25 import utils.env_prepare.stack_prepare as stack_prepare
26 import utils.infra_setup.runner.yardstick as runner_yardstick
28 import testsuites.posca.testcase_dashboard.posca_stress_ping as DashBoard
29 import utils.infra_setup.runner.docker_env as docker_env
30 # --------------------------------------------------
31 # logging configuration
32 # --------------------------------------------------
33 LOG = log.Logger(__name__).getLogger()
36 "action": "runTestCase",
41 "testcase": "ping_bottlenecks"
44 testfile = os.path.basename(__file__)
45 testcase, file_format = os.path.splitext(testfile)
46 cidr = "/home/opnfv/repos/yardstick/samples/ping_bottlenecks.yaml"
52 def env_pre(test_config):
53 test_yardstick = False
54 if "yardstick" in test_config["contexts"].keys():
56 stack_prepare._prepare_env_daemon(test_yardstick)
57 quota_prepare.quota_env_prepare()
58 LOG.info("yardstick environment prepare!")
59 if(test_config["contexts"]['yardstick_envpre']):
60 stdout = runner_yardstick.yardstick_image_prepare()
65 func_name = sys._getframe().f_code.co_name
66 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
68 yardstick_container = docker_env.yardstick_info['container']
69 cmd = runner_yardstick.yardstick_command_parser(debug=runner_DEBUG,
72 parameter=parameter_info)
73 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
77 while loop_value < 60:
79 loop_value = loop_value + 1
80 with open(out_file) as f:
82 if data["result"]["criteria"] == "PASS":
83 LOG.info("yardstick run success")
87 LOG.error("yardstick error exit")
90 q.put((out_value, func_name))
94 def config_to_result(num, out_num, during_date, result):
97 test_result["number_of_stacks"] = float(num)
98 test_result["success_times"] = out_num
99 test_result["success_rate"] = out_num / num
100 test_result["duration_time"] = during_date
101 test_result["result"] = result
102 testdata["data_body"] = test_result
103 testdata["testcase"] = testcase
107 def func_run(condic):
108 test_date = do_test()
112 def run(test_config):
113 con_dic = test_config["load_manager"]
114 test_num = con_dic['scenarios']['num_stack'].split(',')
115 if test_config["contexts"]["yardstick_ip"] is None:
116 con_dic["contexts"]["yardstick_ip"] =\
117 conf_parser.ip_parser("yardstick_test_ip")
119 if "dashboard" in test_config["contexts"].keys():
120 if test_config["contexts"]["dashboard_ip"] is None:
121 test_config["contexts"]["dashboard_ip"] =\
122 conf_parser.ip_parser("dashboard")
123 LOG.info("Create Dashboard data")
124 DashBoard.posca_stress_ping(test_config["contexts"])
127 LOG.info("yardstick environment prepare done!")
129 for value in test_num:
133 # pool = multiprocessing.Pool(processes=num)
135 LOG.info("begin to run %s thread" % num)
137 starttime = datetime.datetime.now()
139 for i in xrange(0, num):
140 temp_thread = threading.Thread(target=func_run, args=(str(i),))
141 threadings.append(temp_thread)
143 for one_thread in threadings:
146 result.append(q.get())
148 out_num = out_num + float(item[0])
150 endtime = datetime.datetime.now()
151 LOG.info("%s thread success %d times" % (num, out_num))
152 during_date = (endtime - starttime).seconds
154 if out_num >= con_dic["scenarios"]['threshhold']:
155 criteria_result = "PASS"
157 criteria_result = "FAIL"
159 data_reply = config_to_result(num, out_num, during_date,
161 if "dashboard" in test_config["contexts"].keys():
162 DashBoard.dashboard_send_data(test_config['contexts'], data_reply)
163 conf_parser.result_to_file(data_reply, test_config["out_file"])
165 if criteria_result is "FAIL":
167 LOG.info('END POSCA stress ping test')
168 return criteria_result