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
27 import testsuites.posca.testcase_dashboard.posca_stress_ping as DashBoard
28 import utils.infra_setup.runner.docker_env as docker_env
29 # --------------------------------------------------
30 # logging configuration
31 # --------------------------------------------------
32 LOG = log.Logger(__name__).getLogger()
35 "action": "runTestCase",
40 "testcase": "ping_bottlenecks"
43 testfile = os.path.basename(__file__)
44 testcase, file_format = os.path.splitext(testfile)
49 def env_pre(test_config):
50 test_yardstick = False
51 if "yardstick" in test_config["contexts"].keys():
53 stack_prepare._prepare_env_daemon(test_yardstick)
54 quota_prepare.quota_env_prepare()
55 cmd = ('yardstick env prepare')
56 LOG.info("yardstick environment prepare!")
57 if(test_config["contexts"]['yardstick_envpre']):
58 yardstick_container = docker_env.yardstick_info['container']
59 stdout = docker_env.docker_exec_cmd(yardstick_container, cmd)
64 func_name = sys._getframe().f_code.co_name
65 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
66 yardstick_container = docker_env.yardstick_info['container']
67 cmd = ('yardstick task start /home/opnfv/repos/yardstick/'
68 'samples/ping_bottlenecks.yaml --output-file ' + out_file)
69 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")
82 elif data["status"] == 2:
83 LOG.error("yardstick error exit")
86 q.put((out_value, func_name))
90 def config_to_result(num, out_num, during_date, result):
93 test_result["number_of_stacks"] = float(num)
94 test_result["success_times"] = out_num
95 test_result["success_rate"] = out_num / num
96 test_result["duration_time"] = during_date
97 test_result["result"] = result
98 testdata["data_body"] = test_result
99 testdata["testcase"] = testcase
103 def func_run(condic):
104 test_date = do_test()
108 def run(test_config):
109 con_dic = test_config["load_manager"]
110 test_num = con_dic['scenarios']['num_stack'].split(',')
111 if test_config["contexts"]["yardstick_ip"] is None:
112 con_dic["contexts"]["yardstick_ip"] =\
113 conf_parser.ip_parser("yardstick_test_ip")
115 if "dashboard" in test_config["contexts"].keys():
116 if test_config["contexts"]["dashboard_ip"] is None:
117 test_config["contexts"]["dashboard_ip"] =\
118 conf_parser.ip_parser("dashboard")
119 LOG.info("Create Dashboard data")
120 DashBoard.posca_stress_ping(test_config["contexts"])
123 LOG.info("yardstick environment prepare done!")
125 for value in test_num:
129 # pool = multiprocessing.Pool(processes=num)
131 LOG.info("begin to run %s thread" % num)
133 starttime = datetime.datetime.now()
135 for i in xrange(0, num):
136 temp_thread = threading.Thread(target=func_run, args=(str(i),))
137 threadings.append(temp_thread)
139 for one_thread in threadings:
142 result.append(q.get())
144 out_num = out_num + float(item[0])
146 endtime = datetime.datetime.now()
147 LOG.info("%s thread success %d times" % (num, out_num))
148 during_date = (endtime - starttime).seconds
150 if out_num >= con_dic["scenarios"]['threshhold']:
151 criteria_result = "PASS"
153 criteria_result = "FAIL"
155 data_reply = config_to_result(num, out_num, during_date,
157 if "dashboard" in test_config["contexts"].keys():
158 DashBoard.dashboard_send_data(test_config['contexts'], data_reply)
159 conf_parser.result_to_file(data_reply, test_config["out_file"])
161 if criteria_result is "FAIL":
163 LOG.info('END POSCA stress ping test')
164 return criteria_result