On 03/26/2012 05:35 PM, Petr Viktorin wrote:
On 03/26/2012 04:54 PM, Rob Crittenden wrote:
Some minor compliants.
Ideally, there would be a routine that sets up the logging and handles
command-line arguments in some uniform way (which is also needed before
logging setup to detect ipa-server-install --uninstall).
The original patch did the common logging setup, and I hacked around the
install/uninstall problem too.
I guess I overdid it when I simplified the patch.
I'm somewhat confused about the scope, so bear with me as I clarify what
you mean.
If you abort the installation you get this somewhat unnerving error:
Continue to configure the system with these values? [no]:
ipa : ERROR ipa-server-install failed, SystemExit: Installation aborted
Installation aborted
ipa-ldap-updater is the same:
# ipa-ldap-updater
[2012-03-26T14:53:41Z ipa] <ERROR>: ipa-ldap-updater failed, SystemExit:
IPA is not configured on this system.
IPA is not configured on this system.
and ipa-upgradeconfig
$ ipa-upgradeconfig
[2012-03-26T14:54:05Z ipa] <ERROR>: ipa-upgradeconfig failed, SystemExit:
You must be root to run this script.
You must be root to run this script.
I'm guessing that the issue is that the log file isn't opened yet.
>
It would be nice if the logging would be confined to just the log.
If I understand you correctly, the code should check if logging has been
configured already, and if not, skip displaying the message?
When uninstalling you get the message 'ipa-server-install successful'.
This is a little odd as well.
ipa-server-install is the name of the command. Wontfix for now, unless
you disagree strongly.
Updated patch: only log if logging has been configured (detected by
looking at the root logger's handlers), and changed the message to “The
ipa-server-install command has succeeded/failed”.
--
Petr³
From 248744253385dab1b0747c38f37287842f00aa62 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Thu, 1 Mar 2012 05:29:52 -0500
Subject: [PATCH] Add final debug message in installers
Invocation of install tools is wrapped in a context manager that logs
the final success or failure.
https://fedorahosted.org/freeipa/ticket/2071
---
install/tools/ipa-adtrust-install | 47 +++++++++++-----------
install/tools/ipa-ca-install | 71 +++++++++++++++++-----------------
install/tools/ipa-compat-manage | 43 ++++++++++----------
install/tools/ipa-compliance | 17 ++++----
install/tools/ipa-csreplica-manage | 33 ++++++++--------
install/tools/ipa-dns-install | 47 +++++++++++-----------
install/tools/ipa-ldap-updater | 27 +++++++------
install/tools/ipa-managed-entries | 35 +++++++++--------
install/tools/ipa-nis-manage | 43 ++++++++++----------
install/tools/ipa-replica-conncheck | 35 +++++++++--------
install/tools/ipa-replica-install | 71 +++++++++++++++++-----------------
install/tools/ipa-replica-manage | 45 +++++++++++----------
install/tools/ipa-replica-prepare | 33 ++++++++--------
install/tools/ipa-server-certinstall | 17 ++++----
install/tools/ipa-server-install | 66 ++++++++++++++++---------------
install/tools/ipa-upgradeconfig | 16 ++++---
ipaserver/install/installutils.py | 21 ++++++++++
17 files changed, 353 insertions(+), 314 deletions(-)
diff --git a/install/tools/ipa-adtrust-install b/install/tools/ipa-adtrust-install
index 248ea35eaa86dd59ebbc871b86df780cfd71ccf6..c3558fce0cceae879f83b61e0057d14fe42811de 100755
--- a/install/tools/ipa-adtrust-install
+++ b/install/tools/ipa-adtrust-install
@@ -227,26 +227,27 @@ def main():
return 0
-try:
- sys.exit(main())
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt:
- print "Installation cancelled."
-except RuntimeError, e:
- print str(e)
-except HostnameLocalhost:
- print "The hostname resolves to the localhost address (127.0.0.1/::1)"
- print "Please change your /etc/hosts file so that the hostname"
- print "resolves to the ip address of your network interface."
- print "The KDC service does not listen on localhost"
- print ""
- print "Please fix your /etc/hosts file and restart the setup program"
-except Exception, e:
- message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
- print message
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
- sys.exit(1)
+with installutils.script_context('ipa-adtrust-install'):
+ try:
+ sys.exit(main())
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt:
+ print "Installation cancelled."
+ except RuntimeError, e:
+ print str(e)
+ except HostnameLocalhost:
+ print "The hostname resolves to the localhost address (127.0.0.1/::1)"
+ print "Please change your /etc/hosts file so that the hostname"
+ print "resolves to the ip address of your network interface."
+ print "The KDC service does not listen on localhost"
+ print ""
+ print "Please fix your /etc/hosts file and restart the setup program"
+ except Exception, e:
+ message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
+ print message
+ message = str(e)
+ for str in traceback.format_tb(sys.exc_info()[2]):
+ message = message + "\n" + str
+ root_logger.debug(message)
+ sys.exit(1)
diff --git a/install/tools/ipa-ca-install b/install/tools/ipa-ca-install
index 57f867e704b559a691ac48a564c152e3b98def72..48a0a4b39dcd18ae0e8c1ebb5fef328e3dc60b8a 100755
--- a/install/tools/ipa-ca-install
+++ b/install/tools/ipa-ca-install
@@ -150,41 +150,42 @@ def main():
# We need to restart apache as we drop a new config file in there
ipaservices.knownservices.httpd.restart(capture_output=True)
-try:
- if not os.geteuid()==0:
- sys.exit("\nYou must be root to run this script.\n")
+with installutils.script_context('ipa-ca-install'):
+ try:
+ if not os.geteuid()==0:
+ sys.exit("\nYou must be root to run this script.\n")
+
+ main()
+ sys.exit(0)
+ except SystemExit, e:
+ sys.exit(e)
+ except socket.error, (errno, errstr):
+ print errstr
+ except HostnameLocalhost:
+ print "The hostname resolves to the localhost address (127.0.0.1/::1)"
+ print "Please change your /etc/hosts file so that the hostname"
+ print "resolves to the ip address of your network interface."
+ print ""
+ print "Please fix your /etc/hosts file and restart the setup program"
+ except Exception, e:
+ print "creation of replica failed: %s" % str(e)
+ message = str(e)
+ for str in traceback.format_tb(sys.exc_info()[2]):
+ message = message + "\n" + str
+ root_logger.debug(message)
+ except KeyboardInterrupt:
+ print "Installation cancelled."
+ finally:
+ # always try to remove decrypted replica file
+ try:
+ if REPLICA_INFO_TOP_DIR:
+ shutil.rmtree(REPLICA_INFO_TOP_DIR)
+ except OSError:
+ pass
- main()
- sys.exit(0)
-except SystemExit, e:
- sys.exit(e)
-except socket.error, (errno, errstr):
- print errstr
-except HostnameLocalhost:
- print "The hostname resolves to the localhost address (127.0.0.1/::1)"
- print "Please change your /etc/hosts file so that the hostname"
- print "resolves to the ip address of your network interface."
print ""
- print "Please fix your /etc/hosts file and restart the setup program"
-except Exception, e:
- print "creation of replica failed: %s" % str(e)
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
-except KeyboardInterrupt:
- print "Installation cancelled."
-finally:
- # always try to remove decrypted replica file
- try:
- if REPLICA_INFO_TOP_DIR:
- shutil.rmtree(REPLICA_INFO_TOP_DIR)
- except OSError:
- pass
+ print "Your system may be partly configured."
+ print "Run /usr/sbin/ipa-server-install --uninstall to clean up."
-print ""
-print "Your system may be partly configured."
-print "Run /usr/sbin/ipa-server-install --uninstall to clean up."
-
-# the only way to get here is on error or ^C
-sys.exit(1)
+ # the only way to get here is on error or ^C
+ sys.exit(1)
diff --git a/install/tools/ipa-compat-manage b/install/tools/ipa-compat-manage
index 13a93cbed02ca69f4f6e8cb156a2f6f18e2da899..48bea7dd6531cba79c46dff4061ea09d5ffa3aef 100755
--- a/install/tools/ipa-compat-manage
+++ b/install/tools/ipa-compat-manage
@@ -196,24 +196,25 @@ def main():
return retval
-try:
- if __name__ == "__main__":
- sys.exit(main())
-except BadSyntax, e:
- print "There is a syntax error in this update file:"
- print " %s" % e
- sys.exit(1)
-except RuntimeError, e:
- print "%s" % e
- sys.exit(1)
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt, e:
- sys.exit(1)
-except config.IPAConfigError, e:
- print "An IPA server to update cannot be found. Has one been configured yet?"
- print "The error was: %s" % e
- sys.exit(1)
-except errors.LDAPError, e:
- print "An error occurred while performing operations: %s" % e
- sys.exit(1)
+with installutils.script_context('ipa-compat-manage'):
+ try:
+ if __name__ == "__main__":
+ sys.exit(main())
+ except BadSyntax, e:
+ print "There is a syntax error in this update file:"
+ print " %s" % e
+ sys.exit(1)
+ except RuntimeError, e:
+ print "%s" % e
+ sys.exit(1)
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt, e:
+ sys.exit(1)
+ except config.IPAConfigError, e:
+ print "An IPA server to update cannot be found. Has one been configured yet?"
+ print "The error was: %s" % e
+ sys.exit(1)
+ except errors.LDAPError, e:
+ print "An error occurred while performing operations: %s" % e
+ sys.exit(1)
diff --git a/install/tools/ipa-compliance b/install/tools/ipa-compliance
index 8ae91b7779295408d5227f813f35b3885b55b842..6992e824c49c3edd3697d909665aa2e2c6577f88 100644
--- a/install/tools/ipa-compliance
+++ b/install/tools/ipa-compliance
@@ -189,12 +189,13 @@ def main():
return 0
-try:
- if not os.geteuid()==0:
- sys.exit("\nMust be root to check compliance\n")
+with installutils.script_context('ipa-compliance'):
+ try:
+ if not os.geteuid()==0:
+ sys.exit("\nMust be root to check compliance\n")
- main()
-except SystemExit, e:
- sys.exit(e)
-except RuntimeError, e:
- sys.exit(e)
+ main()
+ except SystemExit, e:
+ sys.exit(e)
+ except RuntimeError, e:
+ sys.exit(e)
diff --git a/install/tools/ipa-csreplica-manage b/install/tools/ipa-csreplica-manage
index 97c504552c0763e351ef6ae7e197a0acb684a83b..be7df5989ed4e343a21c64bd83574039dd412fbc 100755
--- a/install/tools/ipa-csreplica-manage
+++ b/install/tools/ipa-csreplica-manage
@@ -438,19 +438,20 @@ def main():
replica2 = args[1]
del_link(realm, replica1, replica2, dirman_passwd)
-try:
- main()
-except KeyboardInterrupt:
- sys.exit(1)
-except SystemExit, e:
- sys.exit(e)
-except ldap.INVALID_CREDENTIALS:
- sys.exit("Invalid password")
-except ldap.INSUFFICIENT_ACCESS:
- sys.exit("Insufficient access")
-except ldap.LOCAL_ERROR, e:
- sys.exit(convert_error(e))
-except ldap.SERVER_DOWN, e:
- sys.exit("%s" % convert_error(e))
-except Exception, e:
- sys.exit("unexpected error: %s" % convert_error(e))
+with installutils.script_context('ipa-csreplica-manage'):
+ try:
+ main()
+ except KeyboardInterrupt:
+ sys.exit(1)
+ except SystemExit, e:
+ sys.exit(e)
+ except ldap.INVALID_CREDENTIALS:
+ sys.exit("Invalid password")
+ except ldap.INSUFFICIENT_ACCESS:
+ sys.exit("Insufficient access")
+ except ldap.LOCAL_ERROR, e:
+ sys.exit(convert_error(e))
+ except ldap.SERVER_DOWN, e:
+ sys.exit("%s" % convert_error(e))
+ except Exception, e:
+ sys.exit("unexpected error: %s" % convert_error(e))
diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install
index b540630f4f2782603c31ce1905870c38c9af98ab..892b5cc792054e596e6d74902eed8573af4b67d7 100755
--- a/install/tools/ipa-dns-install
+++ b/install/tools/ipa-dns-install
@@ -243,26 +243,27 @@ def main():
return 0
-try:
- sys.exit(main())
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt:
- print "Installation cancelled."
-except RuntimeError, e:
- print str(e)
-except HostnameLocalhost:
- print "The hostname resolves to the localhost address (127.0.0.1/::1)"
- print "Please change your /etc/hosts file so that the hostname"
- print "resolves to the ip address of your network interface."
- print "The KDC service does not listen on localhost"
- print ""
- print "Please fix your /etc/hosts file and restart the setup program"
-except Exception, e:
- message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
- print message
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
- sys.exit(1)
+with installutils.script_context('ipa-dns-install'):
+ try:
+ sys.exit(main())
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt:
+ print "Installation cancelled."
+ except RuntimeError, e:
+ print str(e)
+ except HostnameLocalhost:
+ print "The hostname resolves to the localhost address (127.0.0.1/::1)"
+ print "Please change your /etc/hosts file so that the hostname"
+ print "resolves to the ip address of your network interface."
+ print "The KDC service does not listen on localhost"
+ print ""
+ print "Please fix your /etc/hosts file and restart the setup program"
+ except Exception, e:
+ message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
+ print message
+ message = str(e)
+ for str in traceback.format_tb(sys.exc_info()[2]):
+ message = message + "\n" + str
+ root_logger.debug(message)
+ sys.exit(1)
diff --git a/install/tools/ipa-ldap-updater b/install/tools/ipa-ldap-updater
index bd2233a94241c28375b29cc10d60908238b8f176..4de69e31a217d44734a24877d4d30721904e325c 100755
--- a/install/tools/ipa-ldap-updater
+++ b/install/tools/ipa-ldap-updater
@@ -154,16 +154,17 @@ def main():
root_logger.info('Update complete')
return 0
-try:
- if __name__ == "__main__":
- sys.exit(main())
-except BadSyntax, e:
- print "There is a syntax error in this update file:"
- print " %s" % e
- sys.exit(1)
-except RuntimeError, e:
- sys.exit(e)
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt, e:
- sys.exit(1)
+with installutils.script_context('ipa-ldap-updater'):
+ try:
+ if __name__ == "__main__":
+ sys.exit(main())
+ except BadSyntax, e:
+ print "There is a syntax error in this update file:"
+ print " %s" % e
+ sys.exit(1)
+ except RuntimeError, e:
+ sys.exit(e)
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt, e:
+ sys.exit(1)
diff --git a/install/tools/ipa-managed-entries b/install/tools/ipa-managed-entries
index 00bb566226adf636fe1c2cfc4a6357636f3ffb71..edc5605b8678cd73a686c68f3baa7cc8deb03168 100755
--- a/install/tools/ipa-managed-entries
+++ b/install/tools/ipa-managed-entries
@@ -237,20 +237,21 @@ def main():
return retval
-try:
- if __name__ == "__main__":
- sys.exit(main())
-except RuntimeError, e:
- print "%s" % e
- sys.exit(1)
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt, e:
- sys.exit(1)
-except config.IPAConfigError, e:
- print "An IPA server to update cannot be found. Has one been configured yet?"
- print "The error was: %s" % e
- sys.exit(1)
-except errors.LDAPError, e:
- print "An error occurred while performing operations: %s" % e
- sys.exit(1)
+with installutils.script_context('ipa-managed-entries'):
+ try:
+ if __name__ == "__main__":
+ sys.exit(main())
+ except RuntimeError, e:
+ print "%s" % e
+ sys.exit(1)
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt, e:
+ sys.exit(1)
+ except config.IPAConfigError, e:
+ print "An IPA server to update cannot be found. Has one been configured yet?"
+ print "The error was: %s" % e
+ sys.exit(1)
+ except errors.LDAPError, e:
+ print "An error occurred while performing operations: %s" % e
+ sys.exit(1)
diff --git a/install/tools/ipa-nis-manage b/install/tools/ipa-nis-manage
index 5c5bbca8e0435441cbb2ea10d80245e36a86e9a7..5473a45ed05db5268effa680f6431d1d69a3cb35 100755
--- a/install/tools/ipa-nis-manage
+++ b/install/tools/ipa-nis-manage
@@ -200,24 +200,25 @@ def main():
return retval
-try:
- if __name__ == "__main__":
- sys.exit(main())
-except BadSyntax, e:
- print "There is a syntax error in this update file:"
- print " %s" % e
- sys.exit(1)
-except RuntimeError, e:
- print "%s" % e
- sys.exit(1)
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt, e:
- sys.exit(1)
-except config.IPAConfigError, e:
- print "An IPA server to update cannot be found. Has one been configured yet?"
- print "The error was: %s" % e
- sys.exit(1)
-except errors.LDAPError, e:
- print "An error occurred while performing operations: %s" % e
- sys.exit(1)
+with installutils.script_context('ipa-nis-manage'):
+ try:
+ if __name__ == "__main__":
+ sys.exit(main())
+ except BadSyntax, e:
+ print "There is a syntax error in this update file:"
+ print " %s" % e
+ sys.exit(1)
+ except RuntimeError, e:
+ print "%s" % e
+ sys.exit(1)
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt, e:
+ sys.exit(1)
+ except config.IPAConfigError, e:
+ print "An IPA server to update cannot be found. Has one been configured yet?"
+ print "The error was: %s" % e
+ sys.exit(1)
+ except errors.LDAPError, e:
+ print "An error occurred while performing operations: %s" % e
+ sys.exit(1)
diff --git a/install/tools/ipa-replica-conncheck b/install/tools/ipa-replica-conncheck
index 6ec3be2a919c4a8a8a32cbf76f54b12d6652ff5e..9a8535ece8dd1b4c0c429901a0837cb3c9376929 100755
--- a/install/tools/ipa-replica-conncheck
+++ b/install/tools/ipa-replica-conncheck
@@ -387,20 +387,21 @@ def main():
print_info("Connection check timeout: terminating listening program")
if __name__ == "__main__":
- try:
- sys.exit(main())
- except SystemExit, e:
- sys.exit(e)
- except KeyboardInterrupt:
- print_info("\nCleaning up...")
- sys.exit(1)
- except RuntimeError, e:
- sys.exit(e)
- finally:
- clean_responders(RESPONDERS)
- for file_name in (CCACHE_FILE, KRB5_CONFIG):
- if file_name:
- try:
- os.remove(file_name)
- except OSError:
- pass
+ with installutils.script_context('ipa-replica-conncheck'):
+ try:
+ sys.exit(main())
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt:
+ print_info("\nCleaning up...")
+ sys.exit(1)
+ except RuntimeError, e:
+ sys.exit(e)
+ finally:
+ clean_responders(RESPONDERS)
+ for file_name in (CCACHE_FILE, KRB5_CONFIG):
+ if file_name:
+ try:
+ os.remove(file_name)
+ except OSError:
+ pass
diff --git a/install/tools/ipa-replica-install b/install/tools/ipa-replica-install
index 07b1781ee7f99cacf1a3abbd6207b95f38da1807..d8240120181b49e335b09cd72f88f534327ac088 100755
--- a/install/tools/ipa-replica-install
+++ b/install/tools/ipa-replica-install
@@ -487,41 +487,42 @@ def main():
#Everything installed properly, activate ipa service.
ipaservices.knownservices.ipa.enable()
-try:
- if not os.geteuid()==0:
- sys.exit("\nYou must be root to run this script.\n")
-
- main()
- sys.exit(0)
-except SystemExit, e:
- sys.exit(e)
-except socket.error, (errno, errstr):
- print errstr
-except HostnameLocalhost:
- print "The hostname resolves to the localhost address (127.0.0.1/::1)"
- print "Please change your /etc/hosts file so that the hostname"
- print "resolves to the ip address of your network interface."
- print ""
- print "Please fix your /etc/hosts file and restart the setup program"
-except Exception, e:
- print "creation of replica failed: %s" % str(e)
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
-except KeyboardInterrupt:
- print "Installation cancelled."
-finally:
- # always try to remove decrypted replica file
+with installutils.script_context('ipa-replica-install'):
try:
- if REPLICA_INFO_TOP_DIR:
- shutil.rmtree(REPLICA_INFO_TOP_DIR)
- except OSError:
- pass
+ if not os.geteuid()==0:
+ sys.exit("\nYou must be root to run this script.\n")
-print ""
-print "Your system may be partly configured."
-print "Run /usr/sbin/ipa-server-install --uninstall to clean up."
+ main()
+ sys.exit(0)
+ except SystemExit, e:
+ sys.exit(e)
+ except socket.error, (errno, errstr):
+ print errstr
+ except HostnameLocalhost:
+ print "The hostname resolves to the localhost address (127.0.0.1/::1)"
+ print "Please change your /etc/hosts file so that the hostname"
+ print "resolves to the ip address of your network interface."
+ print ""
+ print "Please fix your /etc/hosts file and restart the setup program"
+ except Exception, e:
+ print "creation of replica failed: %s" % str(e)
+ message = str(e)
+ for str in traceback.format_tb(sys.exc_info()[2]):
+ message = message + "\n" + str
+ root_logger.debug(message)
+ except KeyboardInterrupt:
+ print "Installation cancelled."
+ finally:
+ # always try to remove decrypted replica file
+ try:
+ if REPLICA_INFO_TOP_DIR:
+ shutil.rmtree(REPLICA_INFO_TOP_DIR)
+ except OSError:
+ pass
-# the only way to get here is on error or ^C
-sys.exit(1)
+ print ""
+ print "Your system may be partly configured."
+ print "Run /usr/sbin/ipa-server-install --uninstall to clean up."
+
+ # the only way to get here is on error or ^C
+ sys.exit(1)
diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage
index f1f5425ca8d4083e7cb11f8d25f327ffb4ab2520..f7de94f2b00346b999611824045fc3e3393c0708 100755
--- a/install/tools/ipa-replica-manage
+++ b/install/tools/ipa-replica-manage
@@ -532,25 +532,26 @@ def main():
replica2 = args[1]
del_link(realm, replica1, replica2, dirman_passwd)
-try:
- main()
-except KeyboardInterrupt:
- sys.exit(1)
-except SystemExit, e:
- sys.exit(e)
-except RuntimeError, e:
- sys.exit(e)
-except ldap.INVALID_CREDENTIALS:
- print "Invalid password"
- sys.exit(1)
-except ldap.INSUFFICIENT_ACCESS:
- print "Insufficient access"
- sys.exit(1)
-except ldap.LOCAL_ERROR, e:
- print e.args[0]['info']
- sys.exit(1)
-except ldap.SERVER_DOWN, e:
- print e.args[0]['desc']
-except Exception, e:
- print "unexpected error: %s" % str(e)
- sys.exit(1)
+with installutils.script_context('ipa-replica-manage'):
+ try:
+ main()
+ except KeyboardInterrupt:
+ sys.exit(1)
+ except SystemExit, e:
+ sys.exit(e)
+ except RuntimeError, e:
+ sys.exit(e)
+ except ldap.INVALID_CREDENTIALS:
+ print "Invalid password"
+ sys.exit(1)
+ except ldap.INSUFFICIENT_ACCESS:
+ print "Insufficient access"
+ sys.exit(1)
+ except ldap.LOCAL_ERROR, e:
+ print e.args[0]['info']
+ sys.exit(1)
+ except ldap.SERVER_DOWN, e:
+ print e.args[0]['desc']
+ except Exception, e:
+ print "unexpected error: %s" % str(e)
+ sys.exit(1)
diff --git a/install/tools/ipa-replica-prepare b/install/tools/ipa-replica-prepare
index c54aa62b8e0e49fcc30d1359423dfa8615cc9cfe..8f26c466f39aa7903adae5576cb52bc389757767 100755
--- a/install/tools/ipa-replica-prepare
+++ b/install/tools/ipa-replica-prepare
@@ -453,20 +453,21 @@ def main():
add_reverse_zone(reverse_zone)
add_ptr_rr(reverse_zone, ip_address, replica_fqdn)
-try:
- if not os.geteuid()==0:
- sys.exit("\nYou must be root to run this script.\n")
+with installutils.script_context('ipa-replica-prepare'):
+ try:
+ if not os.geteuid()==0:
+ sys.exit("\nYou must be root to run this script.\n")
- main()
-except SystemExit, e:
- sys.exit(e)
-except RuntimeError, e:
- sys.exit(e)
-except Exception, e:
- print "preparation of replica failed: %s" % str(e)
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
- print message
- sys.exit(1)
+ main()
+ except SystemExit, e:
+ sys.exit(e)
+ except RuntimeError, e:
+ sys.exit(e)
+ except Exception, e:
+ print "preparation of replica failed: %s" % str(e)
+ message = str(e)
+ for str in traceback.format_tb(sys.exc_info()[2]):
+ message = message + "\n" + str
+ root_logger.debug(message)
+ print message
+ sys.exit(1)
diff --git a/install/tools/ipa-server-certinstall b/install/tools/ipa-server-certinstall
index 901678b2e8e250ed7d460df326ff965e74d6167e..28c4074d0813c77f0981bd6648facb5ec95fb3b2 100755
--- a/install/tools/ipa-server-certinstall
+++ b/install/tools/ipa-server-certinstall
@@ -165,12 +165,13 @@ def main():
return 0
-try:
- if not os.geteuid()==0:
- sys.exit("\nYou must be root to run this script.\n")
+with installutils.script_context('ipa-server-certinstall'):
+ try:
+ if not os.geteuid()==0:
+ sys.exit("\nYou must be root to run this script.\n")
- main()
-except SystemExit, e:
- sys.exit(e)
-except RuntimeError, e:
- sys.exit(e)
+ main()
+ except SystemExit, e:
+ sys.exit(e)
+ except RuntimeError, e:
+ sys.exit(e)
diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install
index 1dd02ba870a02e902c4c345d9f5802ef09f78a7a..ab86794952da2c56c67525f38205a71934a15166 100755
--- a/install/tools/ipa-server-install
+++ b/install/tools/ipa-server-install
@@ -49,6 +49,7 @@ from ipaserver.install import ntpinstance
from ipaserver.install import certs
from ipaserver.install import cainstance
from ipaserver.install import memcacheinstance
+from ipaserver.install import installutils
from ipaserver.install import service
from ipapython import version
@@ -1094,37 +1095,38 @@ def main():
os.remove(ANSWER_CACHE)
return 0
-try:
- success = True
+with installutils.script_context('ipa-server-install'):
try:
- rval = main()
- if rval != 0:
- success = False
- sys.exit(rval)
- except SystemExit, e:
- if e.code is not None or e.code != 0:
- success = False
- sys.exit(e)
- except Exception, e:
- success = False
- if uninstalling:
- message = "Unexpected error - see ipaserver-uninstall.log for details:\n %s" % str(e)
- else:
- message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
- print message
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
- sys.exit(1)
-finally:
- if pw_name and ipautil.file_exists(pw_name):
- os.remove(pw_name)
-
- if not success and installation_cleanup:
- # Do a cautious clean up as we don't know what failed and what is
- # the state of the environment
+ success = True
try:
- fstore.restore_file('/etc/hosts')
- except:
- pass
+ rval = main()
+ if rval != 0:
+ success = False
+ sys.exit(rval)
+ except SystemExit, e:
+ if e.code is not None or e.code != 0:
+ success = False
+ sys.exit(e)
+ except Exception, e:
+ success = False
+ if uninstalling:
+ message = "Unexpected error - see ipaserver-uninstall.log for details:\n %s" % str(e)
+ else:
+ message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
+ print message
+ message = str(e)
+ for str in traceback.format_tb(sys.exc_info()[2]):
+ message = message + "\n" + str
+ root_logger.debug(message)
+ sys.exit(1)
+ finally:
+ if pw_name and ipautil.file_exists(pw_name):
+ os.remove(pw_name)
+
+ if not success and installation_cleanup:
+ # Do a cautious clean up as we don't know what failed and what is
+ # the state of the environment
+ try:
+ fstore.restore_file('/etc/hosts')
+ except:
+ pass
diff --git a/install/tools/ipa-upgradeconfig b/install/tools/ipa-upgradeconfig
index 40a2b68ce89b58b98077428783a98e3060674665..ce02b288e14824aea607b550cde14947fa6bdcd3 100644
--- a/install/tools/ipa-upgradeconfig
+++ b/install/tools/ipa-upgradeconfig
@@ -297,10 +297,12 @@ def main():
cleanup_kdc()
upgrade_ipa_profile(krbctx.default_realm)
-try:
- if __name__ == "__main__":
- sys.exit(main())
-except SystemExit, e:
- sys.exit(e)
-except KeyboardInterrupt, e:
- sys.exit(1)
+
+with installutils.script_context('ipa-upgradeconfig'):
+ try:
+ if __name__ == "__main__":
+ sys.exit(main())
+ except SystemExit, e:
+ sys.exit(e)
+ except KeyboardInterrupt, e:
+ sys.exit(1)
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 3e7ae41b5fdbc11353e43a63424f19fbc331435a..851b58de230b324cb8256883156702d7d6f61c04 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -31,6 +31,7 @@
import tempfile
import shutil
from ConfigParser import SafeConfigParser
+import contextlib
from ipapython import ipautil, dnsclient, sysrestore
from ipapython.ipa_log_manager import *
@@ -712,3 +713,23 @@ def is_ipa_configured():
root_logger.debug('filestore is tracking no files')
return installed
+
+
+@contextlib.contextmanager
+def script_context(operation_name):
+ def final_log(template):
+ # Only log if logging was already configured
+ # TODO: Do this properly (e.g. configure logging before the try/except)
+ if log_mgr.handlers.keys() != ['console']:
+ root_logger.info(template, operation_name)
+ try:
+ yield
+ except BaseException, e:
+ if isinstance(e, SystemExit) and (e.code is None or e.code == 0):
+ # Not an error after all
+ final_log('The %s command was successful')
+ else:
+ final_log('The %s command failed')
+ raise
+ else:
+ final_log('The %s command was successful')
--
1.7.7.6
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel