From 4f6152aa0882ff8c1d62375fec04be331be13d0d Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Jun 11 2019 19:30:26 +0000 Subject: admintool: don't display log file on errors unless logging is setup The admintool will display the message when something goes wrong: See %s for more information" % self.log_file_name This is handy except when finally logging setup is not done yet so the log file doesn't actually get written to. This can happen if validation catches and raises an exception. Fixes: https://pagure.io/freeipa/issue/7952 Signed-off-by: Rob Crittenden Reviewed-By: Florence Blanc-Renaud --- diff --git a/ipapython/admintool.py b/ipapython/admintool.py index d3fee08..e488525 100644 --- a/ipapython/admintool.py +++ b/ipapython/admintool.py @@ -161,6 +161,7 @@ class AdminTool(object): def __init__(self, options, args): self.options = options self.args = args + self.log_file_initialized = False self.safe_options = self.option_parser.get_safe_opts(options) def execute(self): @@ -247,12 +248,15 @@ class AdminTool(object): break self._setup_logging(log_file_mode=log_file_mode) + if self.log_file_name: + self.log_file_initialized = True def _setup_logging(self, log_file_mode='w', no_file=False): if no_file: log_file_name = None elif self.options.log_file: log_file_name = self.options.log_file + self.log_file_name = log_file_name else: log_file_name = self.log_file_name if self.options.verbose: @@ -313,7 +317,7 @@ class AdminTool(object): # ipa-server-install. return message = "The %s command failed." % self.command_name - if self.log_file_name and return_value != 2: + if self.log_file_initialized and return_value != 2: # magic value because this is common between server and client # but imports are not straigthforward message += " See %s for more information" % self.log_file_name