From 667a7a587163c0ff5507c3a0188dea050681b84a Mon Sep 17 00:00:00 2001 From: Marco Capitani Date: Thu, 9 Nov 2017 17:14:48 +0100 Subject: SSH: added stderr to output in case of commmand error --- rumba/ssh_support.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index 93b6ac2..53965f8 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -58,6 +58,7 @@ def _print_stream(stream): return o.rstrip() def ssh_connect(hostname, port, username, password, time_out, proxy_server): + logger.debug('Trying to open a connection towards node %s.' % hostname) retry = 0 max_retries = 10 while retry < max_retries: @@ -172,13 +173,19 @@ def execute_commands(testbed, ssh_config, commands, time_out=3): 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): - raise SSHException('A remote command returned an error.\n' + o) + if chan.recv_exit_status() != 0: + e = _print_stream(stderr) + o_e = o + (('\n' + e) if e != "" else "") + raise SSHException('A remote command returned an error.' + + (('\n' + o_e) if o_e != "" else "")) + ssh_config.client = None + ssh_config.proxy_client = None return o -- cgit v1.2.3