summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2010-03-03 15:14:22 +0100
committerRob Crittenden <rcritten@redhat.com>2010-03-09 16:52:47 -0500
commitb0f302bd99baa1a58e9cc202135b7bdc0c1da25d (patch)
treedb64d0ea77957e65f0680b00e6e2f7d0a1390612
parentb75d06e18938015ad6eafe53e15aa2d7a2f92f02 (diff)
downloadfreeipa-b0f302bd99baa1a58e9cc202135b7bdc0c1da25d.tar.gz
freeipa-b0f302bd99baa1a58e9cc202135b7bdc0c1da25d.tar.xz
freeipa-b0f302bd99baa1a58e9cc202135b7bdc0c1da25d.zip
Provide more detailed NotFound error messages from baseldap classes.
-rw-r--r--ipalib/plugins/baseldap.py62
1 files changed, 55 insertions, 7 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 31f4b4e7c..ca35000ed 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -71,6 +71,10 @@ class LDAPObject(Object):
uuid_attribute = ''
attribute_members = {}
+ container_not_found_msg = _('container entry (%(container)s) not found')
+ parent_not_found_msg = _('%(parent)s: %(oname)s not found')
+ object_not_found_msg = _('%(pkey)s: %(oname)s not found')
+
def get_dn(self, *keys, **kwargs):
if self.parent_object:
parent_dn = self.api.Object[self.parent_object].get_dn(*keys[:-1])
@@ -107,6 +111,13 @@ class LDAPObject(Object):
)
del entry_attrs[attr]
+ def handle_not_found(self, *keys):
+ raise errors.NotFound(
+ reason=self.object_not_found_msg % {
+ 'pkey': keys[-1], 'oname': self.object_name,
+ }
+ )
+
# Options used by create and update.
_attr_options = (
@@ -162,9 +173,27 @@ class LDAPCreate(crud.Create):
dn = self.pre_callback(ldap, dn, entry_attrs, attrs_list, *keys, **options)
- ldap.add_entry(dn, entry_attrs)
+ try:
+ ldap.add_entry(dn, entry_attrs)
+ except errors.NotFound:
+ parent = self.obj.parent_object
+ if parent:
+ raise errors.NotFound(
+ reason=self.obj.parent_not_found_msg % {
+ 'parent': keys[-2],
+ 'oname': self.api.Object[parent].object_name,
+ }
+ )
+ raise errors.NotFound(
+ reason=self.obj.container_not_found_msg % {
+ 'container': self.obj.container_dn,
+ }
+ )
- (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ try:
+ (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
dn = self.post_callback(ldap, dn, entry_attrs, *keys, **options)
@@ -211,7 +240,10 @@ class LDAPRetrieve(LDAPQuery):
dn = self.pre_callback(ldap, dn, attrs_list, *keys, **options)
- (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ try:
+ (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
dn = self.post_callback(ldap, dn, entry_attrs, *keys, **options)
@@ -259,7 +291,10 @@ class LDAPUpdate(LDAPQuery, crud.Update):
set.
"""
if 'addattr' in options:
- (dn, old_entry) = ldap.get_entry(dn, attrs_list)
+ try:
+ (dn, old_entry) = ldap.get_entry(dn, attrs_list)
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
attrlist = get_attributes(options['addattr'])
for attr in attrlist:
if attr in old_entry:
@@ -271,10 +306,17 @@ class LDAPUpdate(LDAPQuery, crud.Update):
try:
ldap.update_entry(dn, entry_attrs)
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
except errors.EmptyModlist:
pass
- (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ try:
+ (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ except errors.NotFound:
+ raise errors.MidairCollision(
+ format=_('the entry was deleted while being modified')
+ )
dn = self.post_callback(ldap, dn, entry_attrs, *keys, **options)
@@ -422,7 +464,10 @@ class LDAPAddMember(LDAPModMember):
set(self.obj.default_attributes + member_dns.keys())
)
- (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ try:
+ (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
(completed, dn) = self.post_callback(
ldap, completed, failed, dn, entry_attrs, *keys, **options
@@ -494,7 +539,10 @@ class LDAPRemoveMember(LDAPModMember):
set(self.obj.default_attributes + member_dns.keys())
)
- (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ try:
+ (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
(completed, dn) = self.post_callback(
ldap, completed, failed, dn, entry_attrs, *keys, **options