[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:
parent
515992249d
commit
ef44d44288
|
@ -167,7 +167,8 @@ class Explorer(object):
|
||||||
def run_global_explorer(self, explorer):
|
def run_global_explorer(self, explorer):
|
||||||
"""Run the given global explorer and return it's output."""
|
"""Run the given global explorer and return it's output."""
|
||||||
script = os.path.join(self.remote.global_explorer_path, explorer)
|
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
|
# type
|
||||||
|
|
||||||
|
@ -229,7 +230,8 @@ class Explorer(object):
|
||||||
})
|
})
|
||||||
script = os.path.join(self.remote.type_path, cdist_type.explorer_path,
|
script = os.path.join(self.remote.type_path, cdist_type.explorer_path,
|
||||||
explorer)
|
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):
|
def transfer_type_explorers(self, cdist_type):
|
||||||
"""Transfer the type explorers for the given type to the
|
"""Transfer the type explorers for the given type to the
|
||||||
|
|
|
@ -219,7 +219,7 @@ class Remote(object):
|
||||||
self._run_command(command)
|
self._run_command(command)
|
||||||
|
|
||||||
def run_script(self, script, env=None, return_output=False, stdout=None,
|
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.
|
"""Run the given script with the given environment on the remote side.
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
|
@ -232,10 +232,11 @@ class Remote(object):
|
||||||
command.append(script)
|
command.append(script)
|
||||||
|
|
||||||
return self.run(command, env=env, return_output=return_output,
|
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,
|
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.
|
"""Run the given command with the given environment on the remote side.
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
|
@ -269,10 +270,11 @@ class Remote(object):
|
||||||
else:
|
else:
|
||||||
cmd.extend(command)
|
cmd.extend(command)
|
||||||
return self._run_command(cmd, env=env, return_output=return_output,
|
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,
|
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.
|
"""Run the given command with the given environment.
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
|
@ -280,7 +282,8 @@ class Remote(object):
|
||||||
assert isinstance(command, (list, tuple)), (
|
assert isinstance(command, (list, tuple)), (
|
||||||
"list or tuple argument expected, got: %s" % command)
|
"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")
|
self.log.debug("return_output is True, ignoring stdout")
|
||||||
|
|
||||||
close_stdout = False
|
close_stdout = False
|
||||||
|
|
Loading…
Reference in New Issue