3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2009 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"
26 if [ $MMR -gt 9 ]; then
35 $SLAPPASSWD -g -n >$CONFIGPWF
37 if test x"$SYNCMODE" = x ; then
42 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
45 SYNCTYPE="type=refreshAndPersist"
48 echo "unknown sync mode $SYNCMODE"
54 # Test replication of dynamic config:
56 # - configure over ldap
57 # - populate over ldap
58 # - configure syncrepl over ldap
59 # - retrieve database over ldap and compare against expected results
62 echo "Initializing server configurations..."
64 while [ $n -le $MMR ]; do
67 CFDIR=${XDIR}$n/slapd.d
69 mkdir -p ${XDIR}$n $DBDIR $CFDIR
71 $SLAPADD -F $CFDIR -n 0 <<EOF
73 objectClass: olcGlobal
77 dn: olcDatabase={0}config,cn=config
78 objectClass: olcDatabaseConfig
79 olcDatabase: {0}config
80 olcRootPW:< file://$CONFIGPWF
86 echo "Starting server 1 on TCP/IP port $PORT1..."
88 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
90 if test $WAIT != 0 ; then
99 echo "Using ldapsearch to check that server 1 is running..."
100 for i in 0 1 2 3 4 5; do
101 $LDAPSEARCH -s base -b "" -H $URI1 \
102 'objectclass=*' > /dev/null 2>&1
104 if test $RC = 0 ; then
107 echo "Waiting 5 seconds for slapd to start..."
111 if test $RC != 0 ; then
112 echo "ldapsearch failed ($RC)!"
113 test $KILLSERVERS != no && kill -HUP $KILLPIDS
117 echo "Inserting syncprov overlay on server 1..."
119 if [ "$SYNCPROV" = syncprovmod ]; then
121 dn: cn=module,cn=config
123 objectClass: olcModuleList
125 olcModulePath: ../../../servers/slapd/overlays
126 olcModuleLoad: syncprov.la
131 # Note that we configure a timeout here; it's possible for both
132 # servers to attempt to bind to each other while a modify to
133 # cn=config is in progress. When the modify pauses the thread pool
134 # neither server will progress. The timeout will drop the syncrepl
135 # attempt and allow the modifies to complete.
137 read CONFIGPW < $CONFIGPWF
138 echo "dn: cn=config" >> $TMP
139 echo "changetype: modify" >> $TMP
140 echo "replace: olcServerID" >> $TMP
142 while [ $n -le $MMR ]; do
143 PORT=`expr $BASEPORT + $n`
144 URI="ldap://${LOCALHOST}:$PORT/"
145 echo "olcServerID: $n $URI" >> $TMP
151 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
153 objectClass: olcOverlayConfig
154 objectClass: olcSyncProvConfig
157 dn: olcDatabase={0}config,cn=config
163 while [ $n -le $MMR ]; do
164 PORT=`expr $BASEPORT + $n`
165 URI="ldap://${LOCALHOST}:$PORT/"
166 echo "olcSyncRepl: rid=00$n provider=$URI binddn=\"cn=config\" bindmethod=simple" >> $TMP
167 echo " credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
168 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
172 echo "add: olcMirrorMode" >> $TMP
173 echo "olcMirrorMode: TRUE" >> $TMP
174 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >> $TESTOUT 2>&1
176 if test $RC != 0 ; then
177 echo "ldapmodify failed for syncrepl config ($RC)!"
178 test $KILLSERVERS != no && kill -HUP $KILLPIDS
183 while [ $n -le $MMR ]; do
184 PORT=`expr $BASEPORT + $n`
185 URI="ldap://${LOCALHOST}:$PORT/"
186 LOG=$TESTDIR/slapd.$n.log
187 echo "Starting server $n on TCP/IP port $PORT..."
189 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING > $LOG 2>&1 &
191 if test $WAIT != 0 ; then
192 echo SLAVEPID $SLAVEPID
195 KILLPIDS="$KILLPIDS $SLAVEPID"
200 echo "Using ldapsearch to check that server $n is running..."
201 for i in 0 1 2 3 4 5; do
202 $LDAPSEARCH -s base -b "" -H $URI \
203 'objectclass=*' > /dev/null 2>&1
205 if test $RC = 0 ; then
208 echo "Waiting 5 seconds for slapd to start..."
212 if test $RC != 0 ; then
213 echo "ldapsearch failed ($RC)!"
214 test $KILLSERVERS != no && kill -HUP $KILLPIDS
218 echo "Configuring syncrepl on server $n..."
220 dn: olcDatabase={0}config,cn=config
225 while [ $j -le $MMR ]; do
226 P2=`expr $BASEPORT + $j`
227 U2="ldap://${LOCALHOST}:$P2/"
228 echo "olcSyncRepl: rid=00$j provider=$U2 binddn=\"cn=config\" bindmethod=simple" >> $TMP
229 echo " credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
230 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
238 $LDAPMODIFY -D cn=config -H $URI -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
242 echo "Adding schema and databases on server 1..."
243 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
244 include: file://$ABS_SCHEMADIR/core.ldif
246 include: file://$ABS_SCHEMADIR/cosine.ldif
248 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
250 include: file://$ABS_SCHEMADIR/openldap.ldif
252 include: file://$ABS_SCHEMADIR/nis.ldif
255 if test $RC != 0 ; then
256 echo "ldapadd failed for schema config ($RC)!"
257 test $KILLSERVERS != no && kill -HUP $KILLPIDS
262 if [ "$BACKENDTYPE" = mod ]; then
264 dn: cn=module,cn=config
265 objectClass: olcModuleList
267 olcModulePath: ../../../servers/slapd/back-$BACKEND
268 olcModuleLoad: back_$BACKEND.la
274 dn: olcDatabase={1}$BACKEND,cn=config
275 objectClass: olcDatabaseConfig
276 objectClass: olc${BACKEND}Config
277 olcDatabase: {1}$BACKEND
280 olcRootDN: $MANAGERDN
285 while [ $n -le $MMR ]; do
286 PORT=`expr $BASEPORT + $n`
287 URI="ldap://${LOCALHOST}:$PORT/"
289 echo "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP
290 echo " credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP
291 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
298 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
299 objectClass: olcOverlayConfig
300 objectClass: olcSyncProvConfig
303 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
305 if test $RC != 0 ; then
306 echo "ldapadd failed for database config ($RC)!"
307 test $KILLSERVERS != no && kill -HUP $KILLPIDS
313 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
314 dn: olcDatabase={1}$BACKEND,cn=config
317 olcDbIndex: objectClass,entryUUID,entryCSN eq
318 olcDbIndex: cn,uid pres,eq,sub
321 if test $RC != 0 ; then
322 echo "ldapadd modify for database config ($RC)!"
323 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329 echo "Using ldapadd to populate server 1..."
330 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
333 if test $RC != 0 ; then
334 echo "ldapadd failed for server 1 database ($RC)!"
335 test $KILLSERVERS != no && kill -HUP $KILLPIDS
339 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
343 while [ $n -le $MMR ]; do
344 PORT=`expr $BASEPORT + $n`
345 URI="ldap://${LOCALHOST}:$PORT/"
347 echo "Using ldapsearch to read config from server $n..."
348 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF \
349 'objectclass=*' > $TESTDIR/server$n.out 2>&1
352 if test $RC != 0 ; then
353 echo "ldapsearch failed at server $n ($RC)!"
354 test $KILLSERVERS != no && kill -HUP $KILLPIDS
358 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
364 while [ $n -le $MMR ]; do
365 echo "Comparing retrieved configs from server 1 and server $n..."
366 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
368 if test $? != 0 ; then
369 echo "test failed - server 1 and server $n configs differ"
370 test $KILLSERVERS != no && kill -HUP $KILLPIDS
377 while [ $n -le $MMR ]; do
378 PORT=`expr $BASEPORT + $n`
379 URI="ldap://${LOCALHOST}:$PORT/"
381 echo "Using ldapsearch to read all the entries from server $n..."
382 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
383 'objectclass=*' > $TESTDIR/server$n.out 2>&1
386 if test $RC != 0 ; then
387 echo "ldapsearch failed at server $n ($RC)!"
388 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
396 while [ $n -le $MMR ]; do
397 echo "Comparing retrieved entries from server 1 and server $n..."
398 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
400 if test $? != 0 ; then
401 echo "test failed - server 1 and server $n databases differ"
402 test $KILLSERVERS != no && kill -HUP $KILLPIDS
408 echo "Using ldapadd to populate server 2..."
409 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
412 if test $RC != 0 ; then
413 echo "ldapadd failed for server 2 database ($RC)!"
414 test $KILLSERVERS != no && kill -HUP $KILLPIDS
418 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
422 while [ $n -le $MMR ]; do
423 PORT=`expr $BASEPORT + $n`
424 URI="ldap://${LOCALHOST}:$PORT/"
426 echo "Using ldapsearch to read all the entries from server $n..."
427 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
428 'objectclass=*' > $TESTDIR/server$n.out 2>&1
431 if test $RC != 0 ; then
432 echo "ldapsearch failed at server $n ($RC)!"
433 test $KILLSERVERS != no && kill -HUP $KILLPIDS
436 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
441 while [ $n -le $MMR ]; do
442 echo "Comparing retrieved entries from server 1 and server $n..."
443 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
445 if test $? != 0 ; then
446 echo "test failed - server 1 and server $n databases differ"
447 test $KILLSERVERS != no && kill -HUP $KILLPIDS
453 echo "Using ldapadd to populate server 3..."
454 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
455 << EOMODS >> $TESTOUT 2>&1
456 dn: cn=Server 3 Test,dc=example,dc=com
462 if test $RC != 0 ; then
463 echo "ldapadd failed for server 3 database ($RC)!"
464 test $KILLSERVERS != no && kill -HUP $KILLPIDS
468 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
472 while [ $n -le $MMR ]; do
473 PORT=`expr $BASEPORT + $n`
474 URI="ldap://${LOCALHOST}:$PORT/"
476 echo "Using ldapsearch to read all the entries from server $n..."
477 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
478 'objectclass=*' > $TESTDIR/server$n.out 2>&1
481 if test $RC != 0 ; then
482 echo "ldapsearch failed at server $n ($RC)!"
483 test $KILLSERVERS != no && kill -HUP $KILLPIDS
486 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
491 while [ $n -le $MMR ]; do
492 echo "Comparing retrieved entries from server 1 and server $n..."
493 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
495 if test $? != 0 ; then
496 echo "test failed - server 1 and server $n databases differ"
497 test $KILLSERVERS != no && kill -HUP $KILLPIDS
503 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
504 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
505 >> $TESTOUT 2>&1 << EOADDS
506 dn: cn=To be deleted by server 1,dc=example,dc=com
509 # no distinguished values, will be added by DSA
511 dn: cn=To be deleted by server 2,dc=example,dc=com
514 # no distinguished values, will be added by DSA
516 dn: cn=To be deleted by server 3,dc=example,dc=com
519 # no distinguished values, will be added by DSA
521 dn: cn=To be deleted by server 1,dc=example,dc=com
525 if test $RC != 0 ; then
526 echo "ldapmodify failed for server 1 database ($RC)!"
527 test $KILLSERVERS != no && kill -HUP $KILLPIDS
531 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
535 while [ $n -le $MMR ]; do
536 PORT=`expr $BASEPORT + $n`
537 URI="ldap://${LOCALHOST}:$PORT/"
539 echo "Using ldapsearch to read all the entries from server $n..."
540 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
541 'objectclass=*' > $TESTDIR/server$n.out 2>&1
544 if test $RC != 0 ; then
545 echo "ldapsearch failed at server $n ($RC)!"
546 test $KILLSERVERS != no && kill -HUP $KILLPIDS
549 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
554 while [ $n -le $MMR ]; do
555 echo "Comparing retrieved entries from server 1 and server $n..."
556 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
558 if test $? != 0 ; then
559 echo "test failed - server 1 and server $n databases differ"
560 test $KILLSERVERS != no && kill -HUP $KILLPIDS
566 echo "Using ldapmodify to delete entries from server 2..."
567 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
568 >> $TESTOUT 2>&1 << EOADDS
569 dn: cn=To be deleted by server 2,dc=example,dc=com
573 if test $RC != 0 ; then
574 echo "ldapmodify failed for server 2 database ($RC)!"
575 test $KILLSERVERS != no && kill -HUP $KILLPIDS
579 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
582 echo "Using ldapmodify to delete entries from server 3..."
583 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
584 >> $TESTOUT 2>&1 << EOADDS
585 dn: cn=To be deleted by server 3,dc=example,dc=com
589 if test $RC != 0 ; then
590 echo "ldapmodify failed for server 3 database ($RC)!"
591 test $KILLSERVERS != no && kill -HUP $KILLPIDS
595 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
599 while [ $n -le $MMR ]; do
600 PORT=`expr $BASEPORT + $n`
601 URI="ldap://${LOCALHOST}:$PORT/"
603 echo "Using ldapsearch to read all the entries from server $n..."
604 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
605 'objectclass=*' > $TESTDIR/server$n.out 2>&1
608 if test $RC != 0 ; then
609 echo "ldapsearch failed at server $n ($RC)!"
610 test $KILLSERVERS != no && kill -HUP $KILLPIDS
613 . $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
618 while [ $n -le $MMR ]; do
619 echo "Comparing retrieved entries from server 1 and server $n..."
620 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
622 if test $? != 0 ; then
623 echo "test failed - server 1 and server $n databases differ"
624 test $KILLSERVERS != no && kill -HUP $KILLPIDS
631 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
635 # test $KILLSERVERS != no && wait
638 echo "Restarting servers..."
641 while [ $n -le $MMR ]; do
642 PORT=`expr $BASEPORT + $n`
643 URI="ldap://${LOCALHOST}:$PORT/"
644 LOG=$TESTDIR/slapd.$n.log
645 echo "Starting server $n on TCP/IP port $PORT..."
647 echo "======================= RESTART =======================" >> $LOG
648 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
650 if test $WAIT != 0 ; then
654 KILLPIDS="$KILLPIDS $PID"
656 echo "Using ldapsearch to check that server $n is running..."
657 for i in 0 1 2 3 4 5; do
658 $LDAPSEARCH -s base -b "" -H $URI \
659 'objectclass=*' > /dev/null 2>&1
661 if test $RC = 0 ; then
664 echo "Waiting 5 seconds for slapd to start..."
668 if test $RC != 0 ; then
669 echo "ldapsearch failed ($RC)!"
670 test $KILLSERVERS != no && kill -HUP $KILLPIDS
676 # Insert modifications and more tests here.
677 echo "Waiting $SLEEP1 seconds for servers to resync..."
680 test $KILLSERVERS != no && kill -HUP $KILLPIDS
682 echo ">>>>> Test succeeded"
684 test $KILLSERVERS != no && wait