aboutsummaryrefslogtreecommitdiff
path: root/rumba/ssh_support.py
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2017-11-16 14:31:58 +0100
committerMarco Capitani <m.capitani@nextworks.it>2017-11-16 14:57:33 +0100
commitc884a5b8c1e2a2f4d610cae7b9aa547b95424210 (patch)
tree33f06897a76950822d46d32d09ed08a1d87a410c /rumba/ssh_support.py
parent986676ade9ffe4738734566c50eeed4b0ce7dd5f (diff)
downloadrumba-c884a5b8c1e2a2f4d610cae7b9aa547b95424210.tar.gz
rumba-c884a5b8c1e2a2f4d610cae7b9aa547b95424210.zip
testbed-qemu: refactor swapout to use call_in_parallel
minor: also cleaned up some commented old code
Diffstat (limited to 'rumba/ssh_support.py')
-rw-r--r--rumba/ssh_support.py74
1 files changed, 30 insertions, 44 deletions
diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py
index 9990fc9..39dbf5f 100644
--- a/rumba/ssh_support.py
+++ b/rumba/ssh_support.py
@@ -165,50 +165,36 @@ def execute_commands(testbed, ssh_config, commands, time_out=3):
ssh_config.proxy_client = proxy_client
o = ""
- try:
- for command in commands:
- logger.debug("%s@%s:%s >> %s" % (testbed.username,
- ssh_config.hostname,
- ssh_config.port,
- command))
- envars = '. /etc/profile;'
- command = envars + ' ' + command
- chan = ssh_config.client.get_transport().open_session()
- stdout = chan.makefile()
- stderr = chan.makefile_stderr()
- try:
- chan.exec_command(command)
- except paramiko.ssh_exception.SSHException as e:
- raise SSHException('Failed to execute command')
- o = _print_stream(stdout)
- if chan.recv_exit_status() != 0:
- # Get ready for printing stdout and stderr
- if o != "":
- list_print = ['**** STDOUT:']
- list_print += o.split('\\n')
- else:
- list_print = []
- e = _print_stream(stderr)
- if e != "":
- list_print.append('**** STDERR:')
- list_print += e.split('\\n')
- raise SSHException('A remote command returned an error. '
- 'Output:\n\n\t' +
- '\n\t'.join(list_print) + '\n')
- return o
- finally:
- ##
- # The following lines are a fix to make this work under
- # true multiprocessing. Right now we are using
- # dummy multiprocessing (i.e. threading), so not needed.
- # They have been kept here in case we want to get back to it.
- ##
- # ssh_config.client.close()
- # if ssh_config.proxy_client is not None:
- # ssh_config.proxy_client.close()
- # ssh_config.client = None
- # ssh_config.proxy_client = None
- pass
+ for command in commands:
+ logger.debug("%s@%s:%s >> %s" % (testbed.username,
+ ssh_config.hostname,
+ ssh_config.port,
+ command))
+ envars = '. /etc/profile;'
+ command = envars + ' ' + command
+ chan = ssh_config.client.get_transport().open_session()
+ stdout = chan.makefile()
+ stderr = chan.makefile_stderr()
+ try:
+ chan.exec_command(command)
+ except paramiko.ssh_exception.SSHException as e:
+ raise SSHException('Failed to execute command')
+ o = _print_stream(stdout)
+ if chan.recv_exit_status() != 0:
+ # Get ready for printing stdout and stderr
+ if o != "":
+ list_print = ['**** STDOUT:']
+ list_print += o.split('\\n')
+ else:
+ list_print = []
+ e = _print_stream(stderr)
+ if e != "":
+ list_print.append('**** STDERR:')
+ list_print += e.split('\\n')
+ raise SSHException('A remote command returned an error. '
+ 'Output:\n\n\t' +
+ '\n\t'.join(list_print) + '\n')
+ return o
def execute_command(testbed, ssh_config, command, time_out=3):
"""