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"
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"
55 # Test replication of dynamic config:
59 # - configure over ldap
60 # - populate over ldap
61 # - configure syncrepl over ldap
62 # - retrieve database over ldap and compare against expected results
65 echo "Initializing server configurations..."
66 $SLAPADD -F $CFCON2 -n 0 <<EOF
68 objectClass: olcGlobal
72 dn: olcDatabase={0}config,cn=config
73 objectClass: olcDatabaseConfig
74 olcDatabase: {0}config
75 olcRootPW:< file://$CONFIGPWF
78 $SLAPADD -F $CFCON -n 0 <<EOF
80 objectClass: olcGlobal
84 dn: olcDatabase={0}config,cn=config
85 objectClass: olcDatabaseConfig
86 olcDatabase: {0}config
87 olcRootPW:< file://$CONFIGPWF
90 $SLAPADD -F $CFPRO -n 0 <<EOF
92 objectClass: olcGlobal
96 dn: olcDatabase={0}config,cn=config
97 objectClass: olcDatabaseConfig
98 olcDatabase: {0}config
99 olcRootPW:< file://$CONFIGPWF
102 echo "Starting producer slapd on TCP/IP port $PORT1..."
104 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
106 if test $WAIT != 0 ; then
115 echo "Using ldapsearch to check that producer slapd is running..."
116 for i in 0 1 2 3 4 5; do
117 $LDAPSEARCH -s base -b "" -H $URI1 \
118 'objectclass=*' > /dev/null 2>&1
120 if test $RC = 0 ; then
123 echo "Waiting 5 seconds for slapd to start..."
127 if test $RC != 0 ; then
128 echo "ldapsearch failed ($RC)!"
129 test $KILLSERVERS != no && kill -HUP $KILLPIDS
133 echo "Inserting syncprov overlay on producer..."
134 if [ "$SYNCPROV" = syncprovmod ]; then
135 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
136 dn: cn=module,cn=config
137 objectClass: olcModuleList
139 olcModulePath: ../../../servers/slapd/overlays
140 olcModuleLoad: syncprov.la
143 if test $RC != 0 ; then
144 echo "ldapadd failed for moduleLoad ($RC)!"
145 test $KILLSERVERS != no && kill -HUP $KILLPIDS
150 # Note that we configure a timeout here; it's possible for both
151 # servers to attempt to bind to each other while a modify to
152 # cn=config is in progress. When the modify pauses the thread pool
153 # neither server will progress. The timeout will drop the syncrepl
154 # attempt and allow the modifies to complete.
156 read CONFIGPW < $CONFIGPWF
157 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
165 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
167 objectClass: olcOverlayConfig
168 objectClass: olcSyncProvConfig
171 dn: olcDatabase={0}config,cn=config
174 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
175 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
176 retry="5 5 300 5" timeout=3
177 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
178 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
179 retry="5 5 300 5" timeout=3
180 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
181 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
182 retry="5 5 300 5" timeout=3
188 if test $RC != 0 ; then
189 echo "ldapmodify failed for syncrepl config ($RC)!"
190 test $KILLSERVERS != no && kill -HUP $KILLPIDS
194 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
196 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
198 if test $WAIT != 0 ; then
199 echo SLAVEPID $SLAVEPID
202 KILLPIDS="$KILLPIDS $SLAVEPID"
207 echo "Using ldapsearch to check that consumer1 slapd is running..."
208 for i in 0 1 2 3 4 5; do
209 $LDAPSEARCH -s base -b "" -H $URI2 \
210 'objectclass=*' > /dev/null 2>&1
212 if test $RC = 0 ; then
215 echo "Waiting 5 seconds for slapd to start..."
219 if test $RC != 0 ; then
220 echo "ldapsearch failed ($RC)!"
221 test $KILLSERVERS != no && kill -HUP $KILLPIDS
225 echo "Configuring syncrepl on consumer1..."
226 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
227 dn: olcDatabase={0}config,cn=config
230 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
231 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
232 retry="5 5 300 5" timeout=3
233 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
234 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
235 retry="5 5 300 5" timeout=3
236 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
237 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
238 retry="5 5 300 5" timeout=3
244 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
246 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
248 if test $WAIT != 0 ; then
249 echo SLAVE2PID $SLAVE2PID
252 KILLPIDS="$KILLPIDS $SLAVE2PID"
257 echo "Using ldapsearch to check that consumer2 slapd is running..."
258 for i in 0 1 2 3 4 5; do
259 $LDAPSEARCH -s base -b "" -H $URI3 \
260 'objectclass=*' > /dev/null 2>&1
262 if test $RC = 0 ; then
265 echo "Waiting 5 seconds for slapd to start..."
269 if test $RC != 0 ; then
270 echo "ldapsearch failed ($RC)!"
271 test $KILLSERVERS != no && kill -HUP $KILLPIDS
275 echo "Configuring syncrepl on consumer2..."
276 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
277 dn: olcDatabase={0}config,cn=config
280 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
281 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
282 retry="5 5 300 5" timeout=3
283 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
284 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
285 retry="5 5 300 5" timeout=3
286 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
287 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
288 retry="5 5 300 5" timeout=3
294 echo "Adding schema and databases on producer..."
295 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
296 include: file://$ABS_SCHEMADIR/core.ldif
298 include: file://$ABS_SCHEMADIR/cosine.ldif
300 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
302 include: file://$ABS_SCHEMADIR/openldap.ldif
304 include: file://$ABS_SCHEMADIR/nis.ldif
307 if test $RC != 0 ; then
308 echo "ldapadd failed for schema config ($RC)!"
309 test $KILLSERVERS != no && kill -HUP $KILLPIDS
313 if [ "$BACKENDTYPE" = mod ]; then
314 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
315 dn: cn=module,cn=config
316 objectClass: olcModuleList
318 olcModulePath: ../../../servers/slapd/back-$BACKEND
319 olcModuleLoad: back_$BACKEND.la
322 if test $RC != 0 ; then
323 echo "ldapadd failed for backend config ($RC)!"
324 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
330 dn: olcDatabase={1}$BACKEND,cn=config
331 objectClass: olcDatabaseConfig
332 objectClass: olc${BACKEND}Config
333 olcDatabase: {1}$BACKEND
336 olcRootDN: $MANAGERDN
338 olcSyncRepl: rid=004 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
339 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
340 retry="5 5 300 5" timeout=3
341 olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
342 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
343 retry="5 5 300 5" timeout=3
344 olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
345 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
346 retry="5 5 300 5" timeout=3
349 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
351 objectClass: olcOverlayConfig
352 objectClass: olcSyncProvConfig
356 if test $RC != 0 ; then
357 echo "ldapadd failed for database config ($RC)!"
358 test $KILLSERVERS != no && kill -HUP $KILLPIDS
364 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
365 dn: olcDatabase={1}$BACKEND,cn=config
368 olcDbIndex: objectClass,entryUUID,entryCSN eq
369 olcDbIndex: cn,uid pres,eq,sub
372 if test $RC != 0 ; then
373 echo "ldapadd modify for database config ($RC)!"
374 test $KILLSERVERS != no && kill -HUP $KILLPIDS
380 echo "Using ldapadd to populate producer..."
381 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
384 if test $RC != 0 ; then
385 echo "ldapadd failed for producer database ($RC)!"
386 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
394 echo "Using ldapadd to populate consumer1..."
395 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
398 if test $RC != 0 ; then
399 echo "ldapadd failed for consumer1 database ($RC)!"
400 test $KILLSERVERS != no && kill -HUP $KILLPIDS
405 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
408 echo "Using ldapadd to populate consumer2..."
409 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
410 << EOMODS >> $TESTOUT 2>&1
411 dn: cn=Consumer 2 Test,dc=example,dc=com
417 if test $RC != 0 ; then
418 echo "ldapadd failed for consumer2 database ($RC)!"
419 test $KILLSERVERS != no && kill -HUP $KILLPIDS
424 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
427 echo "Using ldapmodify to add to the producer entries that will be deleted..."
428 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
429 >> $TESTOUT 2>&1 << EOADDS
430 dn: cn=To be deleted by producer,dc=example,dc=com
433 # no distinguished values, will be added by DSA
435 dn: cn=To be deleted by consumer1,dc=example,dc=com
438 # no distinguished values, will be added by DSA
440 dn: cn=To be deleted by consumer2,dc=example,dc=com
443 # no distinguished values, will be added by DSA
445 dn: cn=To be deleted by producer,dc=example,dc=com
449 if test $RC != 0 ; then
450 echo "ldapmodify failed for producer 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 consumer1..."
460 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
461 >> $TESTOUT 2>&1 << EOADDS
462 dn: cn=To be deleted by consumer1,dc=example,dc=com
466 if test $RC != 0 ; then
467 echo "ldapmodify failed for consumer1 database ($RC)!"
468 test $KILLSERVERS != no && kill -HUP $KILLPIDS
473 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
476 echo "Using ldapmodify to delete entries from consumer2..."
477 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
478 >> $TESTOUT 2>&1 << EOADDS
479 dn: cn=To be deleted by consumer2,dc=example,dc=com
483 if test $RC != 0 ; then
484 echo "ldapmodify failed for consumer2 database ($RC)!"
485 test $KILLSERVERS != no && kill -HUP $KILLPIDS
490 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
493 echo "Using ldapsearch to check that syncrepl received database changes..."
495 for i in 0 1 2 3 4 5; do
496 RESULT=`$LDAPSEARCH -H $URI2 \
497 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
498 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
499 if test "x$RESULT" = "xOK" ; then
503 echo "Waiting 5 seconds for syncrepl to receive changes..."
507 if test $RC != 0 ; then
508 echo "ldapsearch failed ($RC)!"
509 test $KILLSERVERS != no && kill -HUP $KILLPIDS
513 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
515 for i in 0 1 2 3 4 5; do
516 RESULT=`$LDAPSEARCH -H $URI3 \
517 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
518 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
519 if test "x$RESULT" = "xOK" ; then
523 echo "Waiting 5 seconds for syncrepl to receive changes..."
527 if test $RC != 0 ; then
528 echo "ldapsearch failed ($RC)!"
529 test $KILLSERVERS != no && kill -HUP $KILLPIDS
533 echo "Using ldapsearch to read config from the producer..."
534 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
535 'objectclass=*' > $MASTEROUT 2>&1
538 if test $RC != 0 ; then
539 echo "ldapsearch failed at producer ($RC)!"
540 test $KILLSERVERS != no && kill -HUP $KILLPIDS
544 echo "Using ldapsearch to read config from consumer1..."
545 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
546 'objectclass=*' > $SLAVEOUT 2>&1
549 if test $RC != 0 ; then
550 echo "ldapsearch failed at consumer1 ($RC)!"
551 test $KILLSERVERS != no && kill -HUP $KILLPIDS
555 echo "Using ldapsearch to read config from consumer2..."
556 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
557 'objectclass=*' > $SLAVE2OUT 2>&1
560 if test $RC != 0 ; then
561 echo "ldapsearch failed at consumer2 ($RC)!"
562 test $KILLSERVERS != no && kill -HUP $KILLPIDS
566 echo "Filtering producer results..."
567 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
568 echo "Filtering consumer1 results..."
569 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
570 echo "Filtering consumer2 results..."
571 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
573 echo "Comparing retrieved configs from producer and consumer1..."
574 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
576 if test $? != 0 ; then
577 echo "test failed - producer and consumer1 configs differ"
578 test $KILLSERVERS != no && kill -HUP $KILLPIDS
582 echo "Comparing retrieved configs from producer and consumer2..."
583 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
585 if test $? != 0 ; then
586 echo "test failed - producer and consumer2 configs differ"
587 test $KILLSERVERS != no && kill -HUP $KILLPIDS
591 echo "Using ldapsearch to read all the entries from the producer..."
592 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
593 'objectclass=*' > $MASTEROUT 2>&1
596 if test $RC != 0 ; then
597 echo "ldapsearch failed at producer ($RC)!"
598 test $KILLSERVERS != no && kill -HUP $KILLPIDS
602 echo "Using ldapsearch to read all the entries from consumer1..."
603 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
604 'objectclass=*' > $SLAVEOUT 2>&1
607 if test $RC != 0 ; then
608 echo "ldapsearch failed at consumer1 ($RC)!"
609 test $KILLSERVERS != no && kill -HUP $KILLPIDS
613 echo "Using ldapsearch to read all the entries from consumer2..."
614 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
615 'objectclass=*' > $SLAVE2OUT 2>&1
618 if test $RC != 0 ; then
619 echo "ldapsearch failed at consumer2 ($RC)!"
620 test $KILLSERVERS != no && kill -HUP $KILLPIDS
625 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
628 echo "Filtering producer results..."
629 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
630 echo "Filtering consumer1 results..."
631 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
632 echo "Filtering consumer2 results..."
633 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
635 echo "Comparing retrieved entries from producer and consumer1..."
636 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
638 if test $? != 0 ; then
639 echo "test failed - producer and consumer1 databases differ"
643 echo "Comparing retrieved entries from producer and consumer2..."
644 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
646 if test $? != 0 ; then
647 echo "test failed - producer and consumer2 databases differ"
652 # test $KILLSERVERS != no && wait
655 echo "Restarting servers..."
656 echo "Starting producer slapd on TCP/IP port $PORT1..."
658 echo "======================= RESTART =======================" >> $LOG1
659 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
661 if test $WAIT != 0 ; then
667 echo "Using ldapsearch to check that producer slapd is running..."
668 for i in 0 1 2 3 4 5; do
669 $LDAPSEARCH -s base -b "" -H $URI1 \
670 'objectclass=*' > /dev/null 2>&1
672 if test $RC = 0 ; then
675 echo "Waiting 5 seconds for slapd to start..."
679 if test $RC != 0 ; then
680 echo "ldapsearch failed ($RC)!"
681 test $KILLSERVERS != no && kill -HUP $KILLPIDS
685 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
687 echo "======================= RESTART =======================" >> $LOG2
688 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
690 if test $WAIT != 0 ; then
691 echo SLAVEPID $SLAVEPID
694 KILLPIDS="$KILLPIDS $SLAVEPID"
699 echo "Using ldapsearch to check that consumer1 slapd is running..."
700 for i in 0 1 2 3 4 5; do
701 $LDAPSEARCH -s base -b "" -H $URI2 \
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
717 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
719 echo "======================= RESTART =======================" >> $LOG3
720 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
722 if test $WAIT != 0 ; then
723 echo SLAVE2PID $SLAVE2PID
726 KILLPIDS="$KILLPIDS $SLAVE2PID"
731 echo "Using ldapsearch to check that consumer2 slapd is running..."
732 for i in 0 1 2 3 4 5; do
733 $LDAPSEARCH -s base -b "" -H $URI3 \
734 'objectclass=*' > /dev/null 2>&1
736 if test $RC = 0 ; then
739 echo "Waiting 5 seconds for slapd to start..."
743 if test $RC != 0 ; then
744 echo "ldapsearch failed ($RC)!"
745 test $KILLSERVERS != no && kill -HUP $KILLPIDS
749 # Insert modifications and more tests here.
751 echo "Waiting $SLEEP seconds for servers to resync..."
754 test $KILLSERVERS != no && kill -HUP $KILLPIDS
756 echo ">>>>> Test succeeded"
758 test $KILLSERVERS != no && wait