Run cleanup commands in quiet mode for DEBUG, TRACE.

This commit is contained in:
Darko Poljak 2017-09-07 12:10:17 +02:00
parent e0a4fc4ea7
commit cb38354df3
2 changed files with 9 additions and 4 deletions

View File

@ -391,7 +391,12 @@ class Config(object):
cmd = cleanup_cmd.split() cmd = cleanup_cmd.split()
cmd.append(self.local.target_host[0]) cmd.append(self.local.target_host[0])
try: 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: except cdist.Error as e:
# Log warning but continue. # Log warning but continue.
self.log.warning("Cleanup command failed: %s", e) self.log.warning("Cleanup command failed: %s", e)

View File

@ -201,7 +201,7 @@ class Local(object):
os.makedirs(path, exist_ok=True) os.makedirs(path, exist_ok=True)
def run(self, command, env=None, return_output=False, message_prefix=None, 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. """Run the given command with the given environment.
Return the output as a string. Return the output as a string.
@ -226,7 +226,7 @@ class Local(object):
self.log.trace("Local run: %s", command) self.log.trace("Local run: %s", command)
try: try:
if self.quiet_mode: if self.quiet_mode or quiet_mode:
stderr = subprocess.DEVNULL stderr = subprocess.DEVNULL
else: else:
stderr = None stderr = None
@ -242,7 +242,7 @@ class Local(object):
# In some cases no output is saved. # In some cases no output is saved.
# This is used for shell command, stdout and stderr # This is used for shell command, stdout and stderr
# must not be catched. # must not be catched.
if self.quiet_mode: if self.quiet_mode or quiet_mode:
stdout = subprocess.DEVNULL stdout = subprocess.DEVNULL
else: else:
stdout = None stdout = None