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 from utils.parser import Parser as conf_parser
22 import utils.env_prepare.quota_prepare as quota_prepare
23 import utils.env_prepare.stack_prepare as stack_prepare
24 import testsuites.posca.testcase_dashboard.posca_stress_ping as DashBoard
25 # --------------------------------------------------
26 # logging configuration
27 # --------------------------------------------------
28 LOG = log.Logger(__name__).getLogger()
31 "action": "runTestCase",
36 "testcase": "ping_bottlenecks"
39 testfile = os.path.basename(__file__)
40 testcase, file_format = os.path.splitext(testfile)
44 stack_prepare._prepare_env_daemon()
45 quota_prepare.quota_env_prepare()
46 client = docker.from_env()
47 con = client.containers.get('bottleneckcompose_yardstick_1')
48 cmd = ('yardstick env prepare')
49 LOG.info("yardstick envrionment prepare!")
50 stdout = con.exec_run(cmd)
54 def do_test(test_config, con_dic):
55 out_file = ("/tmp/yardstick_" + str(uuid.uuid4()) + ".out")
56 client = docker.from_env()
57 con = client.containers.get('bottleneckcompose_yardstick_1')
58 cmd = ('yardstick task start /home/opnfv/repos/yardstick/'
59 'samples/ping_bottlenecks.yaml --output-file ' + out_file)
60 stdout = con.exec_run(cmd)
62 with open(out_file) as f:
64 if data["status"] == 1:
65 LOG.info("yardstick run success")
68 LOG.error("yardstick error exit")
74 def config_to_result(num, out_num, during_date):
77 test_result["number_of_users"] = float(num)
78 test_result["success_times"] = out_num
79 test_result["success_rate"] = out_num / num
80 test_result["duration_time"] = during_date
81 testdata["data_body"] = test_result
82 testdata["testcase"] = testcase
88 test_date = do_test(test_config, condic)
93 con_dic = test_config["load_manager"]
94 test_num = con_dic['scenarios']['num_stack'].split(',')
95 if con_dic["contexts"]["yardstick_test_ip"] is None:
96 con_dic["contexts"]["yardstick_test_ip"] =\
97 conf_parser.ip_parser("yardstick_test_ip")
99 if test_config["dashboard"]["dashboard"] == 'y':
100 if test_config["dashboard"]["dashboard_ip"] is None:
101 test_config["dashboard"]["dashboard_ip"] =\
102 conf_parser.ip_parser("dashboard")
103 LOG.info("Create Dashboard data")
104 DashBoard.posca_stress_ping(test_config["dashboard"])
106 LOG.info("bottlenecks envrionment prepare!")
108 LOG.info("yardstick envrionment prepare done!")
110 for value in test_num:
114 pool = multiprocessing.Pool(processes=num)
115 LOG.info("begin to run %s thread" % num)
117 starttime = datetime.datetime.now()
118 for i in range(0, int(num)):
119 result.append(pool.apply_async(func_run, (con_dic, )))
123 out_num = out_num + float(res.get())
125 endtime = datetime.datetime.now()
126 LOG.info("%s thread success %d times" % (num, out_num))
127 during_date = (endtime - starttime).seconds
129 data_reply = config_to_result(num, out_num, during_date)
130 if test_config['dashboard']['dashboard'] == 'y':
131 DashBoard.dashboard_send_data(test_config['dashboard'], data_reply)
132 conf_parser.result_to_file(data_reply, test_config["out_file"])
135 success_rate = ('%d/%d' % (out_num, num))
136 LOG.error('error thread: %d '
137 'the successful rate is %s'
138 % (num - out_num, success_rate))
140 LOG.info('END POSCA stress ping test')