From 6f8e167fcaf81d3e4c221cd1d4c1bc84ceb61a9d Mon Sep 17 00:00:00 2001 From: Andrew Bogott Date: Fri, 13 Jan 2012 01:40:10 +0000 Subject: [PATCH] Modify the fake ldap driver to fix compatibility. The fake implementation was raising an exception during a failed search_s where the normal python ldap module does not. So, removed that raise. Also added a modrdn_s implementation because I need it for a network test. (Indirectly) for blueprint public-and-private-dns. Change-Id: Ia86a776afe19ffce72b285bb4c96ce3ed0ae7c4a --- nova/auth/fakeldap.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nova/auth/fakeldap.py b/nova/auth/fakeldap.py index f576da8e7ddd..d092e7e42a5b 100644 --- a/nova/auth/fakeldap.py +++ b/nova/auth/fakeldap.py @@ -266,6 +266,20 @@ class FakeLDAP(object): values.remove(v) values = store.hset(key, k, _to_json(values)) + def modrdn_s(self, dn, newrdn): + oldobj = self.search_s(dn, SCOPE_BASE) + if not oldobj: + raise NO_SUCH_OBJECT() + newdn = "%s,%s" % (newrdn, dn.partition(',')[2]) + newattrs = oldobj[0][1] + + modlist = [] + for attrtype in newattrs.keys(): + modlist.append((attrtype, newattrs[attrtype])) + + self.add_s(newdn, modlist) + self.delete_s(dn) + def search_s(self, dn, scope, query=None, fields=None): """Search for all matching objects under dn using the query. @@ -283,10 +297,14 @@ class FakeLDAP(object): raise NotImplementedError(str(scope)) store = Store.instance() if scope == SCOPE_BASE: - keys = ["%s%s" % (self.__prefix, dn)] + pattern = "%s%s" % (self.__prefix, dn) + keys = store.keys(pattern) else: keys = store.keys("%s*%s" % (self.__prefix, dn)) + if not keys: + raise NO_SUCH_OBJECT() + objects = [] for key in keys: # get the attributes from the store @@ -301,9 +319,6 @@ class FakeLDAP(object): attrs = dict([(k, v) for k, v in attrs.iteritems() if not fields or k in fields]) objects.append((key[len(self.__prefix):], attrs)) - # pylint: enable=E1103 - if objects == []: - raise NO_SUCH_OBJECT() return objects @property