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
19 import utils.infra_setup.runner.yardstick as Runner
20 from utils.parser import Parser as conf_parser
22 # --------------------------------------------------
23 # logging configuration
24 # --------------------------------------------------
25 LOG = log.Logger(__name__).getLogger()
28 "action": "runTestCase",
33 "testcase": "ping_bottlenecks"
39 Runner.yardstick_env_prepare(con_dic['contexts'])
42 def do_test(test_config, con_dic):
43 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
44 client = docker.from_env()
45 con = client.containers.get('bottleneckcompose_yardstick_1')
46 cmd = ('yardstick task start /home/opnfv/repos/yardstick/'
47 'samples/ping_bottlenecks.yaml --output-file ' + out_file)
48 stdout = con.exec_run(cmd)
50 with open(out_file) as f:
52 if data["status"] == 1:
53 LOG.info("yardstick run success")
56 LOG.error("yardstick error exit")
64 test_date = do_test(test_config, condic)
69 con_dic = test_config["load_manager"]
70 test_num = con_dic['scenarios']['num_stack'].split(',')
71 if con_dic["contexts"]["yardstick_test_ip"] is None:
72 con_dic["contexts"]["yardstick_test_ip"] =\
73 conf_parser.ip_parser("yardstick_test_ip")
80 pool = multiprocessing.Pool(processes=num)
81 for i in range(0, int(num)):
82 result.append(pool.apply_async(func_run, (con_dic, )))
86 out_num = out_num + float(res.get())
87 LOG.info("%s thread success %d times" % (num, out_num))
89 success_rate = ('%d/%d' % (out_num, num))
90 LOG.error('error thread: %d '
91 'the successful rate is %s'
92 % (num - out_num, success_rate))
94 LOG.info('END POSCA stress ping test')