[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
This commit is contained in:
evilham 2020-04-28 13:35:48 +02:00
parent 515992249d
commit ef44d44288
2 changed files with 13 additions and 8 deletions

View File

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

View File

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