You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/07/13 15:55:00 UTC

[airflow] branch main updated: Less verbose logging in ssh operator (#24915)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new ca99c23cb4 Less verbose logging in ssh operator (#24915)
ca99c23cb4 is described below

commit ca99c23cb4741eda43ac910a7ad8eda3cfa6add8
Author: Ehsan Poursaeed <hs...@gmail.com>
AuthorDate: Wed Jul 13 20:24:52 2022 +0430

    Less verbose logging in ssh operator (#24915)
    
    * Less verbose logging in ssh operator
---
 airflow/providers/ssh/operators/ssh.py    | 10 +++-------
 tests/providers/ssh/operators/test_ssh.py |  2 +-
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/airflow/providers/ssh/operators/ssh.py b/airflow/providers/ssh/operators/ssh.py
index 1d60aae4f8..a4e5b2910f 100644
--- a/airflow/providers/ssh/operators/ssh.py
+++ b/airflow/providers/ssh/operators/ssh.py
@@ -149,8 +149,7 @@ class SSHOperator(BaseOperator):
 
     def raise_for_status(self, exit_status: int, stderr: bytes) -> None:
         if exit_status != 0:
-            error_msg = stderr.decode('utf-8')
-            raise AirflowException(f"error running cmd: {self.command}, error: {error_msg}")
+            raise AirflowException(f"SSH operator error: exit status = {exit_status}")
 
     def run_ssh_client_command(self, ssh_client: "SSHClient", command: str) -> bytes:
         assert self.ssh_hook
@@ -168,11 +167,8 @@ class SSHOperator(BaseOperator):
         # Forcing get_pty to True if the command begins with "sudo".
         self.get_pty = self.command.startswith('sudo') or self.get_pty
 
-        try:
-            with self.get_ssh_client() as ssh_client:
-                result = self.run_ssh_client_command(ssh_client, self.command)
-        except Exception as e:
-            raise AirflowException(f"SSH operator error: {str(e)}")
+        with self.get_ssh_client() as ssh_client:
+            result = self.run_ssh_client_command(ssh_client, self.command)
         enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
         if not enable_pickling:
             result = b64encode(result).decode('utf-8')
diff --git a/tests/providers/ssh/operators/test_ssh.py b/tests/providers/ssh/operators/test_ssh.py
index 8620c6cc9e..45710ff7bc 100644
--- a/tests/providers/ssh/operators/test_ssh.py
+++ b/tests/providers/ssh/operators/test_ssh.py
@@ -195,5 +195,5 @@ class TestSSHOperator:
             command=command,
         )
         self.exec_ssh_client_command.return_value = (1, b'', b'Error here')
-        with pytest.raises(AirflowException, match=f"error running cmd: {command}, error: Error here"):
+        with pytest.raises(AirflowException, match="SSH operator error: exit status = 1"):
             task.execute(None)