Back to index

moin  1.9.0~rc2
Classes | Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin._tests.ldap_testbase.LdapEnvironment Class Reference
Collaboration diagram for MoinMoin._tests.ldap_testbase.LdapEnvironment:
Collaboration graph
[legend]

List of all members.

Classes

class  LDAPTstBase

Public Member Functions

def __init__
def create_env
def start_slapd
def load_directory
def stop_slapd
def destroy_env

Public Attributes

 basedn
 rootdn
 rootpw
 instance
 schema_dir
 coding
 ldap_dir
 slapd_conf
 timeout
 ldap_db_dir
 slapd

Static Public Attributes

string DB_CONFIG

Detailed Description

Manage a (temporary) environment for running a slapd in it 

Definition at line 131 of file ldap_testbase.py.


Constructor & Destructor Documentation

def MoinMoin._tests.ldap_testbase.LdapEnvironment.__init__ (   self,
  basedn,
  rootdn,
  rootpw,
  instance = 0,
  schema_dir = '/etc/ldap/schema',
  coding = 'utf-8',
  timeout = 10 
)

Definition at line 155 of file ldap_testbase.py.

00155 
00156                 ):
00157         self.basedn = basedn
00158         self.rootdn = rootdn
00159         self.rootpw = rootpw
00160         self.instance = instance
00161         self.schema_dir = schema_dir
00162         self.coding = coding
00163         self.ldap_dir = None
00164         self.slapd_conf = None
00165         self.timeout = timeout


Member Function Documentation

def MoinMoin._tests.ldap_testbase.LdapEnvironment.create_env (   self,
  slapd_config,
  db_config = DB_CONFIG 
)
create a temporary LDAP server environment in a temp. directory,
    including writing a slapd.conf (see configure_slapd) and a
    DB_CONFIG there.

Definition at line 166 of file ldap_testbase.py.

00166 
00167     def create_env(self, slapd_config, db_config=DB_CONFIG):
00168         """ create a temporary LDAP server environment in a temp. directory,
00169             including writing a slapd.conf (see configure_slapd) and a
00170             DB_CONFIG there.
00171         """
00172         # create directories
00173         self.ldap_dir = tempfile.mkdtemp(prefix='LdapEnvironment-%d.' % self.instance)
00174         self.ldap_db_dir = os.path.join(self.ldap_dir, 'db')
00175         os.mkdir(self.ldap_db_dir)
00176 
00177         # create DB_CONFIG for bdb backend
00178         db_config_fname = os.path.join(self.ldap_db_dir, 'DB_CONFIG')
00179         f = open(db_config_fname, 'w')
00180         f.write(db_config)
00181         f.close()
00182 
00183         rootpw = '{MD5}' + base64.b64encode(md5.new(self.rootpw).digest())
00184 
00185         # create slapd.conf from content template in slapd_config
00186         slapd_config = slapd_config % {
00187             'ldap_dir': self.ldap_dir,
00188             'ldap_db_dir': self.ldap_db_dir,
00189             'schema_dir': self.schema_dir,
00190             'basedn': self.basedn,
00191             'rootdn': self.rootdn,
00192             'rootpw': rootpw,
00193         }
00194         if isinstance(slapd_config, unicode):
00195             slapd_config = slapd_config.encode(self.coding)
00196         self.slapd_conf = os.path.join(self.ldap_dir, "slapd.conf")
00197         f = open(self.slapd_conf, 'w')
00198         f.write(slapd_config)
00199         f.close()

remove the temporary LDAP server environment 

Definition at line 223 of file ldap_testbase.py.

00223 
00224     def destroy_env(self):
00225         """ remove the temporary LDAP server environment """
00226         shutil.rmtree(self.ldap_dir)
00227 
try:
load the directory with the ldif_content (str) 

Definition at line 206 of file ldap_testbase.py.

00206 
00207     def load_directory(self, ldif_content):
00208         """ load the directory with the ldif_content (str) """
00209         lo = ldap.initialize(self.slapd.url)
00210         ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3) # ldap v2 is outdated
00211         lo.simple_bind_s(self.rootdn, self.rootpw)
00212 
00213         class LDIFLoader(ldif.LDIFParser):
00214             def handle(self, dn, entry):
00215                 lo.add_s(dn, ldap.modlist.addModlist(entry))
00216 
00217         loader = LDIFLoader(StringIO(ldif_content))
00218         loader.parse()

Here is the call graph for this function:

start a slapd and optionally wait until it talks with us 

Definition at line 200 of file ldap_testbase.py.

00200 
00201     def start_slapd(self):
00202         """ start a slapd and optionally wait until it talks with us """
00203         self.slapd = Slapd(config=self.slapd_conf, port=3890+self.instance)
00204         started = self.slapd.start(timeout=self.timeout)
00205         return started

stop a slapd 

Definition at line 219 of file ldap_testbase.py.

00219 
00220     def stop_slapd(self):
00221         """ stop a slapd """
00222         self.slapd.stop()


Member Data Documentation

Definition at line 156 of file ldap_testbase.py.

Definition at line 161 of file ldap_testbase.py.

Initial value:
"""\
# STRANGE: if i use those settings, after the test slapd goes to 100% and doesn't terminate on SIGTERM
# Set the database in memory cache size.
#set_cachesize 0 10000000 1

# Set log values.
#set_lg_regionmax 262144
#set_lg_bsize 262144
#set_lg_max 10485760

#set_tas_spins 0
"""

Definition at line 135 of file ldap_testbase.py.

Definition at line 159 of file ldap_testbase.py.

Definition at line 173 of file ldap_testbase.py.

Definition at line 162 of file ldap_testbase.py.

Definition at line 157 of file ldap_testbase.py.

Definition at line 158 of file ldap_testbase.py.

Definition at line 160 of file ldap_testbase.py.

Definition at line 202 of file ldap_testbase.py.

Definition at line 163 of file ldap_testbase.py.

Definition at line 164 of file ldap_testbase.py.


The documentation for this class was generated from the following file: