summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2008-12-03 09:00:23 -0500
committerSimo Sorce <ssorce@redhat.com>2008-12-03 11:17:06 -0500
commita9cf868a5591c2952bda72b269cf1cb812d437c7 (patch)
treeaa85e84c2239a4285b287e1150892da875cd00db
parentea04ad5888972ff527e4351bf837658a77ba8fe2 (diff)
downloadfreeipa-a9cf868a5591c2952bda72b269cf1cb812d437c7.zip
freeipa-a9cf868a5591c2952bda72b269cf1cb812d437c7.tar.gz
freeipa-a9cf868a5591c2952bda72b269cf1cb812d437c7.tar.xz
Change ipa-compat-manage to work on older python versions too. Break try,except,finally into a try,try,finally,except Add also checks for LDAPError, errors.
-rwxr-xr-xipa-server/ipa-compat-manage86
1 files changed, 50 insertions, 36 deletions
diff --git a/ipa-server/ipa-compat-manage b/ipa-server/ipa-compat-manage
index 048d6fd..f105f1c 100755
--- a/ipa-server/ipa-compat-manage
+++ b/ipa-server/ipa-compat-manage
@@ -94,46 +94,57 @@ def main():
else:
dirman_password = get_dirman_password()
- if args[0] == "enable":
+ try:
try:
conn = ipaldap.IPAdmin(installutils.get_fqdn())
conn.do_simple_bind(bindpw=dirman_password)
- conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config",
- ldap.SCOPE_BASE, "(objectclass=*)")
- print "Plugin already Enabled"
- retval = 2
- except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
- print "Enabling plugin"
- finally:
- if conn:
- conn.unbind()
-
- if retval == 0:
- ld = LDAPUpdate(dm_password=dirman_password, sub_dict={})
- retval = ld.update(files)
- if retval == 0:
- print "This setting will not take effect until you restart Directory Server."
-
- elif args[0] == "disable":
- # Make a quick hack foir now, directly delete the entries by name,
- # In future we should add delete capabilites to LDAPUpdate
- try:
- conn = ipaldap.IPAdmin(installutils.get_fqdn())
- conn.do_simple_bind(bindpw=dirman_password)
- conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config",
- ldap.SCOPE_BASE, "(objectclass=*)")
- conn.deleteEntry("cn=groups,cn=Schema Compatibility,cn=plugins,cn=config")
- conn.deleteEntry("cn=users,cn=Schema Compatibility,cn=plugins,cn=config")
- conn.deleteEntry("cn=Schema Compatibility,cn=plugins,cn=config")
- except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
- print "Plugin is already disabled"
- retval = 2
- finally:
- if conn:
- conn.unbind()
+ except ldap.LDAPError, e:
+ print "An error occurred while connecting to the server."
+ print "%s" % e[0]['desc']
+ return 1
+
+ if args[0] == "enable":
+ try:
+ conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config",
+ ldap.SCOPE_BASE, "(objectclass=*)")
+ print "Plugin already Enabled"
+ retval = 2
+ except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
+ print "Enabling plugin"
+ except ldap.LDAPError, e:
+ print "An error occurred while talking to the server."
+ print "%s" % e[0]['desc']
+ retval = 1
- else:
- retval = 1
+ if retval == 0:
+ ld = LDAPUpdate(dm_password=dirman_password, sub_dict={})
+ retval = ld.update(files)
+ if retval == 0:
+ print "This setting will not take effect until you restart Directory Server."
+
+ elif args[0] == "disable":
+ # Make a quick hack foir now, directly delete the entries by name,
+ # In future we should add delete capabilites to LDAPUpdate
+ try:
+ conn.getEntry("cn=Schema Compatibility,cn=plugins,cn=config",
+ ldap.SCOPE_BASE, "(objectclass=*)")
+ conn.deleteEntry("cn=groups,cn=Schema Compatibility,cn=plugins,cn=config")
+ conn.deleteEntry("cn=users,cn=Schema Compatibility,cn=plugins,cn=config")
+ conn.deleteEntry("cn=Schema Compatibility,cn=plugins,cn=config")
+ except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
+ print "Plugin is already disabled"
+ retval = 2
+ except ldap.LDAPError, e:
+ print "An error occurred while talking to the server."
+ print "%s" % e[0]['desc']
+ retval = 1
+
+ else:
+ retval = 1
+
+ finally:
+ if conn:
+ conn.unbind()
return retval
@@ -155,3 +166,6 @@ 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 ipaerror, e:
+ print "An error occurred while performing operations: %s" % e
+ sys.exit(1)