-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrannsaka.py
111 lines (101 loc) · 4 KB
/
rannsaka.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import argparse
import os
import subprocess
import sys
import time
import yaml
parser = argparse.ArgumentParser(description='rannsaka.py: API probe / testing tool for OpenStack projects')
parser.add_argument('--config',
action='store',
dest='config_file',
default='rannsaka.yml',
help='File defining test credentials, etc for rannsaka to use. NOT YET IMPLEMENTED'
)
parser.add_argument('--tempest-config',
action='store',
dest='tempest_config',
default='/opt/stack/tempest/etc/tempest.conf',
help='File defining test credentials, etc for rannsaka to use. NOT YET IMPLEMENTED'
)
parser.add_argument('--test-file', '-t',
action='store',
dest='worker_config',
default='test_files/basic_get.py',
help='locust file to execute'
)
parser.add_argument('--host',
action='store',
dest='locust_host',
default='http://127.0.0.1',
help='Test host'
)
parser.add_argument('--requests', '-r',
action='store',
type=int,
dest='request_count',
default=1,
help='Total number of requests to make across all workers'
)
parser.add_argument('--workers', '-w',
action='store',
type=int,
dest='worker_count',
default=1,
help='Number of workers to use for test execution.'
)
parser.add_argument('--hatch-rate',
action='store',
type=int,
dest='hatch_rate',
default=10,
help='Per-second hatch rate for test workers.'
)
parser.add_argument('--verbose', '-v',
action='count',
dest='verbose',
default=0,
help='Controls internal output. Utilize multiple times to increase output'
)
parser.add_argument('--debug', '-d',
action='store_true',
dest='debug',
default=False,
help='Controls debug output. NOT YET IMPLEMENTED'
)
# TODO: add --seed option
# This option must take values such as 'time' to allow for easier
# use of random seed values
args = parser.parse_args(sys.argv[1:])
if args.verbose:
for key, value in vars(args).items():
print('%s : %s' % (key, str(value)))
###################
# main
###################
# write common locust file for workers to read
locust_config_path = 'work/locust_common.yml'
with open(locust_config_path, 'w') as config_out:
locust_data = {}
locust_data['args'] = vars(args)
config_out.write(yaml.dump(locust_data, default_flow_style=False))
# call locust
cmd = "locust --no-web -c %s -f %s -n %s --host %s --hatch-rate %s" % (args.worker_count,
args.worker_config,
args.request_count,
args.locust_host,
args.hatch_rate)
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# Poll process for new output until finished
while True:
nextline = process.stdout.readline()
if nextline == '' and process.poll() != None:
break
sys.stdout.write(nextline)
sys.stdout.flush()
output = process.communicate()[0]
status = process.returncode
print "Test run finishing with exit code: %s" % status
print "Output:"
print output
print 'Fin!'
sys.exit(status)