On 03/01/2012 11:45 AM, Petr Viktorin wrote:
On 02/29/2012 07:46 PM, Rob Crittenden wrote:
Martin Kosek wrote:
On Mon, 2012-02-27 at 17:51 +0100, Petr Viktorin wrote:
On 02/22/2012 10:41 AM, Petr Viktorin wrote:
This fixes https://fedorahosted.org/freeipa/ticket/2071 (Add final
debug
message in installers). The try/except blocks at the end of
installers/management scripts are replaced by a call to a common
function, which includes the final message.

Obviously the installers still need some more love. This is as far
as I
got before Martin stopped me, saying I shouldn't change too much
before
a release :)


If it's still too many changes to test, I could just wrap the
blocks in
some `with add_final_message` block for now, and resubmit this patch
after the release.



Yeah, this is exactly the kind of changes that can have yet-unseen
consequences and I don't like pushing this close to the release.

The original ticket just asks for a debug message when the install
script ends. If possible, I would really prefer to have some low-risk
patch adding just those and leave install script refactoring for next
big release, like 3.x. Rob, what's your opinion on this?

Martin


Yes, I agree. Simpler is better at this point.

rob

This patch simply wraps the try blocks in a context that logs the final
result.
Most of the changes are indentation; diff with -w to see the additions.

Not sure if this would count as an update or a new patch...



_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Rebased against current master.

--
PetrĀ³
From b4d10086b34b63215af1437c138d8857b2355962 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  |   33 ++++++++--------
 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    |   16 ++++++++
 17 files changed, 347 insertions(+), 313 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 096020c5e2619c3719eed15098ec2b1239b720ce..861453951814eea9a37dfb1b625f559ee840bfc5 100755
--- a/install/tools/ipa-dns-install
+++ b/install/tools/ipa-dns-install
@@ -240,26 +240,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 44b3caa45a20d3a72985c051a7982da1f9716147..bf9cffe67469209d15f9c95dc38c3665dea693bb 100755
--- a/install/tools/ipa-replica-conncheck
+++ b/install/tools/ipa-replica-conncheck
@@ -379,20 +379,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:
-        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:
+            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 65f5229df222a54a6a159d6f2f31067015369d8d..66e5943d784457a062601a343934d28b83683a27 100755
--- a/install/tools/ipa-replica-install
+++ b/install/tools/ipa-replica-install
@@ -483,41 +483,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")
+with installutils.script_context('ipa-replica-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-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 9c7388b40dc00385e816bd939a1a843070eea662..1145479d1beecf3bc7a4177f7c5f6e62756c2f0b 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
@@ -1091,37 +1092,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..4d45a48d55d63d0f424601aae39bc79c6818a0c7 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -31,6 +31,7 @@ import time
 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,18 @@ def is_ipa_configured():
         root_logger.debug('filestore is tracking no files')
 
     return installed
+
+
+@contextlib.contextmanager
+def script_context(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
+            root_logger.info('%s successful', operation_name)
+        else:
+            root_logger.error('%s failed, %s: %s', operation_name, type(e).__name__, e)
+        raise
+    else:
+        root_logger.info('%s successful', operation_name)
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to