3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $SYNCPROV = syncprovno; then
20 echo "Syncrepl provider overlay not available, test skipped"
33 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
36 # Test replication of dynamic config:
39 # - configure over ldap
40 # - populate over ldap
41 # - configure syncrepl over ldap
42 # - retrieve database over ldap and compare against expected results
45 echo "Initializing server configurations..."
46 $SLAPADD -F $CFCON -n 0 <<EOF
48 objectClass: olcGlobal
52 dn: olcDatabase={0}config,cn=config
53 objectClass: olcDatabaseConfig
54 olcDatabase: {0}config
55 olcRootPW:< file:configpw
58 $SLAPADD -F $CFPRO -n 0 <<EOF
60 objectClass: olcGlobal
64 dn: olcDatabase={0}config,cn=config
65 objectClass: olcDatabaseConfig
66 olcDatabase: {0}config
67 olcRootPW:< file:configpw
70 echo "Starting producer slapd on TCP/IP port $PORT1..."
72 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > ../$LOG1 2>&1 &
74 if test $WAIT != 0 ; then
83 echo "Using ldapsearch to check that producer slapd is running..."
84 for i in 0 1 2 3 4 5; do
85 $LDAPSEARCH -s base -b "" -H $URI1 \
86 'objectclass=*' > /dev/null 2>&1
88 if test $RC = 0 ; then
91 echo "Waiting 5 seconds for slapd to start..."
95 if test $RC != 0 ; then
96 echo "ldapsearch failed ($RC)!"
97 test $KILLSERVERS != no && kill -HUP $KILLPIDS
101 echo "Inserting syncprov overlay on producer..."
102 if [ "$SYNCPROV" = syncprovmod ]; then
103 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
104 dn: cn=module,cn=config
105 objectClass: olcModuleList
107 olcModulePath: ../../../servers/slapd/overlays
108 olcModuleLoad: syncprov.la
111 if test $RC != 0 ; then
112 echo "ldapadd failed for moduleLoad ($RC)!"
113 test $KILLSERVERS != no && kill -HUP $KILLPIDS
118 # Note that we configure a timeout here; it's possible for both
119 # servers to attempt to bind to each other while a modify to
120 # cn=config is in progress. When the modify pauses the thread pool
121 # neither server will progress. The timeout will drop the syncrepl
122 # attempt and allow the modifies to complete.
124 CONFIGPW=`cat $CONFIGPWF`
125 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
132 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
134 objectClass: olcOverlayConfig
135 objectClass: olcSyncProvConfig
138 dn: olcDatabase={0}config,cn=config
141 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
142 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
143 retry="5 5 300 5" timeout=1
144 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
145 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
146 retry="5 5 300 5" timeout=1
152 if test $RC != 0 ; then
153 echo "ldapmodify failed for syncrepl config ($RC)!"
154 test $KILLSERVERS != no && kill -HUP $KILLPIDS
158 echo "Starting consumer slapd on TCP/IP port $PORT2..."
160 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > ../$LOG2 2>&1 &
162 if test $WAIT != 0 ; then
163 echo SLAVEPID $SLAVEPID
166 KILLPIDS="$KILLPIDS $SLAVEPID"
171 echo "Using ldapsearch to check that consumer slapd is running..."
172 for i in 0 1 2 3 4 5; do
173 $LDAPSEARCH -s base -b "" -H $URI2 \
174 'objectclass=*' > /dev/null 2>&1
176 if test $RC = 0 ; then
179 echo "Waiting 5 seconds for slapd to start..."
183 if test $RC != 0 ; then
184 echo "ldapsearch failed ($RC)!"
185 test $KILLSERVERS != no && kill -HUP $KILLPIDS
189 echo "Configuring syncrepl on consumer..."
190 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
191 dn: olcDatabase={0}config,cn=config
194 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
195 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
196 retry="5 5 300 5" timeout=1
197 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
198 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
199 retry="5 5 300 5" timeout=1
205 echo "Adding schema and databases on producer..."
206 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
207 include: file:$SCHEMADIR/core.ldif
209 include: file:$SCHEMADIR/cosine.ldif
211 include: file:$SCHEMADIR/inetorgperson.ldif
213 include: file:$SCHEMADIR/openldap.ldif
215 include: file:$SCHEMADIR/nis.ldif
218 if test $RC != 0 ; then
219 echo "ldapadd failed for schema config ($RC)!"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
224 if [ "$BACKENDTYPE" = mod ]; then
225 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
226 dn: cn=module,cn=config
227 objectClass: olcModuleList
229 olcModulePath: ../../../servers/slapd/back-$BACKEND
230 olcModuleLoad: back_$BACKEND.la
233 if test $RC != 0 ; then
234 echo "ldapadd failed for backend config ($RC)!"
235 test $KILLSERVERS != no && kill -HUP $KILLPIDS
240 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
241 dn: olcDatabase={1}$BACKEND,cn=config
242 objectClass: olcDatabaseConfig
243 objectClass: olc${BACKEND}Config
244 olcDatabase: {1}$BACKEND
247 olcRootDN: $MANAGERDN
249 olcSyncRepl: rid=003 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
250 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
251 interval=00:00:00:10 retry="5 5 300 5" timeout=1
252 olcSyncRepl: rid=004 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
253 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
254 interval=00:00:00:10 retry="5 5 300 5" timeout=1
257 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
259 objectClass: olcOverlayConfig
260 objectClass: olcSyncProvConfig
264 if test $RC != 0 ; then
265 echo "ldapadd failed for database config ($RC)!"
266 test $KILLSERVERS != no && kill -HUP $KILLPIDS
270 echo "Using ldapadd to populate producer..."
271 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
274 if test $RC != 0 ; then
275 echo "ldapadd failed for database config ($RC)!"
276 test $KILLSERVERS != no && kill -HUP $KILLPIDS
281 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
284 echo "Using ldapsearch to check that syncrepl received database changes..."
286 for i in 0 1 2 3 4 5; do
287 RESULT=`$LDAPSEARCH -H $URI2 \
288 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
289 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
290 if test "x$RESULT" = "xOK" ; then
294 echo "Waiting 5 seconds for syncrepl to receive changes..."
298 if test $RC != 0 ; then
299 echo "ldapsearch failed ($RC)!"
300 test $KILLSERVERS != no && kill -HUP $KILLPIDS
304 echo "Using ldapsearch to read config from the producer..."
305 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
306 'objectclass=*' > $MASTEROUT 2>&1
309 if test $RC != 0 ; then
310 echo "ldapsearch failed at producer ($RC)!"
311 test $KILLSERVERS != no && kill -HUP $KILLPIDS
315 echo "Using ldapsearch to read config from the consumer..."
316 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
317 'objectclass=*' > $SLAVEOUT 2>&1
320 if test $RC != 0 ; then
321 echo "ldapsearch failed at consumer ($RC)!"
322 test $KILLSERVERS != no && kill -HUP $KILLPIDS
326 echo "Filtering producer results..."
327 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
328 echo "Filtering consumer results..."
329 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
331 echo "Comparing retrieved configs from producer and consumer..."
332 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
334 if test $? != 0 ; then
335 echo "test failed - producer and consumer configs differ"
336 test $KILLSERVERS != no && kill -HUP $KILLPIDS
340 echo "Using ldapsearch to read all the entries from the producer..."
341 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
342 'objectclass=*' > $MASTEROUT 2>&1
345 if test $RC != 0 ; then
346 echo "ldapsearch failed at producer ($RC)!"
347 test $KILLSERVERS != no && kill -HUP $KILLPIDS
351 echo "Using ldapsearch to read all the entries from the consumer..."
352 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
353 'objectclass=*' > $SLAVEOUT 2>&1
356 if test $RC != 0 ; then
357 echo "ldapsearch failed at consumer ($RC)!"
358 test $KILLSERVERS != no && kill -HUP $KILLPIDS
362 test $KILLSERVERS != no && kill -HUP $KILLPIDS
364 echo "Filtering producer results..."
365 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
366 echo "Filtering consumer results..."
367 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
369 echo "Comparing retrieved entries from producer and consumer..."
370 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
372 if test $? != 0 ; then
373 echo "test failed - producer and consumer databases differ"
377 test $KILLSERVERS != no && wait
379 echo "Restarting servers..."
380 echo "Starting producer slapd on TCP/IP port $PORT1..."
382 echo "======================= RESTART =======================" >> ../$LOG1
383 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> ../$LOG1 2>&1 &
385 if test $WAIT != 0 ; then
391 echo "Using ldapsearch to check that producer slapd is running..."
392 for i in 0 1 2 3 4 5; do
393 $LDAPSEARCH -s base -b "" -H $URI1 \
394 'objectclass=*' > /dev/null 2>&1
396 if test $RC = 0 ; then
399 echo "Waiting 5 seconds for slapd to start..."
403 if test $RC != 0 ; then
404 echo "ldapsearch failed ($RC)!"
405 test $KILLSERVERS != no && kill -HUP $KILLPIDS
409 echo "Starting consumer slapd on TCP/IP port $PORT2..."
411 echo "======================= RESTART =======================" >> ../$LOG2
412 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> ../$LOG2 2>&1 &
414 if test $WAIT != 0 ; then
415 echo SLAVEPID $SLAVEPID
418 KILLPIDS="$KILLPIDS $SLAVEPID"
423 echo "Using ldapsearch to check that consumer slapd is running..."
424 for i in 0 1 2 3 4 5; do
425 $LDAPSEARCH -s base -b "" -H $URI2 \
426 'objectclass=*' > /dev/null 2>&1
428 if test $RC = 0 ; then
431 echo "Waiting 5 seconds for slapd to start..."
435 if test $RC != 0 ; then
436 echo "ldapsearch failed ($RC)!"
437 test $KILLSERVERS != no && kill -HUP $KILLPIDS
441 # Insert modifications and more tests here.
443 echo "Waiting $SLEEP seconds for servers to resync..."
446 test $KILLSERVERS != no && kill -HUP $KILLPIDS
448 echo ">>>>> Test succeeded"
450 test $KILLSERVERS != no && wait