From 8d072b5a392e892b05dedb5d1a31df2966d12474 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcritten@redhat.com>
Date: Fri, 17 May 2019 15:08:29 -0400
Subject: [PATCH] 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 <rcritten@redhat.com>
---
 ipapython/admintool.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ipapython/admintool.py b/ipapython/admintool.py
index d3fee088e5..e488525ba9 100644
--- a/ipapython/admintool.py
+++ b/ipapython/admintool.py
@@ -161,6 +161,7 @@ def get_command_class(cls, options, args):
     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 @@ def setup_logging(self, log_file_mode='w'):
                 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 @@ def log_failure(self, error_message, return_value, exception, backtrace):
             # 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
