3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2011 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 test $BACKEND = null && nullExclude="# "
265 if [ "$BACKENDTYPE" = mod ]; then
267 dn: cn=module,cn=config
268 objectClass: olcModuleList
270 olcModulePath: ../../../servers/slapd/back-$BACKEND
271 olcModuleLoad: back_$BACKEND.la
277 dn: olcDatabase={1}$BACKEND,cn=config
278 objectClass: olcDatabaseConfig
279 ${nullExclude}objectClass: olc${BACKEND}Config
280 olcDatabase: {1}$BACKEND
282 ${nullExclude}olcDbDirectory: ./db
283 olcRootDN: $MANAGERDN
288 while [ $n -le $MMR ]; do
289 PORT=`expr $BASEPORT + $n`
290 URI="ldap://${LOCALHOST}:$PORT/"
292 echo "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP
293 echo " credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP
294 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
301 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
302 objectClass: olcOverlayConfig
303 objectClass: olcSyncProvConfig
306 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
308 if test $RC != 0 ; then
309 echo "ldapadd failed for database config ($RC)!"
310 test $KILLSERVERS != no && kill -HUP $KILLPIDS
316 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
317 dn: olcDatabase={1}$BACKEND,cn=config
320 olcDbIndex: objectClass,entryUUID,entryCSN eq
321 olcDbIndex: cn,uid pres,eq,sub
324 if test $RC != 0 ; then
325 echo "ldapadd modify for database config ($RC)!"
326 test $KILLSERVERS != no && kill -HUP $KILLPIDS
332 echo "Using ldapadd to populate server 1..."
333 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
336 if test $RC != 0 ; then
337 echo "ldapadd failed for server 1 database ($RC)!"
338 test $KILLSERVERS != no && kill -HUP $KILLPIDS
342 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
346 while [ $n -le $MMR ]; do
347 PORT=`expr $BASEPORT + $n`
348 URI="ldap://${LOCALHOST}:$PORT/"
350 echo "Using ldapsearch to read config from server $n..."
351 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF \
352 'objectclass=*' > $TESTDIR/server$n.out 2>&1
355 if test $RC != 0 ; then
356 echo "ldapsearch failed at server $n ($RC)!"
357 test $KILLSERVERS != no && kill -HUP $KILLPIDS
361 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
367 while [ $n -le $MMR ]; do
368 echo "Comparing retrieved configs from server 1 and server $n..."
369 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
371 if test $? != 0 ; then
372 echo "test failed - server 1 and server $n configs differ"
373 test $KILLSERVERS != no && kill -HUP $KILLPIDS
380 while [ $n -le $MMR ]; do
381 PORT=`expr $BASEPORT + $n`
382 URI="ldap://${LOCALHOST}:$PORT/"
384 echo "Using ldapsearch to read all the entries from server $n..."
385 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
386 'objectclass=*' > $TESTDIR/server$n.out 2>&1
389 if test $RC != 0 ; then
390 echo "ldapsearch failed at server $n ($RC)!"
391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
394 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
399 while [ $n -le $MMR ]; do
400 echo "Comparing retrieved entries from server 1 and server $n..."
401 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
403 if test $? != 0 ; then
404 echo "test failed - server 1 and server $n databases differ"
405 test $KILLSERVERS != no && kill -HUP $KILLPIDS
411 echo "Using ldapadd to populate server 2..."
412 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
415 if test $RC != 0 ; then
416 echo "ldapadd failed for server 2 database ($RC)!"
417 test $KILLSERVERS != no && kill -HUP $KILLPIDS
421 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
425 while [ $n -le $MMR ]; do
426 PORT=`expr $BASEPORT + $n`
427 URI="ldap://${LOCALHOST}:$PORT/"
429 echo "Using ldapsearch to read all the entries from server $n..."
430 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
431 'objectclass=*' > $TESTDIR/server$n.out 2>&1
434 if test $RC != 0 ; then
435 echo "ldapsearch failed at server $n ($RC)!"
436 test $KILLSERVERS != no && kill -HUP $KILLPIDS
439 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
444 while [ $n -le $MMR ]; do
445 echo "Comparing retrieved entries from server 1 and server $n..."
446 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
448 if test $? != 0 ; then
449 echo "test failed - server 1 and server $n databases differ"
450 test $KILLSERVERS != no && kill -HUP $KILLPIDS
456 echo "Using ldapadd to populate server 3..."
457 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
458 << EOMODS >> $TESTOUT 2>&1
459 dn: cn=Server 3 Test,dc=example,dc=com
465 if test $RC != 0 ; then
466 echo "ldapadd failed for server 3 database ($RC)!"
467 test $KILLSERVERS != no && kill -HUP $KILLPIDS
471 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
475 while [ $n -le $MMR ]; do
476 PORT=`expr $BASEPORT + $n`
477 URI="ldap://${LOCALHOST}:$PORT/"
479 echo "Using ldapsearch to read all the entries from server $n..."
480 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
481 'objectclass=*' > $TESTDIR/server$n.out 2>&1
484 if test $RC != 0 ; then
485 echo "ldapsearch failed at server $n ($RC)!"
486 test $KILLSERVERS != no && kill -HUP $KILLPIDS
489 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
494 while [ $n -le $MMR ]; do
495 echo "Comparing retrieved entries from server 1 and server $n..."
496 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
498 if test $? != 0 ; then
499 echo "test failed - server 1 and server $n databases differ"
500 test $KILLSERVERS != no && kill -HUP $KILLPIDS
506 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
507 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
508 >> $TESTOUT 2>&1 << EOADDS
509 dn: cn=To be deleted by server 1,dc=example,dc=com
512 # no distinguished values, will be added by DSA
514 dn: cn=To be deleted by server 2,dc=example,dc=com
517 # no distinguished values, will be added by DSA
519 dn: cn=To be deleted by server 3,dc=example,dc=com
522 # no distinguished values, will be added by DSA
524 dn: cn=To be deleted by server 1,dc=example,dc=com
528 if test $RC != 0 ; then
529 echo "ldapmodify failed for server 1 database ($RC)!"
530 test $KILLSERVERS != no && kill -HUP $KILLPIDS
534 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
538 while [ $n -le $MMR ]; do
539 PORT=`expr $BASEPORT + $n`
540 URI="ldap://${LOCALHOST}:$PORT/"
542 echo "Using ldapsearch to read all the entries from server $n..."
543 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
544 'objectclass=*' > $TESTDIR/server$n.out 2>&1
547 if test $RC != 0 ; then
548 echo "ldapsearch failed at server $n ($RC)!"
549 test $KILLSERVERS != no && kill -HUP $KILLPIDS
552 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
557 while [ $n -le $MMR ]; do
558 echo "Comparing retrieved entries from server 1 and server $n..."
559 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
561 if test $? != 0 ; then
562 echo "test failed - server 1 and server $n databases differ"
563 test $KILLSERVERS != no && kill -HUP $KILLPIDS
569 echo "Using ldapmodify to delete entries from server 2..."
570 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
571 >> $TESTOUT 2>&1 << EOADDS
572 dn: cn=To be deleted by server 2,dc=example,dc=com
576 if test $RC != 0 ; then
577 echo "ldapmodify failed for server 2 database ($RC)!"
578 test $KILLSERVERS != no && kill -HUP $KILLPIDS
582 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
585 echo "Using ldapmodify to delete entries from server 3..."
586 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
587 >> $TESTOUT 2>&1 << EOADDS
588 dn: cn=To be deleted by server 3,dc=example,dc=com
592 if test $RC != 0 ; then
593 echo "ldapmodify failed for server 3 database ($RC)!"
594 test $KILLSERVERS != no && kill -HUP $KILLPIDS
598 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
602 while [ $n -le $MMR ]; do
603 PORT=`expr $BASEPORT + $n`
604 URI="ldap://${LOCALHOST}:$PORT/"
606 echo "Using ldapsearch to read all the entries from server $n..."
607 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
608 'objectclass=*' > $TESTDIR/server$n.out 2>&1
611 if test $RC != 0 ; then
612 echo "ldapsearch failed at server $n ($RC)!"
613 test $KILLSERVERS != no && kill -HUP $KILLPIDS
616 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
621 while [ $n -le $MMR ]; do
622 echo "Comparing retrieved entries from server 1 and server $n..."
623 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
625 if test $? != 0 ; then
626 echo "test failed - server 1 and server $n databases differ"
627 test $KILLSERVERS != no && kill -HUP $KILLPIDS
634 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
638 # test $KILLSERVERS != no && wait
641 echo "Restarting servers..."
644 echo "Starting server 1 on TCP/IP port $PORT1..."
645 echo "======================= RESTART =======================" >> $LOG1
647 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
649 if test $WAIT != 0 ; then
658 echo "Using ldapsearch to check that server 1 is running..."
659 for i in 0 1 2 3 4 5; do
660 $LDAPSEARCH -s base -b "" -H $URI1 \
661 'objectclass=*' > /dev/null 2>&1
663 if test $RC = 0 ; then
666 echo "Waiting 5 seconds for slapd to start..."
670 if test $RC != 0 ; then
671 echo "ldapsearch failed ($RC)!"
672 test $KILLSERVERS != no && kill -HUP $KILLPIDS
677 while [ $n -le $MMR ]; do
678 PORT=`expr $BASEPORT + $n`
679 URI="ldap://${LOCALHOST}:$PORT/"
680 LOG=$TESTDIR/slapd.$n.log
681 echo "Starting server $n on TCP/IP port $PORT..."
683 echo "======================= RESTART =======================" >> $LOG
684 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
686 if test $WAIT != 0 ; then
690 KILLPIDS="$KILLPIDS $PID"
696 while [ $n -le $MMR ]; do
697 PORT=`expr $BASEPORT + $n`
698 URI="ldap://${LOCALHOST}:$PORT/"
699 echo "Using ldapsearch to check that server $n is running..."
700 for i in 0 1 2 3 4 5; do
701 $LDAPSEARCH -s base -b "" -H $URI \
702 'objectclass=*' > /dev/null 2>&1
704 if test $RC = 0 ; then
707 echo "Waiting 5 seconds for slapd to start..."
711 if test $RC != 0 ; then
712 echo "ldapsearch failed ($RC)!"
713 test $KILLSERVERS != no && kill -HUP $KILLPIDS
719 # Insert modifications and more tests here.
720 echo "Waiting $SLEEP1 seconds for servers to resync..."
723 echo "Using ldapmodify to add/modify/delete entries from server 1..."
724 for i in 1 2 3 4 5 6 7 8 9 10; do
726 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
727 >> $TESTOUT 2>&1 << EOMODS
728 dn: cn=Add-Mod-Del,dc=example,dc=com
731 objectclass: organizationalRole
733 dn: cn=Add-Mod-Del,dc=example,dc=com
736 description: guinea pig
739 dn: cn=Add-Mod-Del,dc=example,dc=com
743 if test $RC != 0 ; then
744 echo "ldapmodify failed for server 1 database ($RC)!"
745 test $KILLSERVERS != no && kill -HUP $KILLPIDS
750 echo "Waiting $SLEEP1 seconds for servers to resync..."
754 while [ $n -le $MMR ]; do
755 PORT=`expr $BASEPORT + $n`
756 URI="ldap://${LOCALHOST}:$PORT/"
758 echo "Using ldapsearch to read all the entries from server $n..."
759 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
760 'objectclass=*' > $TESTDIR/server$n.out 2>&1
763 if test $RC != 0 ; then
764 echo "ldapsearch failed at server $n ($RC)!"
765 test $KILLSERVERS != no && kill -HUP $KILLPIDS
768 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
773 while [ $n -le $MMR ]; do
774 echo "Comparing retrieved entries from server 1 and server $n..."
775 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
777 if test $? != 0 ; then
778 echo "test failed - server 1 and server $n databases differ"
779 test $KILLSERVERS != no && kill -HUP $KILLPIDS
785 test $KILLSERVERS != no && kill -HUP $KILLPIDS
787 echo ">>>>> Test succeeded"
789 test $KILLSERVERS != no && wait