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
18 import multiprocessing
21 import utils.infra_setup.runner.yardstick as Runner
22 from utils.parser import Parser as conf_parser
23 import testsuites.posca.testcase_dashboard.posca_stress_ping as DashBoard
24 # --------------------------------------------------
25 # logging configuration
26 # --------------------------------------------------
27 LOG = log.Logger(__name__).getLogger()
30 "action": "runTestCase",
35 "testcase": "ping_bottlenecks"
38 testfile = os.path.basename(__file__)
39 testcase, file_format = os.path.splitext(testfile)
43 client = docker.from_env()
44 con = client.containers.get('bottleneckcompose_yardstick_1')
45 cmd = ('yardstick env prepare')
46 stdout = con.exec_run(cmd)
50 def do_test(test_config, con_dic):
51 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
52 client = docker.from_env()
53 con = client.containers.get('bottleneckcompose_yardstick_1')
54 cmd = ('yardstick task start /home/opnfv/repos/yardstick/'
55 'samples/ping_bottlenecks.yaml --output-file ' + out_file)
56 stdout = con.exec_run(cmd)
58 with open(out_file) as f:
60 if data["status"] == 1:
61 LOG.info("yardstick run success")
64 LOG.error("yardstick error exit")
70 def config_to_result(num, out_num, during_date):
73 test_result["number_of_users"] = float(num)
74 test_result["success_times"] = out_num
75 test_result["success_rate"] = out_num / num
76 test_result["duration_time"] = during_date
77 testdata["data_body"] = test_result
78 testdata["testcase"] = testcase
84 test_date = do_test(test_config, condic)
89 con_dic = test_config["load_manager"]
90 test_num = con_dic['scenarios']['num_stack'].split(',')
91 if con_dic["contexts"]["yardstick_test_ip"] is None:
92 con_dic["contexts"]["yardstick_test_ip"] =\
93 conf_parser.ip_parser("yardstick_test_ip")
95 if test_config["dashboard"]["dashboard"] == 'y':
96 if test_config["dashboard"]["dashboard_ip"] is None:
97 test_config["dashboard"]["dashboard_ip"] =\
98 conf_parser.ip_parser("dashboard")
99 LOG.info("Create Dashboard data")
100 DashBoard.posca_stress_ping(test_config["dashboard"])
102 LOG.info("yardstick envrionment prepare!")
105 for value in test_num:
109 pool = multiprocessing.Pool(processes=num)
111 starttime = datetime.datetime.now()
112 for i in range(0, int(num)):
113 result.append(pool.apply_async(func_run, (con_dic, )))
117 out_num = out_num + float(res.get())
119 endtime = datetime.datetime.now()
120 LOG.info("%s thread success %d times" % (num, out_num))
121 during_date = (endtime - starttime).seconds
123 data_reply = config_to_result(num, out_num, during_date)
124 if test_config['dashboard']['dashboard'] == 'y':
125 DashBoard.dashboard_send_data(test_config['dashboard'], data_reply)
126 conf_parser.result_to_file(data_reply, test_config["out_file"])
129 success_rate = ('%d/%d' % (out_num, num))
130 LOG.error('error thread: %d '
131 'the successful rate is %s'
132 % (num - out_num, success_rate))
134 LOG.info('END POSCA stress ping test')