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"
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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" $SYNCTYPE
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
362 echo "Using ldapadd to populate producer..."
363 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
366 if test $RC != 0 ; then
367 echo "ldapadd failed for producer database ($RC)!"
368 test $KILLSERVERS != no && kill -HUP $KILLPIDS
373 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
376 echo "Using ldapadd to populate consumer1..."
377 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
380 if test $RC != 0 ; then
381 echo "ldapadd failed for consumer1 database ($RC)!"
382 test $KILLSERVERS != no && kill -HUP $KILLPIDS
387 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
390 echo "Using ldapadd to populate consumer2..."
391 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
392 << EOMODS >> $TESTOUT 2>&1
393 dn: cn=Consumer 2 Test,dc=example,dc=com
399 if test $RC != 0 ; then
400 echo "ldapadd failed for consumer2 database ($RC)!"
401 test $KILLSERVERS != no && kill -HUP $KILLPIDS
406 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
409 echo "Using ldapmodify to add to the producer entries that will be deleted..."
410 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
411 >> $TESTOUT 2>&1 << EOADDS
412 dn: cn=To be deleted by producer,dc=example,dc=com
415 # no distinguished values, will be added by DSA
417 dn: cn=To be deleted by consumer1,dc=example,dc=com
420 # no distinguished values, will be added by DSA
422 dn: cn=To be deleted by consumer2,dc=example,dc=com
425 # no distinguished values, will be added by DSA
427 dn: cn=To be deleted by producer,dc=example,dc=com
431 if test $RC != 0 ; then
432 echo "ldapmodify failed for producer database ($RC)!"
433 test $KILLSERVERS != no && kill -HUP $KILLPIDS
438 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
441 echo "Using ldapmodify to delete entries from consumer1..."
442 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
443 >> $TESTOUT 2>&1 << EOADDS
444 dn: cn=To be deleted by consumer1,dc=example,dc=com
448 if test $RC != 0 ; then
449 echo "ldapmodify failed for consumer2 database ($RC)!"
450 test $KILLSERVERS != no && kill -HUP $KILLPIDS
455 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
458 echo "Using ldapmodify to delete entries from consumer2..."
459 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
460 >> $TESTOUT 2>&1 << EOADDS
461 dn: cn=To be deleted by consumer2,dc=example,dc=com
465 if test $RC != 0 ; then
466 echo "ldapmodify failed for consumer2 database ($RC)!"
467 test $KILLSERVERS != no && kill -HUP $KILLPIDS
472 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
475 echo "Using ldapsearch to check that syncrepl received database changes..."
477 for i in 0 1 2 3 4 5; do
478 RESULT=`$LDAPSEARCH -H $URI2 \
479 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
480 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
481 if test "x$RESULT" = "xOK" ; then
485 echo "Waiting 5 seconds for syncrepl to receive changes..."
489 if test $RC != 0 ; then
490 echo "ldapsearch failed ($RC)!"
491 test $KILLSERVERS != no && kill -HUP $KILLPIDS
495 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
497 for i in 0 1 2 3 4 5; do
498 RESULT=`$LDAPSEARCH -H $URI3 \
499 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
500 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
501 if test "x$RESULT" = "xOK" ; then
505 echo "Waiting 5 seconds for syncrepl to receive changes..."
509 if test $RC != 0 ; then
510 echo "ldapsearch failed ($RC)!"
511 test $KILLSERVERS != no && kill -HUP $KILLPIDS
515 echo "Using ldapsearch to read config from the producer..."
516 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
517 'objectclass=*' > $MASTEROUT 2>&1
520 if test $RC != 0 ; then
521 echo "ldapsearch failed at producer ($RC)!"
522 test $KILLSERVERS != no && kill -HUP $KILLPIDS
526 echo "Using ldapsearch to read config from consumer1..."
527 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
528 'objectclass=*' > $SLAVEOUT 2>&1
531 if test $RC != 0 ; then
532 echo "ldapsearch failed at consumer1 ($RC)!"
533 test $KILLSERVERS != no && kill -HUP $KILLPIDS
537 echo "Using ldapsearch to read config from consumer2..."
538 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
539 'objectclass=*' > $SLAVE2OUT 2>&1
542 if test $RC != 0 ; then
543 echo "ldapsearch failed at consumer2 ($RC)!"
544 test $KILLSERVERS != no && kill -HUP $KILLPIDS
548 echo "Filtering producer results..."
549 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
550 echo "Filtering consumer1 results..."
551 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
552 echo "Filtering consumer2 results..."
553 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
555 echo "Comparing retrieved configs from producer and consumer1..."
556 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
558 if test $? != 0 ; then
559 echo "test failed - producer and consumer1 configs differ"
560 test $KILLSERVERS != no && kill -HUP $KILLPIDS
564 echo "Comparing retrieved configs from producer and consumer2..."
565 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
567 if test $? != 0 ; then
568 echo "test failed - producer and consumer2 configs differ"
569 test $KILLSERVERS != no && kill -HUP $KILLPIDS
573 echo "Using ldapsearch to read all the entries from the producer..."
574 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
575 'objectclass=*' > $MASTEROUT 2>&1
578 if test $RC != 0 ; then
579 echo "ldapsearch failed at producer ($RC)!"
580 test $KILLSERVERS != no && kill -HUP $KILLPIDS
584 echo "Using ldapsearch to read all the entries from consumer1..."
585 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
586 'objectclass=*' > $SLAVEOUT 2>&1
589 if test $RC != 0 ; then
590 echo "ldapsearch failed at consumer1 ($RC)!"
591 test $KILLSERVERS != no && kill -HUP $KILLPIDS
595 echo "Using ldapsearch to read all the entries from consumer2..."
596 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
597 'objectclass=*' > $SLAVE2OUT 2>&1
600 if test $RC != 0 ; then
601 echo "ldapsearch failed at consumer2 ($RC)!"
602 test $KILLSERVERS != no && kill -HUP $KILLPIDS
607 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
610 echo "Filtering producer results..."
611 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
612 echo "Filtering consumer1 results..."
613 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
614 echo "Filtering consumer2 results..."
615 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
617 echo "Comparing retrieved entries from producer and consumer1..."
618 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
620 if test $? != 0 ; then
621 echo "test failed - producer and consumer1 databases differ"
625 echo "Comparing retrieved entries from producer and consumer2..."
626 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
628 if test $? != 0 ; then
629 echo "test failed - producer and consumer2 databases differ"
634 # test $KILLSERVERS != no && wait
637 echo "Restarting servers..."
638 echo "Starting producer slapd on TCP/IP port $PORT1..."
640 echo "======================= RESTART =======================" >> $LOG1
641 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
643 if test $WAIT != 0 ; then
649 echo "Using ldapsearch to check that producer slapd is running..."
650 for i in 0 1 2 3 4 5; do
651 $LDAPSEARCH -s base -b "" -H $URI1 \
652 'objectclass=*' > /dev/null 2>&1
654 if test $RC = 0 ; then
657 echo "Waiting 5 seconds for slapd to start..."
661 if test $RC != 0 ; then
662 echo "ldapsearch failed ($RC)!"
663 test $KILLSERVERS != no && kill -HUP $KILLPIDS
667 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
669 echo "======================= RESTART =======================" >> $LOG2
670 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
672 if test $WAIT != 0 ; then
673 echo SLAVEPID $SLAVEPID
676 KILLPIDS="$KILLPIDS $SLAVEPID"
681 echo "Using ldapsearch to check that consumer1 slapd is running..."
682 for i in 0 1 2 3 4 5; do
683 $LDAPSEARCH -s base -b "" -H $URI2 \
684 'objectclass=*' > /dev/null 2>&1
686 if test $RC = 0 ; then
689 echo "Waiting 5 seconds for slapd to start..."
693 if test $RC != 0 ; then
694 echo "ldapsearch failed ($RC)!"
695 test $KILLSERVERS != no && kill -HUP $KILLPIDS
699 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
701 echo "======================= RESTART =======================" >> $LOG3
702 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
704 if test $WAIT != 0 ; then
705 echo SLAVE2PID $SLAVE2PID
708 KILLPIDS="$KILLPIDS $SLAVE2PID"
713 echo "Using ldapsearch to check that consumer2 slapd is running..."
714 for i in 0 1 2 3 4 5; do
715 $LDAPSEARCH -s base -b "" -H $URI3 \
716 'objectclass=*' > /dev/null 2>&1
718 if test $RC = 0 ; then
721 echo "Waiting 5 seconds for slapd to start..."
725 if test $RC != 0 ; then
726 echo "ldapsearch failed ($RC)!"
727 test $KILLSERVERS != no && kill -HUP $KILLPIDS
731 # Insert modifications and more tests here.
733 echo "Waiting $SLEEP seconds for servers to resync..."
736 test $KILLSERVERS != no && kill -HUP $KILLPIDS
738 echo ">>>>> Test succeeded"
740 test $KILLSERVERS != no && wait