summaryrefslogtreecommitdiffstats
path: root/src/osmo_gsm_tester/process.py
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-04-10 03:45:30 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-04-10 05:09:23 +0200
commit5356d0adcef703dc965b03028e6c9a4afd23fb79 (patch)
tree8ca2a85ac637c0e6fca74120145e735ac4be6c91 /src/osmo_gsm_tester/process.py
parent85eb324165a8f4076fdd58f9d84b6c0443b5beb9 (diff)
trying to get sysmobts to work and various details
I know that these commit messages aren't very good, but the code is not stable yet, so I'm not bothering with details. Change-Id: I2d5e5f4a5407725d71093cbd71ef97b271eb8197
Diffstat (limited to 'src/osmo_gsm_tester/process.py')
-rw-r--r--src/osmo_gsm_tester/process.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/osmo_gsm_tester/process.py b/src/osmo_gsm_tester/process.py
index 8152ff0..78814c0 100644
--- a/src/osmo_gsm_tester/process.py
+++ b/src/osmo_gsm_tester/process.py
@@ -22,7 +22,7 @@ import time
import subprocess
import signal
-from . import log
+from . import log, test
from .util import Dir
class Process(log.Origin):
@@ -166,7 +166,9 @@ class Process(log.Origin):
if self.result is not None:
self.cleanup()
- def is_running(self):
+ def is_running(self, poll_first=True):
+ if poll_first:
+ self.poll()
return self.process_obj is not None and self.result is None
def get_output(self, which):
@@ -178,9 +180,12 @@ class Process(log.Origin):
return f2.read()
def get_output_tail(self, which, tail=10, prefix=''):
- out = self.get_output(which).splitlines()
+ out = self.get_output(which)
+ if not out:
+ return None
+ out = out.splitlines()
tail = min(len(out), tail)
- return ('\n' + prefix).join(out[-tail:])
+ return prefix + ('\n' + prefix).join(out[-tail:])
def get_stdout(self):
return self.get_output('stdout')
@@ -194,28 +199,32 @@ class Process(log.Origin):
def get_stderr_tail(self, tail=10, prefix=''):
return self.get_output_tail('stderr', tail, prefix)
- def terminated(self):
- self.poll()
+ def terminated(self, poll_first=True):
+ if poll_first:
+ self.poll()
return self.result is not None
- def wait(self):
- self.process_obj.wait()
- self.poll()
+ def wait(self, timeout=300):
+ test.wait(self.terminated, timeout=timeout)
class RemoteProcess(Process):
- def __init__(self, remote_host, remote_cwd, *process_args, **process_kwargs):
- super().__init__(*process_args, **process_kwargs)
+ def __init__(self, name, run_dir, remote_host, remote_cwd, popen_args, **popen_kwargs):
+ super().__init__(name, run_dir, popen_args, **popen_kwargs)
self.remote_host = remote_host
self.remote_cwd = remote_cwd
# hacky: instead of just prepending ssh, i.e. piping stdout and stderr
# over the ssh link, we should probably run on the remote side,
# monitoring the process remotely.
- self.popen_args = ['ssh', '-t', self.remote_host,
- 'cd "%s"; %s' % (self.remote_cwd,
- ' '.join(['"%s"' % arg for arg in self.popen_args]))]
+ if self.remote_cwd:
+ cd = 'cd "%s"; ' % self.remote_cwd
+ else:
+ cd = ''
+ self.popen_args = ['ssh', self.remote_host,
+ '%s%s' % (cd,
+ ' '.join(self.popen_args))]
self.dbg(self.popen_args, dir=self.run_dir, conf=self.popen_kwargs)
# vim: expandtab tabstop=4 shiftwidth=4