[ldap test] move the slapd database directory to a tempdir (closes #2583993) stable
authorDavid Douard <david.douard@logilab.fr>
Thu, 24 Jan 2013 16:13:40 +0100
branchstable
changeset 8681 48731a0d3df8
parent 8680 2bb3021f4ffe
child 8683 d537786e52b8
child 8685 8bfc0753f1da
[ldap test] move the slapd database directory to a tempdir (closes #2583993) This is required to be sure we are not hurt by NFS or such...
server/test/data/slapd.conf.in
server/test/unittest_ldapuser.py
--- a/server/test/data/slapd.conf.in	Thu Jan 24 16:10:31 2013 +0100
+++ b/server/test/data/slapd.conf.in	Thu Jan 24 16:13:40 2013 +0100
@@ -49,5 +49,5 @@
 rootdn          "cn=admin,dc=cubicweb,dc=test"
 rootpw          "cw"
 # Where the database file are physically stored for database #1
-directory       "%(apphome)s/ldapdb"
+directory       "%(testdir)s"
 
--- a/server/test/unittest_ldapuser.py	Thu Jan 24 16:10:31 2013 +0100
+++ b/server/test/unittest_ldapuser.py	Thu Jan 24 16:13:40 2013 +0100
@@ -23,6 +23,7 @@
 import time
 from os.path import join, exists
 import subprocess
+import tempfile
 
 from logilab.common.testlib import TestCase, unittest_main, mock_object, Tags
 
@@ -39,16 +40,13 @@
 
 def create_slapd_configuration(cls):
     global URL
+    slapddir = tempfile.mkdtemp('cw-unittest-ldap')
     config = cls.config
-    basedir = join(config.apphome, "ldapdb")
     slapdconf = join(config.apphome, "slapd.conf")
     confin = file(join(config.apphome, "slapd.conf.in")).read()
     confstream = file(slapdconf, 'w')
-    confstream.write(confin % {'apphome': config.apphome})
+    confstream.write(confin % {'apphome': config.apphome, 'testdir': slapddir})
     confstream.close()
-    if exists(basedir):
-        shutil.rmtree(basedir)
-    os.makedirs(basedir)
     # fill ldap server with some data
     ldiffile = join(config.apphome, "ldap_test.ldif")
     config.info('Initing ldap database')
@@ -69,6 +67,7 @@
         raise EnvironmentError('Cannot start slapd with cmdline="%s" (from directory "%s")' %
                                (" ".join(cmdline), os.getcwd()))
     URL = u'ldap://%s' % host
+    return slapddir
 
 def terminate_slapd(cls):
     config = cls.config
@@ -89,11 +88,15 @@
     def setUpClass(cls):
         from cubicweb.cwctl import init_cmdline_log_threshold
         init_cmdline_log_threshold(cls.config, cls.loglevel)
-        create_slapd_configuration(cls)
+        cls._tmpdir = create_slapd_configuration(cls)
 
     @classmethod
     def tearDownClass(cls):
         terminate_slapd(cls)
+        try:
+            shutil.rmtree(cls._tmpdir)
+        except:
+            pass
 
 class CheckWrongGroup(LDAPTestBase):