Skip to content

Commit

Permalink
Apply "composite" attrs last
Browse files Browse the repository at this point in the history
Due to composite (read child class) attr dependence on the more fundamental
command arg attrs, we must apply them last in `applydict` otherwise side effects
triggered by setting, for example `logdir`, won't correctly modify the
underlying base attrs. Patch unit test to catch this in the future.

Fixes #5
  • Loading branch information
Tyler Goodlet committed Feb 11, 2016
1 parent 0ac4595 commit 5833d47
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pysipp/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def name(self):
mediaaddr = tuple_property(('media_addr', 'media_port'))
proxyaddr = tuple_property(('proxy_host', 'proxy_port'))
ipcaddr = tuple_property(('ipc_host', 'ipc_port'))
call_load = tuple_property(('limit', 'rate', 'call_count'))
call_load = tuple_property(('rate', 'limit', 'call_count'))

def __call__(self, block=True, timeout=180, runner=None, raise_exc=True,
**kwargs):
Expand Down Expand Up @@ -103,9 +103,9 @@ def logdir(self):

@logdir.setter
def logdir(self, dirpath):
assert path.isdir(dirpath)
assert path.isdir(dirpath), '{} is an invalid path'.format(dirpath)
for name, attr in self.iter_logfile_items():
# set all log files
# assemble all log file paths
setattr(self, name,
path.join(dirpath, "{}_{}".format(self.name, name)))

Expand All @@ -117,7 +117,7 @@ def logdir(self, dirpath):
def plays_media(self, patt='play_pcap_audio'):
"""Bool determining whether script plays media
"""
# FIXME: should be able to parse using -sd
# TODO: should be able to parse using -sd
if not self.scen_file:
return False

Expand Down
12 changes: 11 additions & 1 deletion pysipp/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,19 @@ def keys(cls):
return [key for key, descr in cls.descriptoritems()]

def applydict(self, d):
"""Apply contents of dict `d` onto local instance variables
"""Apply contents of dict `d` onto local instance variables.
Composite attrs (those not found in `_specparams`) are applied
last so that any inter-attr dependencies are (hopefully) resolved.
"""
composite = OrderedDict()
for name, value in d.items():
if name not in self._specparams:
composite[name] = value
else:
setattr(self, name, value)

# apply composites last
for name, value in composite.items():
setattr(self, name, value)

def todict(self):
Expand Down
2 changes: 1 addition & 1 deletion pysipp/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _signalall(self, signum):
signalled = OrderedDict()
for cmd, proc in self.iterprocs():
proc.send_signal(signum)
log.debug("sent signal '{}' to cmd '{}' with pid '{}'"
log.warn("sent signal '{}' to cmd '{}' with pid '{}'"
.format(signum, cmd, proc.pid))
signalled[cmd] = proc
return signalled
Expand Down
12 changes: 6 additions & 6 deletions tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def test_unreachable_uas(basic_scen):
uas = basic_scen.prepare()[0]
logdir = uas.logdir
# verify log file generation
for name, path in itertools.chain(
*[tuple(ua.iter_logfile_items()) for ua in basic_scen.prepare()]
):
assert tempfile.gettempdir() in path
assert logdir in path
assert os.path.isfile(path)
for ua in basic_scen.prepare():
for name, path in ua.iter_logfile_items():
assert tempfile.gettempdir() in path
assert ua.name in path
assert logdir in path
assert os.path.isfile(path)


# def test_async_run(scenwalk):
Expand Down

0 comments on commit 5833d47

Please sign in to comment.