diff options
Diffstat (limited to 'rumba/ssh_support.py')
-rw-r--r-- | rumba/ssh_support.py | 74 |
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): """ |