Modernize 'except' clauses

The 'as' syntax works from Python 2 on, and Python 3 will
drop the "comma" syntax.

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Petr Viktorin
2015-08-12 18:17:23 +02:00
committed by Tomas Babej
parent a651be3eec
commit 27dabb4528
118 changed files with 661 additions and 661 deletions
@@ -213,7 +213,7 @@ def store_cert():
conn.add_entry(entry)
except errors.EmptyModlist:
pass
except Exception, e:
except Exception as e:
attempts += 1
if attempts < 10:
syslog.syslog(
@@ -365,7 +365,7 @@ def export_csr():
try:
with open(csr_file, 'wb') as f:
f.write(csr)
except Exception, e:
except Exception as e:
return (UNREACHABLE, "Failed to write %s: %s" % (csr_file, e))
return (ISSUED, cert)
@@ -464,7 +464,7 @@ def main():
try:
sys.exit(main())
except Exception, e:
except Exception as e:
syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
print "Internal error"
sys.exit(UNREACHABLE)
+1 -1
View File
@@ -49,7 +49,7 @@ def main():
try:
sys.exit(main())
except Exception, e:
except Exception as e:
syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
print "Internal error"
sys.exit(3)
+2 -2
View File
@@ -52,12 +52,12 @@ def bind(ldap_uri, base_dn, username, password):
try:
conn = IPAdmin(ldap_uri=ldap_uri)
conn.do_simple_bind(bind_dn, password)
except (errors.ACIError, errors.DatabaseError, errors.NotFound), e:
except (errors.ACIError, errors.DatabaseError, errors.NotFound) as e:
root_logger.error(
'migration invalid credentials for %s: %s' % (bind_dn, e))
raise IOError(
errno.EPERM, 'Invalid LDAP credentials for user %s' % username)
except Exception, e:
except Exception as e:
root_logger.error('migration bind failed: %s' % e)
raise IOError(errno.EIO, 'Bind error')
finally:
+2 -2
View File
@@ -664,7 +664,7 @@ def main():
'style=', 'verbose', 'version', 'width=', 'exclude-file=',
'docstrings', 'no-docstrings',
])
except getopt.error, msg:
except getopt.error as msg:
usage(1, msg)
# for holding option values
@@ -787,7 +787,7 @@ def main():
eater.set_filename(filename)
try:
tokenize.tokenize(fp.readline, eater)
except tokenize.TokenError, e:
except tokenize.TokenError as e:
print >> sys.stderr, '%s: %s, line %d, column %d' % (
e[0], filename, e[1][0], e[1][1])
finally:
+6 -6
View File
@@ -56,7 +56,7 @@ def _main():
syslog.LOG_NOTICE, "Stopping %s" % dogtag_service.service_name)
try:
dogtag_service.stop(dogtag_instance)
except Exception, e:
except Exception as e:
syslog.syslog(
syslog.LOG_ERR,
"Cannot stop %s: %s" % (dogtag_service.service_name, e))
@@ -142,7 +142,7 @@ def _main():
try:
conn = ldap2(api)
conn.connect(ccache=ccache_filename)
except Exception, e:
except Exception as e:
syslog.syslog(
syslog.LOG_ERR, "Failed to connect to LDAP: %s" % e)
else:
@@ -152,7 +152,7 @@ def _main():
certstore.update_ca_cert(conn, api.env.basedn, cert)
except errors.EmptyModlist:
pass
except Exception, e:
except Exception as e:
syslog.syslog(
syslog.LOG_ERR,
"Updating CA certificate failed: %s" % e)
@@ -163,7 +163,7 @@ def _main():
ca_certs = certstore.get_ca_certs(
conn, api.env.basedn, api.env.realm, False,
filter_subject=ca_issuer)
except Exception, e:
except Exception as e:
syslog.syslog(
syslog.LOG_ERR,
"Failed to get external CA certificates from LDAP: "
@@ -185,7 +185,7 @@ def _main():
try:
db.add_cert(ca_cert, nick, flags)
except ipautil.CalledProcessError, e:
except ipautil.CalledProcessError as e:
syslog.syslog(
syslog.LOG_ERR,
"Failed to add certificate %s" % ca_nick)
@@ -204,7 +204,7 @@ def _main():
'Starting %s' % dogtag_service.service_name)
try:
dogtag_service.start(dogtag_instance)
except Exception, e:
except Exception as e:
syslog.syslog(
syslog.LOG_ERR,
"Cannot start %s: %s" % (dogtag_service.service_name, e))
+1 -1
View File
@@ -67,7 +67,7 @@ def _main():
syslog.syslog(syslog.LOG_NOTICE, "Restarting httpd")
try:
services.knownservices.httpd.restart()
except Exception, e:
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "Cannot restart httpd: %s" % e)
else:
syslog.syslog(syslog.LOG_NOTICE, "Restarted httpd")
+1 -1
View File
@@ -40,7 +40,7 @@ def _main():
try:
services.knownservices.dirsrv.restart(instance)
except Exception, e:
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "Cannot restart dirsrv (instance: '%s'): %s" % (instance, str(e)))
+1 -1
View File
@@ -30,7 +30,7 @@ def _main():
try:
services.knownservices.httpd.restart()
except Exception, e:
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "Cannot restart httpd: %s" % str(e))
+1 -1
View File
@@ -41,7 +41,7 @@ def main():
syslog.syslog(syslog.LOG_NOTICE, "Stopping %s" % dogtag_service.service_name)
try:
dogtag_service.stop(dogtag_instance)
except Exception, e:
except Exception as e:
syslog.syslog(
syslog.LOG_ERR, "Cannot stop %s: %s" % (dogtag_service.service_name, e))
else:
+1 -1
View File
@@ -82,7 +82,7 @@ def add_ca_schema():
continue
try:
shutil.copyfile(source_fname, target_fname)
except IOError, e:
except IOError as e:
root_logger.warning('Could not install %s: %s', target_fname, e)
else:
root_logger.info('Installed %s', target_fname)
+1 -1
View File
@@ -38,7 +38,7 @@ env._finalize_core(**dict(DEFAULT_CONFIG))
api.bootstrap(context='server', debug=env.debug, log=None)
try:
api.finalize()
except StandardError, e:
except StandardError as e:
api.log.error('Failed to start IPA: %s' % e)
else:
api.log.info('*** PROCESS START ***')
+9 -9
View File
@@ -194,7 +194,7 @@ def set_and_check_netbios_name(netbios_name, unattended):
def ensure_admin_kinit(admin_name, admin_password):
try:
ipautil.run(['kinit', admin_name], stdin=admin_password+'\n')
except ipautil.CalledProcessError, e:
except ipautil.CalledProcessError as e:
print "There was error to automatically re-kinit your admin user ticket."
return False
return True
@@ -305,14 +305,14 @@ def main():
ctx = krbV.default_context()
ccache = ctx.default_ccache()
principal = ccache.principal()
except krbV.Krb5Error, e:
except krbV.Krb5Error as e:
sys.exit("Must have Kerberos credentials to setup AD trusts on server")
try:
api.Backend.ldap2.connect(ccache)
except errors.ACIError, e:
except errors.ACIError as e:
sys.exit("Outdated Kerberos credentials. Use kdestroy and kinit to update your ticket")
except errors.DatabaseError, e:
except errors.DatabaseError as e:
sys.exit("Cannot connect to the LDAP database. Please check if IPA is running")
try:
@@ -321,9 +321,9 @@ def main():
if not (user['uid'][0] in group['member_user'] and
group['cn'][0] in user['memberof_group']):
raise errors.RequirementError(name='admins group membership')
except errors.RequirementError, e:
except errors.RequirementError as e:
sys.exit("Must have administrative privileges to setup AD trusts on server")
except Exception, e:
except Exception as e:
sys.exit("Unrecognized error during check of admin rights: %s" % (str(e)))
(netbios_name, reset_netbios_name) = \
@@ -344,7 +344,7 @@ def main():
except errors.NotFound:
# All objects have SIDs assigned
pass
except (errors.DatabaseError, errors.NetworkError), e:
except (errors.DatabaseError, errors.NetworkError) as e:
print "Could not retrieve a list of objects that need a SID identifier assigned:"
print unicode(e)
else:
@@ -400,7 +400,7 @@ def main():
base_dn=masters_dn, attrs_list=['cn'], scope=ldap.SCOPE_ONELEVEL)
except errors.NotFound:
pass
except (errors.DatabaseError, errors.NetworkError), e:
except (errors.DatabaseError, errors.NetworkError) as e:
print "Could not retrieve a list of existing IPA masters:"
print unicode(e)
@@ -409,7 +409,7 @@ def main():
base_dn=agents_dn, attrs_list=['member'], scope=ldap.SCOPE_BASE)
except errors.NotFound:
pass
except (errors.DatabaseError, errors.NetworkError), e:
except (errors.DatabaseError, errors.NetworkError) as e:
print "Could not retrieve a list of adtrust agents:"
print unicode(e)
+7 -7
View File
@@ -111,9 +111,9 @@ def main():
conn.connect(
bind_dn=DN(('cn', 'directory manager')), bind_pw=dirman_password
)
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
sys.exit("An error occurred while connecting to the server.\n%s\n" % str(lde))
except errors.ACIError, e:
except errors.ACIError as e:
sys.exit("Authentication failed: %s" % e.info)
if args[0] == "status":
@@ -124,7 +124,7 @@ def main():
print "Plugin Enabled"
else:
print "Plugin Disabled"
except errors.LDAPError, lde:
except errors.LDAPError as lde:
print "An error occurred while talking to the server."
print lde
@@ -146,7 +146,7 @@ def main():
else:
entry['nsslapd-pluginenabled'] = ['on']
conn.update_entry(entry)
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
@@ -160,7 +160,7 @@ def main():
print >>sys.stderr, "The NIS plugin is configured, cannot disable compatibility."
print >>sys.stderr, "Run 'ipa-nis-manage disable' first."
retval = 2
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
@@ -177,11 +177,11 @@ def main():
entry['nsslapd-pluginenabled'] = ['off']
conn.update_entry(entry)
except errors.DatabaseError, dbe:
except errors.DatabaseError as dbe:
print "An error occurred while talking to the server."
print dbe
retval = 1
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
+20 -20
View File
@@ -105,7 +105,7 @@ def list_replicas(realm, host, replica, dirman_passwd, verbose):
except errors.NotFound:
peers[ent.single_value['cn']] = ['CA not configured', '']
except Exception, e:
except Exception as e:
sys.exit(
"Failed to get data from '%s' while trying to list replicas: %s" %
(host, e))
@@ -119,7 +119,7 @@ def list_replicas(realm, host, replica, dirman_passwd, verbose):
try:
repl = replication.get_cs_replication_manager(realm, replica, dirman_passwd)
except Exception, e:
except Exception as e:
sys.exit(str(e))
entries = repl.find_replication_agreements()
@@ -162,9 +162,9 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
repl1.hostnames = [replica1, replica2]
except errors.NetworkError, e:
except errors.NetworkError as e:
sys.exit("Unable to connect to %s: %s" % (replica1, e))
except Exception, e:
except Exception as e:
sys.exit("Failed to get data from '%s': %s" % (replica1, e))
try:
@@ -201,7 +201,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
print "'%s' has no replication agreement for '%s'" % (replica2, replica1)
if not force:
return
except Exception, e:
except Exception as e:
print "Failed to get data from '%s': %s" % (replica2, e)
if not force:
sys.exit(1)
@@ -211,7 +211,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
try:
repl2.delete_agreement(replica1, replica2_dn)
repl2.delete_referral(replica1, repl1.port)
except Exception, e:
except Exception as e:
print "Unable to remove agreement on %s: %s" % (replica2, e)
failed = True
@@ -239,7 +239,7 @@ def del_master(realm, hostname, options):
try:
thisrepl = replication.get_cs_replication_manager(realm, options.host,
options.dirman_passwd)
except Exception, e:
except Exception as e:
sys.exit("Failed to connect to server %s: %s" % (options.host, e))
# 2. Ensure we have an agreement with the master
@@ -250,7 +250,7 @@ def del_master(realm, hostname, options):
try:
delrepl = replication.get_cs_replication_manager(realm, hostname,
options.dirman_passwd)
except Exception, e:
except Exception as e:
if not options.force:
print "Unable to delete replica %s: %s" % (hostname, e)
sys.exit(1)
@@ -271,7 +271,7 @@ def del_master(realm, hostname, options):
for r in replica_names:
try:
del_link(realm, r, hostname, options.dirman_passwd, force=True)
except Exception, e:
except Exception as e:
sys.exit("There were issues removing a connection: %s" % e)
# 6. Pick CA renewal master
@@ -287,7 +287,7 @@ def del_master(realm, hostname, options):
bind_pw=options.dirman_passwd)
bind = bindinstance.BindInstance()
bind.remove_ipa_ca_dns_records(hostname, realm.lower())
except Exception, e:
except Exception as e:
print "Failed to cleanup %s DNS entries: %s" % (hostname, e)
print "You may need to manually remove them from the tree"
@@ -295,7 +295,7 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
try:
repl2 = replication.get_cs_replication_manager(realm, replica2,
dirman_passwd)
except Exception, e:
except Exception as e:
sys.exit(str(e))
try:
conn = ipaldap.IPAdmin(replica2, 636, cacert=CACERT)
@@ -307,9 +307,9 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
conn.unbind()
except errors.NotFound:
sys.exit('%s does not have a CA configured.' % replica2)
except errors.NetworkError, e:
except errors.NetworkError as e:
sys.exit("Unable to connect to %s: %s" % (ipautil.format_netloc(replica2, 636), str(e)))
except Exception, e:
except Exception as e:
sys.exit("Failed to get data while trying to bind to '%s': %s" % (replica1, str(e)))
try:
@@ -323,9 +323,9 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
except errors.NotFound:
sys.exit("Cannot find replica '%s'" % replica1)
except errors.NetworkError, e:
except errors.NetworkError as e:
sys.exit("Unable to connect to %s: %s" % (replica1, e))
except Exception, e:
except Exception as e:
sys.exit(
"Failed to get data from '%s' while trying to get current "
"agreements: %s" % (replica1, e))
@@ -347,7 +347,7 @@ def re_initialize(realm, options):
options.dirman_passwd)
thisrepl = replication.get_cs_replication_manager(realm, thishost,
options.dirman_passwd)
except Exception, e:
except Exception as e:
sys.exit(str(e))
filter = repl.get_agreement_filter(host=thishost)
@@ -373,7 +373,7 @@ def force_sync(realm, thishost, fromhost, dirman_passwd):
repl = replication.get_cs_replication_manager(realm, fromhost,
dirman_passwd)
repl.force_sync(repl.conn, thishost)
except Exception, e:
except Exception as e:
sys.exit(str(e))
def set_renewal_master(realm, replica):
@@ -386,7 +386,7 @@ def set_renewal_master(realm, replica):
try:
ca.set_renewal_master(replica)
except Exception, e:
except Exception as e:
sys.exit("Failed to set renewal master to %s: %s" % (replica, e))
print "%s is now the renewal master" % replica
@@ -465,7 +465,7 @@ try:
main()
except KeyboardInterrupt:
sys.exit(1)
except SystemExit, e:
except SystemExit as e:
sys.exit(e)
except Exception, e:
except Exception as e:
sys.exit("unexpected error: %s" % e)
+6 -6
View File
@@ -102,7 +102,7 @@ def main():
conn.do_simple_bind(bindpw=dirman_password)
except errors.ACIError:
sys.exit("Invalid credentials")
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
sys.exit("An error occurred while connecting to the server.\n%s\n" %
str(lde))
@@ -112,7 +112,7 @@ def main():
try:
entries = conn.get_entries(
managed_entry_definitions_dn, conn.SCOPE_SUBTREE, filter)
except Exception, e:
except Exception as e:
root_logger.debug("Search for managed entries failed: %s" % str(e))
sys.exit("Unable to find managed entries at %s" % managed_entry_definitions_dn)
managed_entries = [entry.single_value['cn'] for entry in entries]
@@ -140,7 +140,7 @@ def main():
sys.exit("%s is not a valid Managed Entry" % def_dn)
except errors.NotFound:
sys.exit("%s is not a valid Managed Entry" % def_dn)
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
@@ -166,7 +166,7 @@ def main():
retval = 0
except errors.NotFound:
print "Enabling Plugin"
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
@@ -190,11 +190,11 @@ def main():
except errors.NotFound:
print "Plugin is already disabled"
retval = 2
except errors.DatabaseError, dbe:
except errors.DatabaseError as dbe:
print "An error occurred while talking to the server."
print dbe
retval = 1
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
+5 -5
View File
@@ -124,7 +124,7 @@ def main():
conn.connect(
bind_dn=DN(('cn', 'directory manager')), bind_pw=dirman_password
)
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
sys.exit("An error occurred while connecting to the server: %s" % str(lde))
except errors.AuthorizationError:
sys.exit("Incorrect password")
@@ -136,7 +136,7 @@ def main():
entry = None
try:
entry = get_entry(nis_config_dn, conn)
except errors.ExecutionError, lde:
except errors.ExecutionError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
@@ -146,13 +146,13 @@ def main():
portmap = services.knownservices.portmap
portmap.enable()
servicemsg = portmap.service_name
except ipautil.CalledProcessError, cpe:
except ipautil.CalledProcessError as cpe:
if cpe.returncode == 1:
try:
rpcbind = services.knownservices.rpcbind
rpcbind.enable()
servicemsg = rpcbind.service_name
except ipautil.CalledProcessError, cpe:
except ipautil.CalledProcessError as cpe:
print "Unable to enable either %s or %s" % (portmap.service_name, rpcbind.service_name)
retval = 3
@@ -180,7 +180,7 @@ def main():
except (errors.NotFound, errors.EmptyModlist):
print "Plugin is already disabled"
retval = 2
except errors.LDAPError, lde:
except errors.LDAPError as lde:
print "An error occurred while talking to the server."
print lde
retval = 1
+3 -3
View File
@@ -255,7 +255,7 @@ class PortResponder(threading.Thread):
responder_data="FreeIPA")
except socket.timeout:
pass
except socket.error, e:
except socket.error as e:
if e.errno == errno.EADDRINUSE:
time.sleep(1)
else:
@@ -419,12 +419,12 @@ def main():
if __name__ == "__main__":
try:
sys.exit(main())
except SystemExit, e:
except SystemExit as e:
sys.exit(e)
except KeyboardInterrupt:
print_info("\nCleaning up...")
sys.exit(1)
except RuntimeError, e:
except RuntimeError as e:
sys.exit(e)
finally:
clean_responders(RESPONDERS)
+30 -30
View File
@@ -158,7 +158,7 @@ def list_replicas(realm, host, replica, dirman_passwd, verbose, nolookup=False):
conn.do_simple_bind(bindpw=dirman_passwd)
else:
conn.do_sasl_gssapi_bind()
except Exception, e:
except Exception as e:
print "Failed to connect to host '%s': %s" % (host, str(e))
return
@@ -212,7 +212,7 @@ def list_replicas(realm, host, replica, dirman_passwd, verbose, nolookup=False):
dirman_passwd)
entries = repl.find_replication_agreements()
ent_type = 'replica'
except Exception, e:
except Exception as e:
print "Failed to get data from '%s': %s" % (replica, e)
return
@@ -258,7 +258,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
else:
print "'%s' has no replication agreement for '%s'" % (replica1, replica2)
return False
except Exception, e:
except Exception as e:
print "Failed to determine agreement type for '%s': %s" % (replica2, e)
if type1 == replication.IPA_REPLICA and managed_topology:
@@ -284,7 +284,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
print "'%s' has no replication agreement for '%s'" % (replica2, replica1)
if not force:
return False
except Exception, e:
except Exception as e:
print "Failed to get list of agreements from '%s': %s" % (replica2, e)
if not force:
return False
@@ -308,7 +308,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
repl2.delete_agreement(replica1)
repl2.delete_referral(replica1)
repl2.set_readonly(readonly=False)
except Exception, e:
except Exception as e:
print "Unable to remove agreement on %s: %s" % (replica2, e)
failed = True
@@ -335,7 +335,7 @@ def del_link(realm, replica1, replica2, dirman_passwd, force=False):
entries.sort(key=lambda x: len(x.dn), reverse=True)
for entry in entries:
repl1.conn.delete_entry(entry)
except Exception, e:
except Exception as e:
print "Error deleting winsync replica shared info: %s" % e
print "Deleted replication agreement from '%s' to '%s'" % (replica1, replica2)
@@ -352,7 +352,7 @@ def get_ruv(realm, host, dirman_passwd, nolookup=False):
try:
thisrepl = replication.ReplicationManager(realm, host, dirman_passwd)
except Exception, e:
except Exception as e:
print "Failed to connect to server %s: %s" % (host, e)
sys.exit(1)
@@ -687,7 +687,7 @@ def cleanup_server_dns_entries(realm, hostname, suffix, options):
keysyncd = dnskeysyncinstance.DNSKeySyncInstance()
keysyncd.remove_replica_public_keys(hostname)
except Exception, e:
except Exception as e:
print "Failed to cleanup %s DNS entries: %s" % (hostname, e)
print "You may need to manually remove them from the tree"
@@ -740,7 +740,7 @@ def del_master_managed(realm, hostname, options):
# 6. Cleanup
try:
thisrepl.replica_cleanup(hostname, realm, force=True)
except Exception, e:
except Exception as e:
print "Failed to cleanup %s entries: %s" % (hostname, e)
print "You may need to manually remove them from the tree"
@@ -815,7 +815,7 @@ def del_master_direct(realm, hostname, options):
try:
thisrepl = replication.ReplicationManager(realm, options.host,
options.dirman_passwd)
except Exception, e:
except Exception as e:
print "Failed to connect to server %s: %s" % (options.host, e)
sys.exit(1)
@@ -844,7 +844,7 @@ def del_master_direct(realm, hostname, options):
winsync = False
try:
delrepl = replication.ReplicationManager(realm, hostname, options.dirman_passwd)
except Exception, e:
except Exception as e:
print "Connection to '%s' failed: %s" % (hostname, e)
if not options.force:
print "Unable to delete replica '%s'" % hostname
@@ -888,7 +888,7 @@ def del_master_direct(realm, hostname, options):
if delrepl and not winsync:
try:
masters = api.Command.server_find('', sizelimit=0)['result']
except Exception, e:
except Exception as e:
masters = []
print "Failed to read masters data from '%s': %s" % (
delrepl.hostname, e)
@@ -923,7 +923,7 @@ def del_master_direct(realm, hostname, options):
try:
if not del_link(realm, r, hostname, options.dirman_passwd, force=True):
print "Unable to remove replication agreement for %s from %s." % (hostname, r)
except Exception, e:
except Exception as e:
print ("There were issues removing a connection for %s "
"from %s: %s" % (hostname, r, e))
@@ -937,7 +937,7 @@ def del_master_direct(realm, hostname, options):
# 6. Finally clean up the removed replica common entries.
try:
thisrepl.replica_cleanup(hostname, realm, force=True)
except Exception, e:
except Exception as e:
print "Failed to cleanup %s entries: %s" % (hostname, e)
print "You may need to manually remove them from the tree"
@@ -965,7 +965,7 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
except errors.NotFound:
print "Cannot find replica '%s'" % replica1
return
except Exception, e:
except Exception as e:
print "Failed to connect to '%s': %s" % (replica1, e)
return
@@ -997,7 +997,7 @@ def add_link(realm, replica1, replica2, dirman_passwd, options):
except errors.NotFound:
print "Cannot find replica '%s'" % replica1
return
except Exception, e:
except Exception as e:
print "Failed to connect to '%s': %s" % (replica1, e)
return
@@ -1117,7 +1117,7 @@ def show_DNA_ranges(hostname, master, realm, dirman_passwd, nextrange=False,
try:
repl = replication.ReplicationManager(realm, hostname, dirman_passwd)
except Exception, e:
except Exception as e:
sys.exit("Connection failed: %s" % e)
dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), repl.suffix)
try:
@@ -1131,7 +1131,7 @@ def show_DNA_ranges(hostname, master, realm, dirman_passwd, nextrange=False,
continue
try:
repl2 = replication.ReplicationManager(realm, remote, dirman_passwd)
except Exception, e:
except Exception as e:
print "%s: Connection failed: %s" % (remote, e)
continue
if not nextrange:
@@ -1187,14 +1187,14 @@ def store_DNA_range(repl, range_start, range_max, deleted_master, realm,
continue
try:
repl2 = replication.ReplicationManager(realm, candidate, dirman_passwd)
except Exception, e:
except Exception as e:
print "Connection failed: %s" % e
continue
(next_start, next_max) = repl2.get_DNA_next_range(candidate)
if next_start is None:
try:
return repl2.save_DNA_next_range(range_start, range_max)
except Exception, e:
except Exception as e:
print '%s: %s' % (candidate, e)
return False
@@ -1226,7 +1226,7 @@ def set_DNA_range(hostname, range, realm, dirman_passwd, next_range=False,
"""
try:
(dna_next, dna_max) = range.split('-', 1)
except ValueError, e:
except ValueError as e:
return "Invalid range, must be the form x-y"
try:
@@ -1263,14 +1263,14 @@ def set_DNA_range(hostname, range, realm, dirman_passwd, next_range=False,
try:
repl = replication.ReplicationManager(realm, hostname, dirman_passwd)
except Exception, e:
except Exception as e:
sys.exit("Connection failed: %s" % e)
if dna_next > 0:
# Verify that the new range doesn't overlap with an existing range
dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), repl.suffix)
try:
entries = repl.conn.get_entries(dn, repl.conn.SCOPE_ONELEVEL)
except Exception, e:
except Exception as e:
sys.exit("Failed to read master data from '%s': %s" % (repl.conn.host, str(e)))
else:
for ent in entries:
@@ -1279,7 +1279,7 @@ def set_DNA_range(hostname, range, realm, dirman_passwd, next_range=False,
continue
try:
repl2 = replication.ReplicationManager(realm, master, dirman_passwd)
except Exception, e:
except Exception as e:
print "Connection to %s failed: %s" % (master, e)
print "Overlap not checked."
continue
@@ -1304,7 +1304,7 @@ def set_DNA_range(hostname, range, realm, dirman_passwd, next_range=False,
try:
entries = repl.conn.get_entries(dn, repl.conn.SCOPE_ONELEVEL,
"(objectclass=ipaDomainIDRange)")
except errors.NotFound, e:
except errors.NotFound as e:
sys.exit('Unable to load IPA ranges: %s' % e.message)
for ent in entries:
@@ -1336,7 +1336,7 @@ def set_DNA_range(hostname, range, realm, dirman_passwd, next_range=False,
sys.exit("No changes to make")
except errors.NotFound:
sys.exit("No permission to update ranges")
except Exception, e:
except Exception as e:
sys.exit("Updating next range failed: %s" % e)
else:
try:
@@ -1346,7 +1346,7 @@ def set_DNA_range(hostname, range, realm, dirman_passwd, next_range=False,
sys.exit("No changes to make")
except errors.NotFound:
sys.exit("No permission to update ranges")
except Exception, e:
except Exception as e:
sys.exit("Updating range failed: %s" % e)
def has_managed_topology():
@@ -1477,13 +1477,13 @@ try:
main()
except KeyboardInterrupt:
sys.exit(1)
except SystemExit, e:
except SystemExit as e:
sys.exit(e)
except RuntimeError, e:
except RuntimeError as e:
sys.exit(e)
except socket.timeout:
print "Connection timed out."
sys.exit(1)
except Exception, e:
except Exception as e:
print "unexpected error: %s" % str(e)
sys.exit(1)
+14 -14
View File
@@ -163,7 +163,7 @@ def get_config(dirsrv):
attrs = ['cn']
try:
entries = con.get_entries(dn, con.SCOPE_ONELEVEL, attrs_list=attrs)
except Exception, e:
except Exception as e:
masters_list.append("No master found because of error: %s" % str(e))
else:
for master_entry in entries:
@@ -174,7 +174,7 @@ def get_config(dirsrv):
raise IpactlError("Failed to get list of services to probe status!\n"
"Configured hostname '%s' does not match any master server in LDAP:\n%s"
% (api.env.host, masters))
except Exception, e:
except Exception as e:
raise IpactlError("Unknown error when retrieving list of services from LDAP: " + str(e))
svc_list = []
@@ -203,7 +203,7 @@ def get_config_from_file():
try:
f = open(tasks.get_svc_list_file(), 'r')
svc_list = json.load(f)
except Exception, e:
except Exception as e:
raise IpactlError("Unknown error when retrieving list of services from file: " + str(e))
# the framework can start/stop a number of related services we are not
@@ -260,13 +260,13 @@ def ipa_start(options):
try:
print "Starting Directory Service"
dirsrv.start(capture_output=get_capture_output('dirsrv', options.debug))
except Exception, e:
except Exception as e:
raise IpactlError("Failed to start Directory Service: " + str(e))
ldap_list = []
try:
svc_list = get_config(dirsrv)
except Exception, e:
except Exception as e:
emit_err("Failed to read data from service file: " + str(e))
emit_err("Shutting down")
@@ -306,13 +306,13 @@ def ipa_stop(options):
dirsrv = services.knownservices.dirsrv
try:
svc_list = get_config_from_file()
except Exception, e:
except Exception as e:
# Issue reading the file ? Let's try to get data from LDAP as a
# fallback
try:
dirsrv.start(capture_output=False)
svc_list = get_config(dirsrv)
except Exception, e:
except Exception as e:
emit_err("Failed to read data from Directory Service: " + str(e))
emit_err("Shutting down")
try:
@@ -356,12 +356,12 @@ def ipa_restart(options):
print "Starting Directory Service"
dirsrv.start(capture_output=get_capture_output('dirsrv', options.debug))
dirsrv_restart = False
except Exception, e:
except Exception as e:
raise IpactlError("Failed to start Directory Service: " + str(e))
try:
new_svc_list = get_config(dirsrv)
except Exception, e:
except Exception as e:
emit_err("Failed to read data from Directory Service: " + str(e))
emit_err("Shutting down")
try:
@@ -377,7 +377,7 @@ def ipa_restart(options):
old_svc_list = []
try:
old_svc_list = get_config_from_file()
except Exception, e:
except Exception as e:
emit_err("Failed to get service list from file: " + str(e))
# fallback to what's in LDAP
old_svc_list = new_svc_list
@@ -410,7 +410,7 @@ def ipa_restart(options):
if dirsrv_restart:
print "Restarting Directory Service"
dirsrv.restart(capture_output=get_capture_output('dirsrv', options.debug))
except Exception, e:
except Exception as e:
emit_err("Failed to restart Directory Service: " + str(e))
emit_err("Shutting down")
@@ -471,12 +471,12 @@ def ipa_status(options):
svc_list = get_config(dirsrv)
else:
svc_list = get_config_from_file()
except IpactlError, e:
except IpactlError as e:
if os.path.exists(tasks.get_svc_list_file()):
raise e
else:
svc_list = []
except Exception, e:
except Exception as e:
raise IpactlError("Failed to get list of services to probe status: " + str(e))
dirsrv = services.knownservices.dirsrv
@@ -520,7 +520,7 @@ def main():
# check if IPA is configured at all
try:
check_IPA_configuration()
except IpactlError, e:
except IpactlError as e:
if args[0].lower() == "status":
# Different LSB return code for status command:
# 4 - program or service status is unknown
+1 -1
View File
@@ -43,7 +43,7 @@ def application(environ, start_response):
try:
index = get_plugin_index()
status = '200 OK'
except Exception, e:
except Exception as e:
root_logger.error('plugin index generation failed: %s' % e)
status = '200 OK'
index = get_failed()