From ef44d44288db75821fd195f1ff286fa20a2412c2 Mon Sep 17 00:00:00 2001 From: Evilham Date: Tue, 28 Apr 2020 13:35:48 +0200 Subject: [PATCH] [logging] Mute return_output warning for explorers. This adds a `warn_return_output` flag to `cdist.exec.remote.Remote.(run_script|run|_run_command)`. It defaults to `True` keeping current behaviour except when called from `cdist.core.explorer.Explorer`. This way debug logging is significantly cleaner. Fixes #806 --- cdist/core/explorer.py | 6 ++++-- cdist/exec/remote.py | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cdist/core/explorer.py b/cdist/core/explorer.py index 353d7681..c93f8958 100644 --- a/cdist/core/explorer.py +++ b/cdist/core/explorer.py @@ -167,7 +167,8 @@ class Explorer(object): def run_global_explorer(self, explorer): """Run the given global explorer and return it's output.""" script = os.path.join(self.remote.global_explorer_path, explorer) - return self.remote.run_script(script, env=self.env, return_output=True) + return self.remote.run_script(script, env=self.env, return_output=True, + warn_return_output=False) # type @@ -229,7 +230,8 @@ class Explorer(object): }) script = os.path.join(self.remote.type_path, cdist_type.explorer_path, explorer) - return self.remote.run_script(script, env=env, return_output=True) + return self.remote.run_script(script, env=env, return_output=True, + warn_return_output=False) def transfer_type_explorers(self, cdist_type): """Transfer the type explorers for the given type to the diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index e0ef66ec..c53f2efa 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -219,7 +219,7 @@ class Remote(object): self._run_command(command) def run_script(self, script, env=None, return_output=False, stdout=None, - stderr=None): + stderr=None, warn_return_output=True): """Run the given script with the given environment on the remote side. Return the output as a string. @@ -232,10 +232,11 @@ class Remote(object): command.append(script) return self.run(command, env=env, return_output=return_output, - stdout=stdout, stderr=stderr) + stdout=stdout, stderr=stderr, + warn_return_output=warn_return_output) def run(self, command, env=None, return_output=False, stdout=None, - stderr=None): + stderr=None, warn_return_output=True): """Run the given command with the given environment on the remote side. Return the output as a string. @@ -269,10 +270,11 @@ class Remote(object): else: cmd.extend(command) return self._run_command(cmd, env=env, return_output=return_output, - stdout=stdout, stderr=stderr) + stdout=stdout, stderr=stderr, + warn_return_output=warn_return_output) def _run_command(self, command, env=None, return_output=False, stdout=None, - stderr=None): + stderr=None, warn_return_output=True): """Run the given command with the given environment. Return the output as a string. @@ -280,7 +282,8 @@ class Remote(object): assert isinstance(command, (list, tuple)), ( "list or tuple argument expected, got: %s" % command) - if return_output and stdout is not subprocess.PIPE: + warn_return_output_applies = warn_return_output and return_output + if warn_return_output_applies and stdout is not subprocess.PIPE: self.log.debug("return_output is True, ignoring stdout") close_stdout = False