3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2012 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: $TESTWD/../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: $TESTWD/../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
314 if test $INDEXDB = indexdb ; then
315 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
316 dn: olcDatabase={1}$BACKEND,cn=config
319 olcDbIndex: objectClass,entryUUID,entryCSN eq
320 olcDbIndex: cn,uid pres,eq,sub
323 if test $RC != 0 ; then
324 echo "ldapadd modify for database config ($RC)!"
325 test $KILLSERVERS != no && kill -HUP $KILLPIDS
330 echo "Using ldapadd to populate server 1..."
331 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
334 if test $RC != 0 ; then
335 echo "ldapadd failed for server 1 database ($RC)!"
336 test $KILLSERVERS != no && kill -HUP $KILLPIDS
340 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
344 while [ $n -le $MMR ]; do
345 PORT=`expr $BASEPORT + $n`
346 URI="ldap://${LOCALHOST}:$PORT/"
348 echo "Using ldapsearch to read config from server $n..."
349 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF \
350 'objectclass=*' > $TESTDIR/server$n.out 2>&1
353 if test $RC != 0 ; then
354 echo "ldapsearch failed at server $n ($RC)!"
355 test $KILLSERVERS != no && kill -HUP $KILLPIDS
359 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
365 while [ $n -le $MMR ]; do
366 echo "Comparing retrieved configs from server 1 and server $n..."
367 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
369 if test $? != 0 ; then
370 echo "test failed - server 1 and server $n configs differ"
371 test $KILLSERVERS != no && kill -HUP $KILLPIDS
378 while [ $n -le $MMR ]; do
379 PORT=`expr $BASEPORT + $n`
380 URI="ldap://${LOCALHOST}:$PORT/"
382 echo "Using ldapsearch to read all the entries from server $n..."
383 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
384 'objectclass=*' > $TESTDIR/server$n.out 2>&1
387 if test $RC != 0 ; then
388 echo "ldapsearch failed at server $n ($RC)!"
389 test $KILLSERVERS != no && kill -HUP $KILLPIDS
392 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
397 while [ $n -le $MMR ]; do
398 echo "Comparing retrieved entries from server 1 and server $n..."
399 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
401 if test $? != 0 ; then
402 echo "test failed - server 1 and server $n databases differ"
403 test $KILLSERVERS != no && kill -HUP $KILLPIDS
409 echo "Using ldapadd to populate server 2..."
410 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
413 if test $RC != 0 ; then
414 echo "ldapadd failed for server 2 database ($RC)!"
415 test $KILLSERVERS != no && kill -HUP $KILLPIDS
419 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
423 while [ $n -le $MMR ]; do
424 PORT=`expr $BASEPORT + $n`
425 URI="ldap://${LOCALHOST}:$PORT/"
427 echo "Using ldapsearch to read all the entries from server $n..."
428 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
429 'objectclass=*' > $TESTDIR/server$n.out 2>&1
432 if test $RC != 0 ; then
433 echo "ldapsearch failed at server $n ($RC)!"
434 test $KILLSERVERS != no && kill -HUP $KILLPIDS
437 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
442 while [ $n -le $MMR ]; do
443 echo "Comparing retrieved entries from server 1 and server $n..."
444 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
446 if test $? != 0 ; then
447 echo "test failed - server 1 and server $n databases differ"
448 test $KILLSERVERS != no && kill -HUP $KILLPIDS
454 echo "Using ldapadd to populate server 3..."
455 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
456 << EOMODS >> $TESTOUT 2>&1
457 dn: cn=Server 3 Test,dc=example,dc=com
463 if test $RC != 0 ; then
464 echo "ldapadd failed for server 3 database ($RC)!"
465 test $KILLSERVERS != no && kill -HUP $KILLPIDS
469 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
473 while [ $n -le $MMR ]; do
474 PORT=`expr $BASEPORT + $n`
475 URI="ldap://${LOCALHOST}:$PORT/"
477 echo "Using ldapsearch to read all the entries from server $n..."
478 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
479 'objectclass=*' > $TESTDIR/server$n.out 2>&1
482 if test $RC != 0 ; then
483 echo "ldapsearch failed at server $n ($RC)!"
484 test $KILLSERVERS != no && kill -HUP $KILLPIDS
487 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
492 while [ $n -le $MMR ]; do
493 echo "Comparing retrieved entries from server 1 and server $n..."
494 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
496 if test $? != 0 ; then
497 echo "test failed - server 1 and server $n databases differ"
498 test $KILLSERVERS != no && kill -HUP $KILLPIDS
504 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
505 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
506 >> $TESTOUT 2>&1 << EOADDS
507 dn: cn=To be deleted by server 1,dc=example,dc=com
510 # no distinguished values, will be added by DSA
512 dn: cn=To be deleted by server 2,dc=example,dc=com
515 # no distinguished values, will be added by DSA
517 dn: cn=To be deleted by server 3,dc=example,dc=com
520 # no distinguished values, will be added by DSA
522 dn: cn=To be deleted by server 1,dc=example,dc=com
526 if test $RC != 0 ; then
527 echo "ldapmodify failed for server 1 database ($RC)!"
528 test $KILLSERVERS != no && kill -HUP $KILLPIDS
532 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
536 while [ $n -le $MMR ]; do
537 PORT=`expr $BASEPORT + $n`
538 URI="ldap://${LOCALHOST}:$PORT/"
540 echo "Using ldapsearch to read all the entries from server $n..."
541 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
542 'objectclass=*' > $TESTDIR/server$n.out 2>&1
545 if test $RC != 0 ; then
546 echo "ldapsearch failed at server $n ($RC)!"
547 test $KILLSERVERS != no && kill -HUP $KILLPIDS
550 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
555 while [ $n -le $MMR ]; do
556 echo "Comparing retrieved entries from server 1 and server $n..."
557 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
559 if test $? != 0 ; then
560 echo "test failed - server 1 and server $n databases differ"
561 test $KILLSERVERS != no && kill -HUP $KILLPIDS
567 echo "Using ldapmodify to delete entries from server 2..."
568 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
569 >> $TESTOUT 2>&1 << EOADDS
570 dn: cn=To be deleted by server 2,dc=example,dc=com
574 if test $RC != 0 ; then
575 echo "ldapmodify failed for server 2 database ($RC)!"
576 test $KILLSERVERS != no && kill -HUP $KILLPIDS
580 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
583 echo "Using ldapmodify to delete entries from server 3..."
584 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
585 >> $TESTOUT 2>&1 << EOADDS
586 dn: cn=To be deleted by server 3,dc=example,dc=com
590 if test $RC != 0 ; then
591 echo "ldapmodify failed for server 3 database ($RC)!"
592 test $KILLSERVERS != no && kill -HUP $KILLPIDS
596 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
600 while [ $n -le $MMR ]; do
601 PORT=`expr $BASEPORT + $n`
602 URI="ldap://${LOCALHOST}:$PORT/"
604 echo "Using ldapsearch to read all the entries from server $n..."
605 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
606 'objectclass=*' > $TESTDIR/server$n.out 2>&1
609 if test $RC != 0 ; then
610 echo "ldapsearch failed at server $n ($RC)!"
611 test $KILLSERVERS != no && kill -HUP $KILLPIDS
614 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
619 while [ $n -le $MMR ]; do
620 echo "Comparing retrieved entries from server 1 and server $n..."
621 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
623 if test $? != 0 ; then
624 echo "test failed - server 1 and server $n databases differ"
625 test $KILLSERVERS != no && kill -HUP $KILLPIDS
632 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
636 # test $KILLSERVERS != no && wait
639 echo "Restarting servers..."
642 echo "Starting server 1 on TCP/IP port $PORT1..."
643 echo "======================= RESTART =======================" >> $LOG1
645 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
647 if test $WAIT != 0 ; then
656 echo "Using ldapsearch to check that server 1 is running..."
657 for i in 0 1 2 3 4 5; do
658 $LDAPSEARCH -s base -b "" -H $URI1 \
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
675 while [ $n -le $MMR ]; do
676 PORT=`expr $BASEPORT + $n`
677 URI="ldap://${LOCALHOST}:$PORT/"
678 LOG=$TESTDIR/slapd.$n.log
679 echo "Starting server $n on TCP/IP port $PORT..."
681 echo "======================= RESTART =======================" >> $LOG
682 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
684 if test $WAIT != 0 ; then
688 KILLPIDS="$KILLPIDS $PID"
694 while [ $n -le $MMR ]; do
695 PORT=`expr $BASEPORT + $n`
696 URI="ldap://${LOCALHOST}:$PORT/"
697 echo "Using ldapsearch to check that server $n is running..."
698 for i in 0 1 2 3 4 5; do
699 $LDAPSEARCH -s base -b "" -H $URI \
700 'objectclass=*' > /dev/null 2>&1
702 if test $RC = 0 ; then
705 echo "Waiting 5 seconds for slapd to start..."
709 if test $RC != 0 ; then
710 echo "ldapsearch failed ($RC)!"
711 test $KILLSERVERS != no && kill -HUP $KILLPIDS
717 # Insert modifications and more tests here.
718 echo "Waiting $SLEEP1 seconds for servers to resync..."
721 echo "Using ldapmodify to add/modify/delete entries from server 1..."
722 for i in 1 2 3 4 5 6 7 8 9 10; do
724 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
725 >> $TESTOUT 2>&1 << EOMODS
726 dn: cn=Add-Mod-Del,dc=example,dc=com
729 objectclass: organizationalRole
731 dn: cn=Add-Mod-Del,dc=example,dc=com
734 description: guinea pig
737 dn: cn=Add-Mod-Del,dc=example,dc=com
741 if test $RC != 0 ; then
742 echo "ldapmodify failed for server 1 database ($RC)!"
743 test $KILLSERVERS != no && kill -HUP $KILLPIDS
748 echo "Waiting $SLEEP1 seconds for servers to resync..."
752 while [ $n -le $MMR ]; do
753 PORT=`expr $BASEPORT + $n`
754 URI="ldap://${LOCALHOST}:$PORT/"
756 echo "Using ldapsearch to read all the entries from server $n..."
757 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
758 'objectclass=*' > $TESTDIR/server$n.out 2>&1
761 if test $RC != 0 ; then
762 echo "ldapsearch failed at server $n ($RC)!"
763 test $KILLSERVERS != no && kill -HUP $KILLPIDS
766 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
771 while [ $n -le $MMR ]; do
772 echo "Comparing retrieved entries from server 1 and server $n..."
773 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
775 if test $? != 0 ; then
776 echo "test failed - server 1 and server $n databases differ"
777 test $KILLSERVERS != no && kill -HUP $KILLPIDS
783 test $KILLSERVERS != no && kill -HUP $KILLPIDS
785 echo ">>>>> Test succeeded"
787 test $KILLSERVERS != no && wait