15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
16
17
17
# Authors : Tyler Goodlet
18
- '''
18
+ """
19
19
pysipp - a python wrapper for launching SIPp
20
- '''
20
+ """
21
21
import sys
22
22
from os .path import dirname
23
23
from . import plugin , netplug , agent
24
24
from .load import iter_scen_dirs
25
25
from .agent import client , server
26
26
27
27
28
- __package__ = ' pysipp'
29
- __author__ = ' Tyler Goodlet ([email protected] )'
28
+ __package__ = " pysipp"
29
+ __author__ = " Tyler Goodlet ([email protected] )"
30
30
31
- __all__ = [' walk' , ' client' , ' server' , ' plugin' ]
31
+ __all__ = [" walk" , " client" , " server" , " plugin" ]
32
32
33
33
34
- def walk (rootpath , delay_conf_scen = False , autolocalsocks = True ,
35
- ** scenkwargs ):
34
+ def walk (rootpath , delay_conf_scen = False , autolocalsocks = True , ** scenkwargs ):
36
35
"""SIPp scenario generator.
37
36
38
37
Build and return scenario objects for each scenario directory.
@@ -48,23 +47,21 @@ def walk(rootpath, delay_conf_scen=False, autolocalsocks=True,
48
47
assert dirname (confpy .__file__ ) == path
49
48
50
49
# predicate hook based filtering
51
- res = hooks .pysipp_load_scendir (
52
- path = path , xmls = xmls , confpy = confpy )
50
+ res = hooks .pysipp_load_scendir (path = path , xmls = xmls , confpy = confpy )
53
51
if res and not all (res ):
54
52
continue
55
53
56
54
agents = []
57
55
for xml in xmls :
58
- if ' uac' in xml .lower ():
56
+ if " uac" in xml .lower ():
59
57
ua = agent .client (scen_file = xml )
60
58
agents .append (ua )
61
- elif ' uas' in xml .lower ():
59
+ elif " uas" in xml .lower ():
62
60
ua = agent .server (scen_file = xml )
63
61
agents .insert (0 , ua ) # servers are always launched first
64
62
else :
65
63
raise ValueError (
66
- "xml script must contain one of 'uac' or 'uas':\n {}"
67
- .format (xml )
64
+ "xml script must contain one of 'uac' or 'uas':\n {}" .format (xml )
68
65
)
69
66
70
67
if delay_conf_scen :
@@ -81,17 +78,13 @@ def walk(rootpath, delay_conf_scen=False, autolocalsocks=True,
81
78
yield path , scen
82
79
83
80
84
- def scenario (dirpath = None , proxyaddr = None , autolocalsocks = True ,
85
- ** scenkwargs ):
81
+ def scenario (dirpath = None , proxyaddr = None , autolocalsocks = True , ** scenkwargs ):
86
82
"""Return a single Scenario loaded from `dirpath` if provided else the
87
83
basic default call flow.
88
84
"""
89
85
if dirpath :
90
86
# deliver single scenario from dir
91
- path , scen = next (
92
- walk (dirpath , autolocalsocks = autolocalsocks ,
93
- ** scenkwargs )
94
- )
87
+ path , scen = next (walk (dirpath , autolocalsocks = autolocalsocks , ** scenkwargs ))
95
88
else :
96
89
with plugin .register ([netplug ] if autolocalsocks else []):
97
90
# deliver the default scenario bound to loopback sockets
@@ -100,13 +93,13 @@ def scenario(dirpath=None, proxyaddr=None, autolocalsocks=True,
100
93
101
94
# same as above
102
95
scen = plugin .mng .hook .pysipp_conf_scen_protocol (
103
- agents = [uas , uac ], confpy = None ,
96
+ agents = [uas , uac ],
97
+ confpy = None ,
104
98
scenkwargs = scenkwargs ,
105
99
)
106
100
107
101
if proxyaddr is not None :
108
- assert isinstance (proxyaddr , tuple ), (
109
- 'proxyaddr must be a (addr, port) tuple' )
102
+ assert isinstance (proxyaddr , tuple ), "proxyaddr must be a (addr, port) tuple"
110
103
scen .clientdefaults .proxyaddr = proxyaddr
111
104
112
105
return scen
@@ -123,8 +116,7 @@ def pysipp_load_scendir(path, xmls, confpy):
123
116
124
117
@plugin .hookimpl
125
118
def pysipp_conf_scen_protocol (agents , confpy , scenkwargs ):
126
- """Perform default configuration rule set
127
- """
119
+ """Perform default configuration rule set"""
128
120
# more sanity
129
121
if confpy :
130
122
ua = agents [0 ]
@@ -138,13 +130,19 @@ def pysipp_conf_scen_protocol(agents, confpy, scenkwargs):
138
130
scen = agent .Scenario (agents , confpy = confpy )
139
131
140
132
# order the agents for launch
141
- agents = list (hooks .pysipp_order_agents (
142
- agents = scen .agents , clients = scen .clients ,
143
- servers = scen .servers )) or agents
133
+ agents = (
134
+ list (
135
+ hooks .pysipp_order_agents (
136
+ agents = scen .agents , clients = scen .clients , servers = scen .servers
137
+ )
138
+ )
139
+ or agents
140
+ )
144
141
145
142
# create scenario wrapper
146
143
scen = hooks .pysipp_new_scen (
147
- agents = agents , confpy = confpy , scenkwargs = scenkwargs )
144
+ agents = agents , confpy = confpy , scenkwargs = scenkwargs
145
+ )
148
146
149
147
# configure scenario
150
148
hooks .pysipp_conf_scen (agents = scen .agents , scen = scen )
@@ -158,10 +156,8 @@ def pysipp_conf_scen_protocol(agents, confpy, scenkwargs):
158
156
159
157
@plugin .hookimpl
160
158
def pysipp_order_agents (agents , clients , servers ):
161
- """Lexicographically sort agents by name and always start servers first
162
- """
163
- return (agents [name ] for name in
164
- sorted (servers ) + sorted (clients ))
159
+ """Lexicographically sort agents by name and always start servers first"""
160
+ return (agents [name ] for name in sorted (servers ) + sorted (clients ))
165
161
166
162
167
163
@plugin .hookimpl
@@ -171,14 +167,13 @@ def pysipp_new_scen(agents, confpy, scenkwargs):
171
167
172
168
@plugin .hookimpl (trylast = True )
173
169
def pysipp_conf_scen (agents , scen ):
174
- """Default validation logic and routing with media
175
- """
170
+ """Default validation logic and routing with media"""
176
171
if scen .servers :
177
172
# point all clients to send requests to 'primary' server agent
178
173
# if they aren't already
179
- servers_addr = scen .serverdefaults .get (' srcaddr' , (' 127.0.0.1' , 5060 ))
174
+ servers_addr = scen .serverdefaults .get (" srcaddr" , (" 127.0.0.1" , 5060 ))
180
175
uas = scen .prepare_agent (list (scen .servers .values ())[0 ])
181
- scen .clientdefaults .setdefault (' destaddr' , uas .srcaddr or servers_addr )
176
+ scen .clientdefaults .setdefault (" destaddr" , uas .srcaddr or servers_addr )
182
177
183
178
elif not scen .clientdefaults .proxyaddr :
184
179
# no servers in scenario so point proxy addr to remote socket addr
0 commit comments