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 2021/10/21 05:36:07 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #17651: Create CommandExecutor for raising an exception in case of error during cmd execution

uranusjr commented on a change in pull request #17651:
URL: https://github.com/apache/airflow/pull/17651#discussion_r733332670



##########
File path: tests/test_utils/logging_command_executor.py
##########
@@ -62,5 +66,39 @@ def check_output(self, cmd):
             return output
 
 
+class CommandExecutor(LoggingCommandExecutor):
+    """
+    Due to 'LoggingCommandExecutor' class just returns the status code of command execution
+    ('execute_cmd' method) and continues to perform code with possible errors, separate
+    inherited 'CommandExecutor' class was created to use it if you need to break code performing
+    and immediately raise an exception in case of error during command execution,
+    so re-written 'execute_cmd' method will raise 'CommandExecutionError' exception.
+    """
+
+    def execute_cmd(self, cmd, silent=False, cwd=None, env=None):
+        if silent:
+            self.log.info("Executing in silent mode: '%s'", " ".join(shlex.quote(c) for c in cmd))
+            with open(os.devnull, 'w') as dev_null:
+                return subprocess.call(args=cmd, stdout=dev_null, stderr=subprocess.STDOUT, env=env, cwd=cwd)

Review comment:
       You can just use `subprocess.DEVNULL` for this.




-- 
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