Add a reason to the NotFound exception so we can provide more robust errors

This commit is contained in:
Rob Crittenden
2009-05-08 11:15:45 -04:00
parent de88954b91
commit 1c31b5bc08
8 changed files with 22 additions and 22 deletions

View File

@@ -298,7 +298,7 @@ class IPAdmin(SimpleLDAPObject):
raise e
except ldap.NO_SUCH_OBJECT, e:
args = kw.get('args', '')
raise errors.NotFound(msg=notfound(args))
raise errors.NotFound(reason=notfound(args))
except ldap.ALREADY_EXISTS, e:
raise errors.DuplicateEntry()
except ldap.CONSTRAINT_VIOLATION, e:
@@ -361,7 +361,7 @@ class IPAdmin(SimpleLDAPObject):
self.__handle_errors(e, **kw)
if not obj:
raise errors.NotFound(msg=notfound(args))
raise errors.NotFound(reason=notfound(args))
elif isinstance(obj,Entry):
return obj
@@ -383,7 +383,7 @@ class IPAdmin(SimpleLDAPObject):
self.__handle_errors(e, **kw)
if not obj:
raise errors.NotFound(msg=notfound(args))
raise errors.NotFound(reason=notfound(args))
entries = []
for s in obj:
@@ -421,7 +421,7 @@ class IPAdmin(SimpleLDAPObject):
self.__handle_errors(e, **kw)
if not entries:
raise errors.NotFound(msg=notfound(args))
raise errors.NotFound(reason=notfound(args))
if partial == 1:
counter = -1

View File

@@ -270,7 +270,7 @@ def search(base, filter, attributes, timelimit=1, sizelimit=3000, scope=ldap.SCO
results = context.ldap.conn.getListAsync(base, scope,
filter, attributes, 0, None, None, timelimit, sizelimit)
except ldap.NO_SUCH_OBJECT:
raise errors.NotFound()
raise errors.NotFound(reason=filter)
counter = results[0]
entries = [counter]
@@ -315,9 +315,9 @@ def get_ipa_config():
searchfilter = "cn=ipaconfig"
try:
config = get_sub_entry("cn=etc," + api.env.basedn, searchfilter)
except ldap.NO_SUCH_OBJECT, e:
except ldap.NO_SUCH_OBJECT:
# FIXME
raise errors.NotFound()
raise errors.NotFound(reason="IPA configuration cannot be loaded")
return config
@@ -409,12 +409,12 @@ def add_member_to_group(member_dn, group_dn, memberattr='member'):
group = get_entry_by_dn(group_dn, None)
if group is None:
raise errors.NotFound()
raise errors.NotFound(reason="cannot find group %s" % group_dn)
# check to make sure member_dn exists
member_entry = get_base_entry(member_dn, "(objectClass=*)", ['dn','objectclass'])
if not member_entry:
raise errors.NotFound()
raise errors.NotFound(reason="cannot find member %s" % member_dn)
# Add the new member to the group member attribute
members = group.get(memberattr, [])
@@ -430,7 +430,7 @@ def remove_member_from_group(member_dn, group_dn, memberattr='member'):
group = get_entry_by_dn(group_dn, None)
if group is None:
raise errors.NotFound()
raise errors.NotFound(reason="cannot find group %s" % group_dn)
"""
if group.get('cn') == "admins":
member = get_entry_by_dn(member_dn, ['dn','uid'])