summaryrefslogtreecommitdiffstats
path: root/src/osmo_gsm_tester/process.py
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-10-01 11:27:55 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2018-10-02 13:10:36 +0200
commite4358a9a36b2ce16c322ec4e061d2e86ccdbd59c (patch)
tree7bec52c2a376a6c5f3700a6b654b42909f22d9de /src/osmo_gsm_tester/process.py
parent90b050764a6d4fb26f48f4389473a5cb601588ec (diff)
Make code copying inst through ssh generic
It can later on be used by other classes that need to run binaries in inst remotely. Change-Id: I838b999528695207e1147cfe76e6f7aaf3b1dd53
Diffstat (limited to 'src/osmo_gsm_tester/process.py')
-rw-r--r--src/osmo_gsm_tester/process.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/osmo_gsm_tester/process.py b/src/osmo_gsm_tester/process.py
index ad2405d..9db9241 100644
--- a/src/osmo_gsm_tester/process.py
+++ b/src/osmo_gsm_tester/process.py
@@ -233,4 +233,41 @@ class RemoteProcess(Process):
' '.join(self.popen_args))]
self.dbg(self.popen_args, dir=self.run_dir, conf=self.popen_kwargs)
+
+def run_local_sync(run_dir, name, popen_args):
+ run_dir =run_dir.new_dir(name)
+ proc = Process(name, run_dir, popen_args)
+ proc.launch()
+ proc.wait()
+ if proc.result != 0:
+ log.ctx(proc)
+ raise log.Error('Exited in error')
+
+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)
+ proc.launch()
+ proc.wait()
+ if proc.result != 0:
+ log.ctx(proc)
+ raise log.Error('Exited in error')
+
+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)))
+
+def copy_inst_ssh(run_dir, inst, remote_dir, remote_user, remote_addr, remote_rundir_append, cfg_file_name):
+ remote_inst = Dir(remote_dir.child(os.path.basename(str(inst))))
+ remote_dir_str = str(remote_dir)
+ run_remote_sync(run_dir, remote_user, remote_addr, 'rm-remote-dir', ('test', '!', '-d', remote_dir_str, '||', 'rm', '-rf', remote_dir_str))
+ run_remote_sync(run_dir, remote_user, remote_addr, 'mk-remote-dir', ('mkdir', '-p', remote_dir_str))
+ scp(run_dir, remote_user, remote_addr, 'scp-inst-to-remote', str(inst), remote_dir_str)
+
+ remote_run_dir = remote_dir.child(remote_rundir_append)
+ run_remote_sync(run_dir, remote_user, remote_addr, 'mk-remote-run-dir', ('mkdir', '-p', remote_run_dir))
+
+ remote_config_file = remote_dir.child(os.path.basename(cfg_file_name))
+ scp(run_dir, remote_user, remote_addr, 'scp-cfg-to-remote', cfg_file_name, remote_config_file)
+ return remote_inst
+
# vim: expandtab tabstop=4 shiftwidth=4