[ldap] quieter tests
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 23 Apr 2013 16:25:56 +0200
changeset 8902 9edfa3660bf4
parent 8901 661b6aaac240
child 8903 192a748550c7
[ldap] quieter tests Capture slapadd and slapd output if everything goes well.
server/test/unittest_ldapsource.py
--- a/server/test/unittest_ldapsource.py	Wed Apr 10 17:50:11 2013 +0200
+++ b/server/test/unittest_ldapsource.py	Tue Apr 23 16:25:56 2013 +0200
@@ -18,6 +18,7 @@
 """cubicweb.server.sources.ldapusers unit and functional tests"""
 
 import os
+import sys
 import shutil
 import time
 from os.path import join, exists
@@ -50,8 +51,15 @@
     # fill ldap server with some data
     ldiffile = join(config.apphome, "ldap_test.ldif")
     config.info('Initing ldap database')
-    cmdline = "/usr/sbin/slapadd -f %s -l %s -c" % (slapdconf, ldiffile)
-    subprocess.call(cmdline, shell=True)
+    cmdline = ['/usr/sbin/slapadd', '-f', slapdconf, '-l', ldiffile, '-c']
+    PIPE = subprocess.PIPE
+    slapproc = subprocess.Popen(cmdline, stdout=PIPE, stderr=PIPE)
+    stdout, stderr = slapproc.communicate()
+    if slapproc.returncode:
+        print >> sys.stderr, ('slapadd returned with status: %s'
+                              % slapproc.returncode)
+        sys.stdout.write(stdout)
+        sys.stderr.write(stderr)
 
     #ldapuri = 'ldapi://' + join(basedir, "ldapi").replace('/', '%2f')
     port = get_available_port(xrange(9000, 9100))
@@ -59,7 +67,8 @@
     ldapuri = 'ldap://%s' % host
     cmdline = ["/usr/sbin/slapd", "-f",  slapdconf,  "-h",  ldapuri, "-d", "0"]
     config.info('Starting slapd:', ' '.join(cmdline))
-    cls.slapd_process = subprocess.Popen(cmdline)
+    PIPE = subprocess.PIPE
+    cls.slapd_process = subprocess.Popen(cmdline, stdout=PIPE, stderr=PIPE)
     time.sleep(0.2)
     if cls.slapd_process.poll() is None:
         config.info('slapd started with pid %s', cls.slapd_process.pid)
@@ -78,7 +87,12 @@
         else:
             import os, signal
             os.kill(cls.slapd_process.pid, signal.SIGTERM)
-        cls.slapd_process.wait()
+        stdout, stderr = cls.slapd_process.communicate()
+        if cls.slapd_process.returncode:
+            print >> sys.stderr, ('slapd returned with status: %s'
+                                  % cls.slapd_process.returncode)
+            sys.stdout.write(stdout)
+            sys.stderr.write(stderr)
         config.info('DONE')
 
 class LDAPTestBase(CubicWebTC):