You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/10/30 15:00:23 UTC

[GitHub] [airflow] bdsoha commented on a diff in pull request #27370: SSH task exit code added to XCOM as 'ssh_exit' key

bdsoha commented on code in PR #27370:
URL: https://github.com/apache/airflow/pull/27370#discussion_r1008879118


##########
airflow/providers/ssh/operators/ssh.py:
##########
@@ -151,16 +151,18 @@ def exec_ssh_client_command(self, ssh_client: SSHClient, command: str):
             ssh_client, command, timeout=self.timeout, environment=self.environment, get_pty=self.get_pty
         )
 
-    def raise_for_status(self, exit_status: int, stderr: bytes) -> None:
+    def raise_for_status(self, exit_status: int, stderr: bytes, **kwargs) -> None:
+        ti=kwargs['context'].get('task_instance')
+        ti.xcom_push(key='ssh_exit', value=exit_status)
         if exit_status != 0:
             raise AirflowException(f"SSH operator error: exit status = {exit_status}")
 
-    def run_ssh_client_command(self, ssh_client: SSHClient, command: str) -> bytes:
+    def run_ssh_client_command(self, ssh_client: SSHClient, command: str, **kwargs) -> bytes:
         assert self.ssh_hook
         exit_status, agg_stdout, agg_stderr = self.ssh_hook.exec_ssh_client_command(
             ssh_client, command, timeout=self.timeout, environment=self.environment, get_pty=self.get_pty
         )
-        self.raise_for_status(exit_status, agg_stderr)
+        self.raise_for_status(exit_status, agg_stderr, context=kwargs['context'])

Review Comment:
   ```suggestion
           self.raise_for_status(exit_status, agg_stderr, context=kwargs["context"])
   ```



##########
airflow/providers/ssh/operators/ssh.py:
##########
@@ -151,16 +151,18 @@ def exec_ssh_client_command(self, ssh_client: SSHClient, command: str):
             ssh_client, command, timeout=self.timeout, environment=self.environment, get_pty=self.get_pty
         )
 
-    def raise_for_status(self, exit_status: int, stderr: bytes) -> None:
+    def raise_for_status(self, exit_status: int, stderr: bytes, **kwargs) -> None:
+        ti=kwargs['context'].get('task_instance')
+        ti.xcom_push(key='ssh_exit', value=exit_status)

Review Comment:
   ```suggestion
           ti=kwargs["context"].get("task_instance")
           ti.xcom_push(key="ssh_exit", value=exit_status)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org