diff options
author | pmikus <pmikus@cisco.com> | 2016-09-30 14:29:08 +0100 |
---|---|---|
committer | Miroslav Miklus <mmiklus@cisco.com> | 2016-10-05 08:55:27 +0000 |
commit | 145e2101dc39a701286bc51ddaa0dbd1a4cf022f (patch) | |
tree | 44019bc589f3d9b7851bd9ba0875acd20cc55bd9 /resources/libraries/python | |
parent | b213a9f30c333b84705aede28f16de5e8e8a06ea (diff) |
CSIT-176 Fix interactive SSH console deadlock
Change-Id: Iba291d6781238c0e880534195ff65a7b3c4bede1
Signed-off-by: pmikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r-- | resources/libraries/python/ssh.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py index 287ad31d65..8acb54b382 100644 --- a/resources/libraries/python/ssh.py +++ b/resources/libraries/python/ssh.py @@ -21,7 +21,6 @@ import paramiko from paramiko import RSAKey from paramiko.ssh_exception import SSHException from scp import SCPClient -from interruptingcow import timeout as icTimeout from robot.api import logger from robot.utils.asserts import assert_equal @@ -213,19 +212,23 @@ class SSH(object): chan.get_pty() chan.invoke_shell() chan.settimeout(int(time_out)) + chan.set_combine_stderr(True) buf = '' - try: - with icTimeout(time_out, exception=RuntimeError): - while not buf.endswith(':~$ '): - if chan.recv_ready(): - buf = chan.recv(4096) - except RuntimeError: - raise Exception('Open interactive terminal timeout.') + while not buf.endswith(':~$ '): + try: + chunk = chan.recv(self.__MAX_RECV_BUF) + if not chunk: + break + buf += chunk + if chan.exit_status_ready(): + logger.error('Channel exit status ready') + break + except socket.timeout: + raise Exception('Socket timeout: {0}'.format(buf)) return chan - @staticmethod - def interactive_terminal_exec_command(chan, cmd, prompt, + def interactive_terminal_exec_command(self, chan, cmd, prompt, time_out=30): """Execute command on interactive terminal. @@ -247,13 +250,17 @@ class SSH(object): """ chan.sendall('{c}\n'.format(c=cmd)) buf = '' - try: - with icTimeout(time_out, exception=RuntimeError): - while not buf.endswith(prompt): - if chan.recv_ready(): - buf += chan.recv(4096) - except RuntimeError: - raise Exception("Exec '{c}' timeout.".format(c=cmd)) + while not buf.endswith(prompt): + try: + chunk = chan.recv(self.__MAX_RECV_BUF) + if not chunk: + break + buf += chunk + if chan.exit_status_ready(): + logger.error('Channel exit status ready') + break + except socket.timeout: + raise Exception('Socket timeout: {0}'.format(buf)) tmp = buf.replace(cmd.replace('\n', ''), '') return tmp.replace(prompt, '') |