From cb38354df338f464588de02b919ea17712f5e056 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 7 Sep 2017 12:10:17 +0200 Subject: [PATCH] Run cleanup commands in quiet mode for DEBUG, TRACE. --- cdist/config.py | 7 ++++++- cdist/exec/local.py | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index 877014a0..6566205d 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -391,7 +391,12 @@ class Config(object): cmd = cleanup_cmd.split() cmd.append(self.local.target_host[0]) try: - self.local.run(cmd, return_output=False, save_output=False) + if self.log.getEffectiveLevel() <= logging.DEBUG: + quiet_mode = False + else: + quiet_mode = True + self.local.run(cmd, return_output=False, save_output=False, + quiet_mode=quiet_mode) except cdist.Error as e: # Log warning but continue. self.log.warning("Cleanup command failed: %s", e) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 1f2c66a3..468deb4a 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -201,7 +201,7 @@ class Local(object): os.makedirs(path, exist_ok=True) def run(self, command, env=None, return_output=False, message_prefix=None, - save_output=True): + save_output=True, quiet_mode=False): """Run the given command with the given environment. Return the output as a string. @@ -226,7 +226,7 @@ class Local(object): self.log.trace("Local run: %s", command) try: - if self.quiet_mode: + if self.quiet_mode or quiet_mode: stderr = subprocess.DEVNULL else: stderr = None @@ -242,7 +242,7 @@ class Local(object): # In some cases no output is saved. # This is used for shell command, stdout and stderr # must not be catched. - if self.quiet_mode: + if self.quiet_mode or quiet_mode: stdout = subprocess.DEVNULL else: stdout = None