Skip to content

Commit

Permalink
Better logging and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bolkedebruin committed Nov 28, 2015
1 parent ef045db commit 78b8093
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions airflow/contrib/hooks/ssh_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _prepare_command(self, cmd):
if self.tty:
connection_cmd.append("-t")

logging.debug("SSH cmd: {} ".format(connection_cmd))
logging.debug("SSH cmd: {} ".format(connection_cmd + cmd))

return connection_cmd + cmd

Expand All @@ -95,13 +95,13 @@ def _Popen(self, cmd, **kwargs):
return subprocess.Popen(prefixed_cmd, **kwargs)

def check_output(self, cmd):
p = self._Popen(cmd, stdout=subprocess.PIPE)
output, _ = p.communicate()
p = self._Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, stderr = p.communicate()

if p.returncode != 0:
# I like this better: RemoteCalledProcessError(p.returncode, cmd, self.host, output=output)
raise AirflowException("Cannot execute {} on {}. Error code is: {}. Output: {}".format(
cmd, self.conn.host, p.returncode, output))
raise AirflowException("Cannot execute {} on {}. Error code is: {}. Output: {}, Stderr: {}".format(
cmd, self.conn.host, p.returncode, output, stderr))

return output

Expand Down
1 change: 1 addition & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ def setUp(self):
configuration.test_mode()
from airflow.contrib.hooks.ssh_hook import SSHHook
self.hook = SSHHook()
self.hook.no_host_key_check = True

def test_remote_cmd(self):
output = self.hook.check_output(["echo", "-n", "airflow"])
Expand Down

0 comments on commit 78b8093

Please sign in to comment.