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:03"
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="3 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="3 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="3 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="3 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="3 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="3 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="3 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="3 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="3 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="3 5 300 5" timeout=3
341 olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
342 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
343 retry="3 5 300 5" timeout=3
344 olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
345 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
346 retry="3 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
390 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
393 echo "Using ldapadd to populate consumer1..."
394 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
397 if test $RC != 0 ; then
398 echo "ldapadd failed for consumer1 database ($RC)!"
399 test $KILLSERVERS != no && kill -HUP $KILLPIDS
403 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
406 echo "Using ldapadd to populate consumer2..."
407 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
408 << EOMODS >> $TESTOUT 2>&1
409 dn: cn=Consumer 2 Test,dc=example,dc=com
415 if test $RC != 0 ; then
416 echo "ldapadd failed for consumer2 database ($RC)!"
417 test $KILLSERVERS != no && kill -HUP $KILLPIDS
421 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
424 echo "Using ldapmodify to add to the producer entries that will be deleted..."
425 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
426 >> $TESTOUT 2>&1 << EOADDS
427 dn: cn=To be deleted by producer,dc=example,dc=com
430 # no distinguished values, will be added by DSA
432 dn: cn=To be deleted by consumer1,dc=example,dc=com
435 # no distinguished values, will be added by DSA
437 dn: cn=To be deleted by consumer2,dc=example,dc=com
440 # no distinguished values, will be added by DSA
442 dn: cn=To be deleted by producer,dc=example,dc=com
446 if test $RC != 0 ; then
447 echo "ldapmodify failed for producer database ($RC)!"
448 test $KILLSERVERS != no && kill -HUP $KILLPIDS
452 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
455 echo "Using ldapmodify to delete entries from consumer1..."
456 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
457 >> $TESTOUT 2>&1 << EOADDS
458 dn: cn=To be deleted by consumer1,dc=example,dc=com
462 if test $RC != 0 ; then
463 echo "ldapmodify failed for consumer2 database ($RC)!"
464 test $KILLSERVERS != no && kill -HUP $KILLPIDS
468 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
471 echo "Using ldapmodify to delete entries from consumer2..."
472 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
473 >> $TESTOUT 2>&1 << EOADDS
474 dn: cn=To be deleted by consumer2,dc=example,dc=com
478 if test $RC != 0 ; then
479 echo "ldapmodify failed for consumer2 database ($RC)!"
480 test $KILLSERVERS != no && kill -HUP $KILLPIDS
484 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
487 echo "Using ldapsearch to check that syncrepl received database changes..."
489 for i in 0 1 2 3 4 5; do
490 RESULT=`$LDAPSEARCH -H $URI2 \
491 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
492 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
493 if test "x$RESULT" = "xOK" ; then
497 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
501 if test $RC != 0 ; then
502 echo "ldapsearch failed ($RC)!"
503 test $KILLSERVERS != no && kill -HUP $KILLPIDS
507 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
509 for i in 0 1 2 3 4 5; do
510 RESULT=`$LDAPSEARCH -H $URI3 \
511 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
512 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
513 if test "x$RESULT" = "xOK" ; then
517 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
521 if test $RC != 0 ; then
522 echo "ldapsearch failed ($RC)!"
523 test $KILLSERVERS != no && kill -HUP $KILLPIDS
527 echo "Using ldapsearch to read config from the producer..."
528 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
529 'objectclass=*' > $MASTEROUT 2>&1
532 if test $RC != 0 ; then
533 echo "ldapsearch failed at producer ($RC)!"
534 test $KILLSERVERS != no && kill -HUP $KILLPIDS
538 echo "Using ldapsearch to read config from consumer1..."
539 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
540 'objectclass=*' > $SLAVEOUT 2>&1
543 if test $RC != 0 ; then
544 echo "ldapsearch failed at consumer1 ($RC)!"
545 test $KILLSERVERS != no && kill -HUP $KILLPIDS
549 echo "Using ldapsearch to read config from consumer2..."
550 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
551 'objectclass=*' > $SLAVE2OUT 2>&1
554 if test $RC != 0 ; then
555 echo "ldapsearch failed at consumer2 ($RC)!"
556 test $KILLSERVERS != no && kill -HUP $KILLPIDS
560 echo "Filtering producer results..."
561 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
562 echo "Filtering consumer1 results..."
563 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
564 echo "Filtering consumer2 results..."
565 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
567 echo "Comparing retrieved configs from producer and consumer1..."
568 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
570 if test $? != 0 ; then
571 echo "test failed - producer and consumer1 configs differ"
572 test $KILLSERVERS != no && kill -HUP $KILLPIDS
576 echo "Comparing retrieved configs from producer and consumer2..."
577 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
579 if test $? != 0 ; then
580 echo "test failed - producer and consumer2 configs differ"
581 test $KILLSERVERS != no && kill -HUP $KILLPIDS
585 echo "Using ldapsearch to read all the entries from the producer..."
586 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
587 'objectclass=*' > $MASTEROUT 2>&1
590 if test $RC != 0 ; then
591 echo "ldapsearch failed at producer ($RC)!"
592 test $KILLSERVERS != no && kill -HUP $KILLPIDS
596 echo "Using ldapsearch to read all the entries from consumer1..."
597 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
598 'objectclass=*' > $SLAVEOUT 2>&1
601 if test $RC != 0 ; then
602 echo "ldapsearch failed at consumer1 ($RC)!"
603 test $KILLSERVERS != no && kill -HUP $KILLPIDS
607 echo "Using ldapsearch to read all the entries from consumer2..."
608 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
609 'objectclass=*' > $SLAVE2OUT 2>&1
612 if test $RC != 0 ; then
613 echo "ldapsearch failed at consumer2 ($RC)!"
614 test $KILLSERVERS != no && kill -HUP $KILLPIDS
619 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
622 echo "Filtering producer results..."
623 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
624 echo "Filtering consumer1 results..."
625 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
626 echo "Filtering consumer2 results..."
627 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
629 echo "Comparing retrieved entries from producer and consumer1..."
630 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
632 if test $? != 0 ; then
633 echo "test failed - producer and consumer1 databases differ"
637 echo "Comparing retrieved entries from producer and consumer2..."
638 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
640 if test $? != 0 ; then
641 echo "test failed - producer and consumer2 databases differ"
646 # test $KILLSERVERS != no && wait
649 echo "Restarting servers..."
650 echo "Starting producer slapd on TCP/IP port $PORT1..."
652 echo "======================= RESTART =======================" >> $LOG1
653 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
655 if test $WAIT != 0 ; then
661 echo "Using ldapsearch to check that producer slapd is running..."
662 for i in 0 1 2 3 4 5; do
663 $LDAPSEARCH -s base -b "" -H $URI1 \
664 'objectclass=*' > /dev/null 2>&1
666 if test $RC = 0 ; then
669 echo "Waiting 5 seconds for slapd to start..."
673 if test $RC != 0 ; then
674 echo "ldapsearch failed ($RC)!"
675 test $KILLSERVERS != no && kill -HUP $KILLPIDS
679 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
681 echo "======================= RESTART =======================" >> $LOG2
682 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
684 if test $WAIT != 0 ; then
685 echo SLAVEPID $SLAVEPID
688 KILLPIDS="$KILLPIDS $SLAVEPID"
693 echo "Using ldapsearch to check that consumer1 slapd is running..."
694 for i in 0 1 2 3 4 5; do
695 $LDAPSEARCH -s base -b "" -H $URI2 \
696 'objectclass=*' > /dev/null 2>&1
698 if test $RC = 0 ; then
701 echo "Waiting 5 seconds for slapd to start..."
705 if test $RC != 0 ; then
706 echo "ldapsearch failed ($RC)!"
707 test $KILLSERVERS != no && kill -HUP $KILLPIDS
711 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
713 echo "======================= RESTART =======================" >> $LOG3
714 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
716 if test $WAIT != 0 ; then
717 echo SLAVE2PID $SLAVE2PID
720 KILLPIDS="$KILLPIDS $SLAVE2PID"
725 echo "Using ldapsearch to check that consumer2 slapd is running..."
726 for i in 0 1 2 3 4 5; do
727 $LDAPSEARCH -s base -b "" -H $URI3 \
728 'objectclass=*' > /dev/null 2>&1
730 if test $RC = 0 ; then
733 echo "Waiting 5 seconds for slapd to start..."
737 if test $RC != 0 ; then
738 echo "ldapsearch failed ($RC)!"
739 test $KILLSERVERS != no && kill -HUP $KILLPIDS
743 # Insert modifications and more tests here.
744 echo "Waiting $SLEEP1 seconds for servers to resync..."
747 test $KILLSERVERS != no && kill -HUP $KILLPIDS
749 echo ">>>>> Test succeeded"
751 test $KILLSERVERS != no && wait