1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
# Copyright [2010] [Anso Labs, LLC]
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
17
Fake LDAP server for test harnesses.
22
from nova import datastore
27
class NO_SUCH_OBJECT(Exception):
35
class FakeLDAP(object):
36
def __init__(self, _uri):
37
self.keeper = datastore.Keeper('fakeldap')
38
if self.keeper['objects'] is None:
39
self.keeper['objects'] = {}
41
def simple_bind_s(self, dn, password):
47
def search_s(self, dn, scope, query=None, fields=None):
48
logging.debug("searching for %s" % dn)
50
d = self.keeper['objects'] or {}
51
for cn, attrs in d.iteritems():
52
if cn[-len(dn):] == dn:
55
k,v = query[1:-1].split('=')
57
for cn, attrs in filtered.iteritems():
58
if attrs.has_key(k) and (v in attrs[k] or
62
raise NO_SUCH_OBJECT()
63
return objects.items()
65
def add_s(self, cn, attr):
66
logging.debug("adding %s" % cn)
73
d = self.keeper['objects']
75
self.keeper['objects'] = d
77
def delete_s(self, cn):
78
logging.debug("creating for %s" % cn)
79
d = self.keeper['objects'] or {}
81
self.keeper['objects'] = d