process: Move standalone run_local_sync as method of Process

Change-Id: Ib2b3fd39db5400a93a8caabae367dac3e3250247
This commit is contained in:
Pau Espin 2018-11-12 18:15:30 +01:00
parent 64f0b1b114
commit 79df739c07
3 changed files with 20 additions and 16 deletions

View File

@ -105,7 +105,7 @@ class IPerf3Client(log.Origin):
self.process = process.NetNSProcess(self.name(), self.run_dir, netns, popen_args, env={})
else:
self.process = process.Process(self.name(), self.run_dir, popen_args, env={})
process.run_proc_sync(self.process)
self.process.launch_sync()
return self.get_results()
def get_results(self):

View File

@ -636,7 +636,7 @@ class Modem(log.Origin):
def run_netns_wait(self, name, popen_args):
proc = process.NetNSProcess(name, self.run_dir.new_dir(name), self.netns(), popen_args,
env={})
process.run_proc_sync(proc)
proc.launch_sync()
def setup_context_data_plane(self, ctx_id):
self.dbg('setup_context_data', path=ctx_id)

View File

@ -77,6 +77,21 @@ class Process(log.Origin):
self.set_name(self.name_str, pid=self.process_obj.pid)
self.log('Launched')
def launch_sync(self):
'''
calls launch() method and block waiting for it to finish, serving the
mainloop meanwhile.
'''
try:
self.launch()
self.wait()
except Exception as e:
self.terminate()
raise e
if self.result != 0:
log.ctx(self)
raise log.Error('Exited in error')
def respawn(self):
self.dbg('respawn')
assert not self.is_running()
@ -255,31 +270,20 @@ class NetNSProcess(Process):
run_local_netns_sync(self.run_dir, self.name()+"-kill", self.netns, kill_cmd)
def run_proc_sync(proc):
try:
proc.launch()
proc.wait()
except Exception as e:
proc.terminate()
raise e
if proc.result != 0:
log.ctx(proc)
raise log.Error('Exited in error')
def run_local_sync(run_dir, name, popen_args):
run_dir =run_dir.new_dir(name)
proc = Process(name, run_dir, popen_args)
run_proc_sync(proc)
proc.launch_sync()
def run_local_netns_sync(run_dir, name, netns, popen_args):
run_dir =run_dir.new_dir(name)
proc = NetNSProcess(name, run_dir, netns, popen_args)
run_proc_sync(proc)
proc.launch_sync()
def run_remote_sync(run_dir, remote_user, remote_addr, name, popen_args, remote_cwd=None):
run_dir = run_dir.new_dir(name)
proc = RemoteProcess(name, run_dir, remote_user, remote_addr, remote_cwd, popen_args)
run_proc_sync(proc)
proc.launch_sync()
def scp(run_dir, remote_user, remote_addr, name, local_path, remote_path):
run_local_sync(run_dir, name, ('scp', '-r', local_path, '%s@%s:%s' % (remote_user, remote_addr, remote_path)))