Blob Blame History Raw
From 840e6144cd1ad75a7cf6ba5a8c936c6aa9bfc58d Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcritten@redhat.com>
Date: Tue, 1 May 2018 11:15:18 -0400
Subject: [PATCH] Disable message about log in ipa-backup if IPA is not
 configured

Introduce server installation constants similar to the client
but only tie in SERVER_NOT_CONFIGURED right now.

For the case of not configured don't spit out the "See <some log>
for more information" because no logging was actually done.

In the case of ipa-backup this could also be confusing if the
--log-file option was also passed in because it would not be
used.

https://pagure.io/freeipa/issue/6843

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
---
 install/tools/man/ipa-backup.1    | 2 ++
 ipapython/admintool.py            | 8 +++++++-
 ipaserver/install/installutils.py | 5 +++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/install/tools/man/ipa-backup.1 b/install/tools/man/ipa-backup.1
index ff9759ec77d54f32532c4ececfa5081daab9ec15..9e2900f770880d3a554df5cd5d0430716e3bf70e 100644
--- a/install/tools/man/ipa-backup.1
+++ b/install/tools/man/ipa-backup.1
@@ -69,6 +69,8 @@ Log to the given file
 0 if the command was successful
 
 1 if an error occurred
+
+2 if IPA is not configured
 .SH "FILES"
 .PP
 \fI/var/lib/ipa/backup\fR
diff --git a/ipapython/admintool.py b/ipapython/admintool.py
index 329e20f3744e304626bebcadfbb187782451dd4f..5a5d3eb421b204944123e19a2d7303d7237492cb 100644
--- a/ipapython/admintool.py
+++ b/ipapython/admintool.py
@@ -32,6 +32,10 @@ from ipapython import version
 from ipapython import config
 from ipapython.ipa_log_manager import standard_logging_setup
 
+SUCCESS = 0
+SERVER_INSTALL_ERROR = 1
+SERVER_NOT_CONFIGURED = 2
+
 logger = logging.getLogger(__name__)
 
 
@@ -301,7 +305,9 @@ class AdminTool(object):
         if error_message:
             logger.error('%s', error_message)
         message = "The %s command failed." % self.command_name
-        if self.log_file_name:
+        if self.log_file_name 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
         logger.error('%s', message)
 
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 22889ed1b305b8df91eda0831c56c4b187cf6f86..6614da69a0a046cdfa1b309f77972ead9de1279f 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -56,7 +56,7 @@ from ipalib.install import sysrestore
 from ipalib.install.kinit import kinit_password
 import ipaplatform
 from ipapython import ipautil, admintool, version
-from ipapython.admintool import ScriptError
+from ipapython.admintool import ScriptError, SERVER_NOT_CONFIGURED  # noqa: E402
 from ipapython.certdb import EXTERNAL_CA_TRUST_FLAGS
 from ipapython.ipaldap import DIRMAN_DN, LDAPClient
 from ipalib.util import validate_hostname
@@ -934,7 +934,8 @@ def check_server_configuration():
     """
     server_fstore = sysrestore.FileStore(paths.SYSRESTORE)
     if not server_fstore.has_files():
-        raise RuntimeError("IPA is not configured on this system.")
+        raise ScriptError("IPA is not configured on this system.",
+                          rval=SERVER_NOT_CONFIGURED)
 
 
 def remove_file(filename):
-- 
2.17.1