From 2ea07b26b4fe5fc803660f2197536c6f743af4e2 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.

The workaround is to save off and remove the log_file_name value
before calling validation, then restore it if successful. This will
suppress the above error message.

Fixes: https://pagure.io/freeipa/issue/7952

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
---
 ipapython/admintool.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/ipapython/admintool.py b/ipapython/admintool.py
index 1bb953f4f4..96407fd23c 100644
--- a/ipapython/admintool.py
+++ b/ipapython/admintool.py
@@ -169,12 +169,20 @@ def execute(self):
 
         This includes validating options, setting up logging, doing the
         actual work, and handling the result.
+
+        log_file_name is set to None to defer logging until after
+        validation is complete. This will prevent the message
+        "See <file> for more information" from appearing in
+        validation errors because logging setup is not yet complete.
         """
         self._setup_logging(no_file=True)
+        save_log_file_name = self.log_file_name
+        self.log_file_name = None
         return_value = 1
         try:
             self.validate_options()
             self.ask_for_options()
+            self.log_file_name = save_log_file_name
             self.setup_logging()
             return_value = self.run()
         except BaseException as exception:
