-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.py
138 lines (115 loc) · 4.11 KB
/
run.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
#
# Copyright (c) 2007-2009 Corey Goldberg ([email protected])
# License: GNU GPLv3
#
# This file is part of Pylot.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. See the GNU General Public License
# for more details.
#
"""
usage: %prog [options] args
-a, --agents=NUM_AGENTS : number of agents
-d, --duration=DURATION : test duration in seconds
-r, --rampup=RAMPUP : rampup in seconds
-i, --interval=INTERVAL : interval in milliseconds
-x, --xmlfile=TEST_CASE_XML : test case xml file
-o, --output_dir=PATH : output directory
-n, --name=TESTNAME : name of test
-l, --log_msgs : log messages
-b, --blocking : blocking mode
-g, --gui : start GUI
-p, --port=PORT : xml-rpc listening port
"""
import sys
import core.config as config
import core.optionparse as optionparse
VERSION = '1.26'
# get default config parameters
agents = config.AGENTS
duration = config.DURATION
rampup = config.RAMPUP
interval = config.INTERVAL
tc_xml_filename = config.TC_XML_FILENAME
output_dir = config.OUTPUT_DIR
test_name = config.TEST_NAME
log_msgs = config.LOG_MSGS
blocking = config.BLOCKING
gui = config.GUI
# parse command line arguments
opt, args = optionparse.parse(__doc__)
if not opt and not args:
print 'version: %s' % VERSION
optionparse.exit()
try:
if opt.agents:
agents = int(opt.agents)
if opt.duration:
duration = int(opt.duration)
if opt.rampup:
rampup = int(opt.rampup)
if opt.interval:
interval = int(opt.interval)
if opt.xmlfile:
tc_xml_filename = opt.xmlfile
if opt.log_msgs:
log_msgs = True
if opt.output_dir:
output_dir = opt.output_dir
if opt.name:
test_name = opt.name
if opt.blocking:
blocking = True
if opt.gui:
gui = True
if opt.port:
port = int(opt.port)
except Exception, e:
print 'Invalid Argument'
sys.exit(1)
if gui: # gui mode
import ui.gui as pylot_gui
pylot_gui.main(agents, rampup, interval, duration, tc_xml_filename, log_msgs, VERSION, output_dir, test_name)
elif opt.port: # xml-rpc listener mode
import SimpleXMLRPCServer
import ui.blocking as pylot_blocking
class RemoteStarter:
def start(self):
return pylot_blocking.main(agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir, test_name)
rs = RemoteStarter()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(('localhost', port))
server.register_instance(rs)
print 'Pylot - listening on port', port
print 'waiting for xml-rpc start command...\n'
server.serve_forever()
elif blocking: # blocked output mode (stdout blocked until test finishes, then result is returned)
import ui.blocking as pylot_blocking
try:
pylot_blocking.main(agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir, test_name)
except KeyboardInterrupt:
print '\nInterrupt'
sys.exit(1)
else: # console/shell mode
import ui.console as pylot_console
print '\n-------------------------------------------------'
print 'Test parameters:'
print ' number of agents: %s' % agents
print ' test duration in seconds: %s' % duration
print ' rampup in seconds: %s' % rampup
print ' interval in milliseconds: %s' % interval
print ' test case xml: %s' % tc_xml_filename
print ' log messages: %s' % log_msgs
if test_name:
print ' test name: %s' % test_name
if output_dir:
print ' output directory: %s' % output_dir
print '\n'
try:
pylot_console.main(agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir, test_name)
except KeyboardInterrupt:
print '\nInterrupt'
sys.exit(1)