X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fssh.py;h=7b15998be08816b14d7bf625a1e435236b841d31;hb=b2f75ec0f52110c267b90372e657b664417c1f4b;hp=90ac0be2dc2d5ad830514272dddfeb73799ddb42;hpb=cf561a6e3d4c4fbd78ab6c9d0a9aa817bb3300fc;p=csit.git diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py index 90ac0be2dc..7b15998be0 100644 --- a/resources/libraries/python/ssh.py +++ b/resources/libraries/python/ssh.py @@ -29,6 +29,11 @@ __all__ = ["exec_cmd", "exec_cmd_no_error"] # TODO: load priv key +class SSHTimeout(Exception): + """This exception is raised when a timeout occurs.""" + pass + + class SSH(object): """Contains methods for managing and using SSH connections.""" @@ -118,7 +123,7 @@ class SSH(object): :type timeout: int :return return_code, stdout, stderr :rtype: tuple(int, str, str) - :raise socket.timeout: If command is not finished in timeout time. + :raise SSHTimeout: If command is not finished in timeout time. """ start = time() stdout = StringIO.StringIO() @@ -144,7 +149,7 @@ class SSH(object): stderr.write(chan.recv_stderr(self.__MAX_RECV_BUF)) if time() - start > timeout: - raise socket.timeout( + raise SSHTimeout( 'Timeout exception.\n' 'Current contents of stdout buffer: {0}\n' 'Current contents of stderr buffer: {1}\n' @@ -215,7 +220,7 @@ class SSH(object): chan.set_combine_stderr(True) buf = '' - while not buf.endswith(':~$ '): + while not buf.endswith((":~$ ", "~]$ ")): try: chunk = chan.recv(self.__MAX_RECV_BUF) if not chunk: @@ -260,7 +265,9 @@ class SSH(object): except socket.timeout: raise Exception('Socket timeout: {0}'.format(buf)) tmp = buf.replace(cmd.replace('\n', ''), '') - return tmp.replace(prompt, '') + for p in prompt: + tmp.replace(p, '') + return tmp @staticmethod def interactive_terminal_close(chan):