3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2008 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"
32 CFCON2=$CONDIR2/slapd.d
34 mkdir -p $TESTDIR $PRODIR $CONDIR $CONDIR2 $DBPRO $DBCON $DBCON2 $CFPRO $CFCON $CFCON2
36 $SLAPPASSWD -g -n >$CONFIGPWF
38 if test x"$SYNCMODE" = x ; then
43 SYNCTYPE="type=refreshOnly interval=00:00:00:10"
46 SYNCTYPE="type=refreshAndPersist"
49 echo "unknown sync mode $SYNCMODE"
56 # Test replication of dynamic config:
60 # - configure over ldap
61 # - populate over ldap
62 # - configure syncrepl over ldap
63 # - retrieve database over ldap and compare against expected results
66 echo "Initializing server configurations..."
67 $SLAPADD -F $CFCON2 -n 0 <<EOF
69 objectClass: olcGlobal
73 dn: olcDatabase={0}config,cn=config
74 objectClass: olcDatabaseConfig
75 olcDatabase: {0}config
76 olcRootPW:< file://$CONFIGPWF
79 $SLAPADD -F $CFCON -n 0 <<EOF
81 objectClass: olcGlobal
85 dn: olcDatabase={0}config,cn=config
86 objectClass: olcDatabaseConfig
87 olcDatabase: {0}config
88 olcRootPW:< file://$CONFIGPWF
91 $SLAPADD -F $CFPRO -n 0 <<EOF
93 objectClass: olcGlobal
97 dn: olcDatabase={0}config,cn=config
98 objectClass: olcDatabaseConfig
99 olcDatabase: {0}config
100 olcRootPW:< file://$CONFIGPWF
103 echo "Starting producer slapd on TCP/IP port $PORT1..."
105 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
107 if test $WAIT != 0 ; then
116 echo "Using ldapsearch to check that producer slapd is running..."
117 for i in 0 1 2 3 4 5; do
118 $LDAPSEARCH -s base -b "" -H $URI1 \
119 'objectclass=*' > /dev/null 2>&1
121 if test $RC = 0 ; then
124 echo "Waiting 5 seconds for slapd to start..."
128 if test $RC != 0 ; then
129 echo "ldapsearch failed ($RC)!"
130 test $KILLSERVERS != no && kill -HUP $KILLPIDS
134 echo "Inserting syncprov overlay on producer..."
135 if [ "$SYNCPROV" = syncprovmod ]; then
136 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
137 dn: cn=module,cn=config
138 objectClass: olcModuleList
140 olcModulePath: ../../../servers/slapd/overlays
141 olcModuleLoad: syncprov.la
144 if test $RC != 0 ; then
145 echo "ldapadd failed for moduleLoad ($RC)!"
146 test $KILLSERVERS != no && kill -HUP $KILLPIDS
151 # Note that we configure a timeout here; it's possible for both
152 # servers to attempt to bind to each other while a modify to
153 # cn=config is in progress. When the modify pauses the thread pool
154 # neither server will progress. The timeout will drop the syncrepl
155 # attempt and allow the modifies to complete.
157 read CONFIGPW < $CONFIGPWF
158 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
166 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
168 objectClass: olcOverlayConfig
169 objectClass: olcSyncProvConfig
172 dn: olcDatabase={0}config,cn=config
175 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
176 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
177 retry="5 5 300 5" timeout=3
178 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
179 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
180 retry="5 5 300 5" timeout=3
181 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
182 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
183 retry="5 5 300 5" timeout=3
189 if test $RC != 0 ; then
190 echo "ldapmodify failed for syncrepl config ($RC)!"
191 test $KILLSERVERS != no && kill -HUP $KILLPIDS
195 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
197 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
199 if test $WAIT != 0 ; then
200 echo SLAVEPID $SLAVEPID
203 KILLPIDS="$KILLPIDS $SLAVEPID"
208 echo "Using ldapsearch to check that consumer1 slapd is running..."
209 for i in 0 1 2 3 4 5; do
210 $LDAPSEARCH -s base -b "" -H $URI2 \
211 'objectclass=*' > /dev/null 2>&1
213 if test $RC = 0 ; then
216 echo "Waiting 5 seconds for slapd to start..."
220 if test $RC != 0 ; then
221 echo "ldapsearch failed ($RC)!"
222 test $KILLSERVERS != no && kill -HUP $KILLPIDS
226 echo "Configuring syncrepl on consumer1..."
227 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
228 dn: olcDatabase={0}config,cn=config
231 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
232 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
233 retry="5 5 300 5" timeout=3
234 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
235 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
236 retry="5 5 300 5" timeout=3
237 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
238 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
239 retry="5 5 300 5" timeout=3
245 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
247 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
249 if test $WAIT != 0 ; then
250 echo SLAVE2PID $SLAVE2PID
253 KILLPIDS="$KILLPIDS $SLAVE2PID"
258 echo "Using ldapsearch to check that consumer2 slapd is running..."
259 for i in 0 1 2 3 4 5; do
260 $LDAPSEARCH -s base -b "" -H $URI3 \
261 'objectclass=*' > /dev/null 2>&1
263 if test $RC = 0 ; then
266 echo "Waiting 5 seconds for slapd to start..."
270 if test $RC != 0 ; then
271 echo "ldapsearch failed ($RC)!"
272 test $KILLSERVERS != no && kill -HUP $KILLPIDS
276 echo "Configuring syncrepl on consumer2..."
277 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
278 dn: olcDatabase={0}config,cn=config
281 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
282 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
283 retry="5 5 300 5" timeout=3
284 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
285 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
286 retry="5 5 300 5" timeout=3
287 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
288 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
289 retry="5 5 300 5" timeout=3
295 echo "Adding schema and databases on producer..."
296 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
297 include: file://$ABS_SCHEMADIR/core.ldif
299 include: file://$ABS_SCHEMADIR/cosine.ldif
301 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
303 include: file://$ABS_SCHEMADIR/openldap.ldif
305 include: file://$ABS_SCHEMADIR/nis.ldif
308 if test $RC != 0 ; then
309 echo "ldapadd failed for schema config ($RC)!"
310 test $KILLSERVERS != no && kill -HUP $KILLPIDS
314 if [ "$BACKENDTYPE" = mod ]; then
315 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
316 dn: cn=module,cn=config
317 objectClass: olcModuleList
319 olcModulePath: ../../../servers/slapd/back-$BACKEND
320 olcModuleLoad: back_$BACKEND.la
323 if test $RC != 0 ; then
324 echo "ldapadd failed for backend config ($RC)!"
325 test $KILLSERVERS != no && kill -HUP $KILLPIDS
330 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
331 dn: olcDatabase={1}$BACKEND,cn=config
332 objectClass: olcDatabaseConfig
333 objectClass: olc${BACKEND}Config
334 olcDatabase: {1}$BACKEND
337 olcRootDN: $MANAGERDN
339 olcSyncRepl: rid=004 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
340 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
341 retry="5 5 300 5" timeout=3
342 olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
343 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
344 retry="5 5 300 5" timeout=3
345 olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
346 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
347 retry="5 5 300 5" timeout=3
350 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
352 objectClass: olcOverlayConfig
353 objectClass: olcSyncProvConfig
357 if test $RC != 0 ; then
358 echo "ldapadd failed for database config ($RC)!"
359 test $KILLSERVERS != no && kill -HUP $KILLPIDS
363 echo "Using ldapadd to populate producer..."
364 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
367 if test $RC != 0 ; then
368 echo "ldapadd failed for producer database ($RC)!"
369 test $KILLSERVERS != no && kill -HUP $KILLPIDS
374 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
377 echo "Using ldapadd to populate consumer1..."
378 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
381 if test $RC != 0 ; then
382 echo "ldapadd failed for consumer1 database ($RC)!"
383 test $KILLSERVERS != no && kill -HUP $KILLPIDS
388 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
391 echo "Using ldapadd to populate consumer2..."
392 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
393 << EOMODS >> $TESTOUT 2>&1
394 dn: cn=Consumer 2 Test,dc=example,dc=com
400 if test $RC != 0 ; then
401 echo "ldapadd failed for consumer2 database ($RC)!"
402 test $KILLSERVERS != no && kill -HUP $KILLPIDS
407 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
410 echo "Using ldapmodify to add to the producer entries that will be deleted..."
411 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
412 >> $TESTOUT 2>&1 << EOADDS
413 dn: cn=To be deleted by producer,dc=example,dc=com
416 # no distinguished values, will be added by DSA
418 dn: cn=To be deleted by consumer1,dc=example,dc=com
421 # no distinguished values, will be added by DSA
423 dn: cn=To be deleted by consumer2,dc=example,dc=com
426 # no distinguished values, will be added by DSA
428 dn: cn=To be deleted by producer,dc=example,dc=com
432 if test $RC != 0 ; then
433 echo "ldapmodify failed for producer database ($RC)!"
434 test $KILLSERVERS != no && kill -HUP $KILLPIDS
439 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
442 echo "Using ldapmodify to delete entries from consumer1..."
443 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
444 >> $TESTOUT 2>&1 << EOADDS
445 dn: cn=To be deleted by consumer1,dc=example,dc=com
449 if test $RC != 0 ; then
450 echo "ldapmodify failed for consumer2 database ($RC)!"
451 test $KILLSERVERS != no && kill -HUP $KILLPIDS
456 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
459 echo "Using ldapmodify to delete entries from consumer2..."
460 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
461 >> $TESTOUT 2>&1 << EOADDS
462 dn: cn=To be deleted by consumer2,dc=example,dc=com
466 if test $RC != 0 ; then
467 echo "ldapmodify failed for consumer2 database ($RC)!"
468 test $KILLSERVERS != no && kill -HUP $KILLPIDS
473 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
476 echo "Using ldapsearch to check that syncrepl received database changes..."
478 for i in 0 1 2 3 4 5; do
479 RESULT=`$LDAPSEARCH -H $URI2 \
480 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
481 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
482 if test "x$RESULT" = "xOK" ; then
486 echo "Waiting 5 seconds for syncrepl to receive changes..."
490 if test $RC != 0 ; then
491 echo "ldapsearch failed ($RC)!"
492 test $KILLSERVERS != no && kill -HUP $KILLPIDS
496 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
498 for i in 0 1 2 3 4 5; do
499 RESULT=`$LDAPSEARCH -H $URI3 \
500 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
501 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
502 if test "x$RESULT" = "xOK" ; then
506 echo "Waiting 5 seconds for syncrepl to receive changes..."
510 if test $RC != 0 ; then
511 echo "ldapsearch failed ($RC)!"
512 test $KILLSERVERS != no && kill -HUP $KILLPIDS
516 echo "Using ldapsearch to read config from the producer..."
517 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
518 'objectclass=*' > $MASTEROUT 2>&1
521 if test $RC != 0 ; then
522 echo "ldapsearch failed at producer ($RC)!"
523 test $KILLSERVERS != no && kill -HUP $KILLPIDS
527 echo "Using ldapsearch to read config from consumer1..."
528 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
529 'objectclass=*' > $SLAVEOUT 2>&1
532 if test $RC != 0 ; then
533 echo "ldapsearch failed at consumer1 ($RC)!"
534 test $KILLSERVERS != no && kill -HUP $KILLPIDS
538 echo "Using ldapsearch to read config from consumer2..."
539 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
540 'objectclass=*' > $SLAVE2OUT 2>&1
543 if test $RC != 0 ; then
544 echo "ldapsearch failed at consumer2 ($RC)!"
545 test $KILLSERVERS != no && kill -HUP $KILLPIDS
549 echo "Filtering producer results..."
550 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
551 echo "Filtering consumer1 results..."
552 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
553 echo "Filtering consumer2 results..."
554 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
556 echo "Comparing retrieved configs from producer and consumer1..."
557 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
559 if test $? != 0 ; then
560 echo "test failed - producer and consumer1 configs differ"
561 test $KILLSERVERS != no && kill -HUP $KILLPIDS
565 echo "Comparing retrieved configs from producer and consumer2..."
566 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
568 if test $? != 0 ; then
569 echo "test failed - producer and consumer2 configs differ"
570 test $KILLSERVERS != no && kill -HUP $KILLPIDS
574 echo "Using ldapsearch to read all the entries from the producer..."
575 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
576 'objectclass=*' > $MASTEROUT 2>&1
579 if test $RC != 0 ; then
580 echo "ldapsearch failed at producer ($RC)!"
581 test $KILLSERVERS != no && kill -HUP $KILLPIDS
585 echo "Using ldapsearch to read all the entries from consumer1..."
586 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
587 'objectclass=*' > $SLAVEOUT 2>&1
590 if test $RC != 0 ; then
591 echo "ldapsearch failed at consumer1 ($RC)!"
592 test $KILLSERVERS != no && kill -HUP $KILLPIDS
596 echo "Using ldapsearch to read all the entries from consumer2..."
597 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
598 'objectclass=*' > $SLAVE2OUT 2>&1
601 if test $RC != 0 ; then
602 echo "ldapsearch failed at consumer2 ($RC)!"
603 test $KILLSERVERS != no && kill -HUP $KILLPIDS
608 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
611 echo "Filtering producer results..."
612 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
613 echo "Filtering consumer1 results..."
614 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
615 echo "Filtering consumer2 results..."
616 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
618 echo "Comparing retrieved entries from producer and consumer1..."
619 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
621 if test $? != 0 ; then
622 echo "test failed - producer and consumer1 databases differ"
626 echo "Comparing retrieved entries from producer and consumer2..."
627 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
629 if test $? != 0 ; then
630 echo "test failed - producer and consumer2 databases differ"
635 # test $KILLSERVERS != no && wait
638 echo "Restarting servers..."
639 echo "Starting producer slapd on TCP/IP port $PORT1..."
641 echo "======================= RESTART =======================" >> $LOG1
642 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
644 if test $WAIT != 0 ; then
650 echo "Using ldapsearch to check that producer slapd is running..."
651 for i in 0 1 2 3 4 5; do
652 $LDAPSEARCH -s base -b "" -H $URI1 \
653 'objectclass=*' > /dev/null 2>&1
655 if test $RC = 0 ; then
658 echo "Waiting 5 seconds for slapd to start..."
662 if test $RC != 0 ; then
663 echo "ldapsearch failed ($RC)!"
664 test $KILLSERVERS != no && kill -HUP $KILLPIDS
668 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
670 echo "======================= RESTART =======================" >> $LOG2
671 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
673 if test $WAIT != 0 ; then
674 echo SLAVEPID $SLAVEPID
677 KILLPIDS="$KILLPIDS $SLAVEPID"
682 echo "Using ldapsearch to check that consumer1 slapd is running..."
683 for i in 0 1 2 3 4 5; do
684 $LDAPSEARCH -s base -b "" -H $URI2 \
685 'objectclass=*' > /dev/null 2>&1
687 if test $RC = 0 ; then
690 echo "Waiting 5 seconds for slapd to start..."
694 if test $RC != 0 ; then
695 echo "ldapsearch failed ($RC)!"
696 test $KILLSERVERS != no && kill -HUP $KILLPIDS
700 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
702 echo "======================= RESTART =======================" >> $LOG3
703 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
705 if test $WAIT != 0 ; then
706 echo SLAVE2PID $SLAVE2PID
709 KILLPIDS="$KILLPIDS $SLAVE2PID"
714 echo "Using ldapsearch to check that consumer2 slapd is running..."
715 for i in 0 1 2 3 4 5; do
716 $LDAPSEARCH -s base -b "" -H $URI3 \
717 'objectclass=*' > /dev/null 2>&1
719 if test $RC = 0 ; then
722 echo "Waiting 5 seconds for slapd to start..."
726 if test $RC != 0 ; then
727 echo "ldapsearch failed ($RC)!"
728 test $KILLSERVERS != no && kill -HUP $KILLPIDS
732 # Insert modifications and more tests here.
734 echo "Waiting $SLEEP seconds for servers to resync..."
737 test $KILLSERVERS != no && kill -HUP $KILLPIDS
739 echo ">>>>> Test succeeded"
741 test $KILLSERVERS != no && wait