Skip to content

Commit

Permalink
Revert "Update the paramiko runner code to replace all occurances of …
Browse files Browse the repository at this point in the history
…\r\n in the"

This reverts commit 21fac2c.
  • Loading branch information
Kami committed Apr 9, 2019
1 parent 3de29f1 commit 2c66d53
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions st2common/st2common/runners/paramiko_ssh.py
Expand Up @@ -363,13 +363,7 @@ def run(self, cmd, timeout=None, quote=False, call_line_handler_func=False):
if cmd.startswith('sudo'):
# Note that fabric does this as well. If you set pty, stdout and stderr
# streams will be combined into one.
# NOTE: If pty is used, every new line character \n will be converted to \r\n which
# isn't desired. Because of that we sanitize the output and replace \r\n with \n at the
# bottom of this method
uses_pty = True
chan.get_pty()
else:
uses_pty = False
chan.exec_command(cmd)

stdout = StringIO()
Expand Down Expand Up @@ -410,8 +404,8 @@ def run(self, cmd, timeout=None, quote=False, call_line_handler_func=False):
# TODO: Is this the right way to clean up?
chan.close()

stdout = self._sanitize_output(stdout.getvalue(), uses_pty=uses_pty)
stderr = self._sanitize_output(stderr.getvalue(), uses_pty=uses_pty)
stdout = strip_shell_chars(stdout.getvalue())
stderr = strip_shell_chars(stderr.getvalue())
raise SSHCommandTimeoutError(cmd=cmd, timeout=timeout, stdout=stdout,
stderr=stderr)

Expand Down Expand Up @@ -440,8 +434,8 @@ def run(self, cmd, timeout=None, quote=False, call_line_handler_func=False):
# Receive the exit status code of the command we ran.
status = chan.recv_exit_status()

stdout = self._sanitize_output(stdout.getvalue(), uses_pty=uses_pty)
stderr = self._sanitize_output(stderr.getvalue(), uses_pty=uses_pty)
stdout = strip_shell_chars(stdout.getvalue())
stderr = strip_shell_chars(stderr.getvalue())

extra = {'_status': status, '_stdout': stdout, '_stderr': stderr}
self.logger.debug('Command finished', extra=extra)
Expand Down Expand Up @@ -742,20 +736,6 @@ def _get_ssh_config_for_host(self, host):

return ssh_config_info

def _sanitize_output(self, output, uses_pty=False):
"""
Function which sanitizes the output (stdout / stderr).
It strips trailing carriage return and new line characters and if pty is used, it also
replaces all occurances of \r\n with \n.
"""
output = strip_shell_chars(output)

if uses_pty:
output = output.replace('\r\n', '\n')

return output

@staticmethod
def _is_key_file_needs_passphrase(file):
for cls in [paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey]:
Expand Down

0 comments on commit 2c66d53

Please sign in to comment.