Return 0 on uninstall when on_master for case of not installed

This is to suppress the spurious error message:

The ipa-client-install command failed.

when the client is not configured.

This is managed by allowing a ScriptError to return SUCCESS (0)
and have this ignored in log_failure().

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

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
This commit is contained in:
Rob Crittenden 2019-06-04 12:18:46 -04:00 committed by Florence Blanc-Renaud
parent 1284bf1588
commit c1c50650a7
2 changed files with 11 additions and 2 deletions

View File

@ -3175,9 +3175,13 @@ def uninstall_check(options):
fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE) fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
if not is_ipa_client_installed(fstore): if not is_ipa_client_installed(fstore):
if options.on_master:
rval = SUCCESS
else:
rval = CLIENT_NOT_CONFIGURED
raise ScriptError( raise ScriptError(
"IPA client is not configured on this system.", "IPA client is not configured on this system.",
rval=CLIENT_NOT_CONFIGURED) rval=rval)
server_fstore = sysrestore.FileStore(paths.SYSRESTORE) server_fstore = sysrestore.FileStore(paths.SYSRESTORE)
if server_fstore.has_files() and not options.on_master: if server_fstore.has_files() and not options.on_master:

View File

@ -279,7 +279,7 @@ class AdminTool:
"""Given an exception, return a message (or None) and process exit code """Given an exception, return a message (or None) and process exit code
""" """
if isinstance(exception, ScriptError): if isinstance(exception, ScriptError):
return exception.msg, exception.rval or 1 return exception.msg, exception.rval
elif isinstance(exception, SystemExit): elif isinstance(exception, SystemExit):
if isinstance(exception.code, int): if isinstance(exception.code, int):
return None, exception.code return None, exception.code
@ -307,6 +307,11 @@ class AdminTool:
self.command_name, type(exception).__name__, exception) self.command_name, type(exception).__name__, exception)
if error_message: if error_message:
logger.error('%s', error_message) logger.error('%s', error_message)
if return_value == 0:
# A script may raise an exception but still want quit gracefully,
# like the case of ipa-client-install called from
# ipa-server-install.
return
message = "The %s command failed." % self.command_name message = "The %s command failed." % self.command_name
if self.log_file_name and return_value != 2: if self.log_file_name and return_value != 2:
# magic value because this is common between server and client # magic value because this is common between server and client