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 SYNCTYPE="type=refreshOnly interval=00:00:00:10"
35 #SYNCTYPE="type=refreshAndPersist"
37 mkdir -p $TESTDIR $PRODIR $CONDIR $CONDIR2 $DBPRO $DBCON $DBCON2 $CFPRO $CFCON $CFCON2
39 $SLAPPASSWD -g -n >$CONFIGPWF
42 # Test replication of dynamic config:
46 # - configure over ldap
47 # - populate over ldap
48 # - configure syncrepl over ldap
49 # - retrieve database over ldap and compare against expected results
52 echo "Initializing server configurations..."
53 $SLAPADD -F $CFCON2 -n 0 <<EOF
55 objectClass: olcGlobal
59 dn: olcDatabase={0}config,cn=config
60 objectClass: olcDatabaseConfig
61 olcDatabase: {0}config
62 olcRootPW:< file://$CONFIGPWF
65 $SLAPADD -F $CFCON -n 0 <<EOF
67 objectClass: olcGlobal
71 dn: olcDatabase={0}config,cn=config
72 objectClass: olcDatabaseConfig
73 olcDatabase: {0}config
74 olcRootPW:< file://$CONFIGPWF
77 $SLAPADD -F $CFPRO -n 0 <<EOF
79 objectClass: olcGlobal
83 dn: olcDatabase={0}config,cn=config
84 objectClass: olcDatabaseConfig
85 olcDatabase: {0}config
86 olcRootPW:< file://$CONFIGPWF
89 echo "Starting producer slapd on TCP/IP port $PORT1..."
91 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
93 if test $WAIT != 0 ; then
102 echo "Using ldapsearch to check that producer slapd is running..."
103 for i in 0 1 2 3 4 5; do
104 $LDAPSEARCH -s base -b "" -H $URI1 \
105 'objectclass=*' > /dev/null 2>&1
107 if test $RC = 0 ; then
110 echo "Waiting 5 seconds for slapd to start..."
114 if test $RC != 0 ; then
115 echo "ldapsearch failed ($RC)!"
116 test $KILLSERVERS != no && kill -HUP $KILLPIDS
120 echo "Inserting syncprov overlay on producer..."
121 if [ "$SYNCPROV" = syncprovmod ]; then
122 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
123 dn: cn=module,cn=config
124 objectClass: olcModuleList
126 olcModulePath: ../../../servers/slapd/overlays
127 olcModuleLoad: syncprov.la
130 if test $RC != 0 ; then
131 echo "ldapadd failed for moduleLoad ($RC)!"
132 test $KILLSERVERS != no && kill -HUP $KILLPIDS
137 # Note that we configure a timeout here; it's possible for both
138 # servers to attempt to bind to each other while a modify to
139 # cn=config is in progress. When the modify pauses the thread pool
140 # neither server will progress. The timeout will drop the syncrepl
141 # attempt and allow the modifies to complete.
143 read CONFIGPW < $CONFIGPWF
144 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
152 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
154 objectClass: olcOverlayConfig
155 objectClass: olcSyncProvConfig
158 dn: olcDatabase={0}config,cn=config
161 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
162 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
163 retry="5 5 300 5" timeout=3
164 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
165 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
166 retry="5 5 300 5" timeout=3
167 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
168 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
169 retry="5 5 300 5" timeout=3
175 if test $RC != 0 ; then
176 echo "ldapmodify failed for syncrepl config ($RC)!"
177 test $KILLSERVERS != no && kill -HUP $KILLPIDS
181 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
183 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
185 if test $WAIT != 0 ; then
186 echo SLAVEPID $SLAVEPID
189 KILLPIDS="$KILLPIDS $SLAVEPID"
194 echo "Using ldapsearch to check that consumer1 slapd is running..."
195 for i in 0 1 2 3 4 5; do
196 $LDAPSEARCH -s base -b "" -H $URI2 \
197 'objectclass=*' > /dev/null 2>&1
199 if test $RC = 0 ; then
202 echo "Waiting 5 seconds for slapd to start..."
206 if test $RC != 0 ; then
207 echo "ldapsearch failed ($RC)!"
208 test $KILLSERVERS != no && kill -HUP $KILLPIDS
212 echo "Configuring syncrepl on consumer1..."
213 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
214 dn: olcDatabase={0}config,cn=config
217 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
218 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
219 retry="5 5 300 5" timeout=3
220 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
221 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
222 retry="5 5 300 5" timeout=3
223 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
224 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
225 retry="5 5 300 5" timeout=3
231 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
233 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
235 if test $WAIT != 0 ; then
236 echo SLAVE2PID $SLAVE2PID
239 KILLPIDS="$KILLPIDS $SLAVE2PID"
244 echo "Using ldapsearch to check that consumer2 slapd is running..."
245 for i in 0 1 2 3 4 5; do
246 $LDAPSEARCH -s base -b "" -H $URI3 \
247 'objectclass=*' > /dev/null 2>&1
249 if test $RC = 0 ; then
252 echo "Waiting 5 seconds for slapd to start..."
256 if test $RC != 0 ; then
257 echo "ldapsearch failed ($RC)!"
258 test $KILLSERVERS != no && kill -HUP $KILLPIDS
262 echo "Configuring syncrepl on consumer2..."
263 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
264 dn: olcDatabase={0}config,cn=config
267 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
268 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
269 retry="5 5 300 5" timeout=3
270 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
271 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
272 retry="5 5 300 5" timeout=3
273 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
274 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
275 retry="5 5 300 5" timeout=3
281 echo "Adding schema and databases on producer..."
282 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
283 include: file://$ABS_SCHEMADIR/core.ldif
285 include: file://$ABS_SCHEMADIR/cosine.ldif
287 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
289 include: file://$ABS_SCHEMADIR/openldap.ldif
291 include: file://$ABS_SCHEMADIR/nis.ldif
294 if test $RC != 0 ; then
295 echo "ldapadd failed for schema config ($RC)!"
296 test $KILLSERVERS != no && kill -HUP $KILLPIDS
300 if [ "$BACKENDTYPE" = mod ]; then
301 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
302 dn: cn=module,cn=config
303 objectClass: olcModuleList
305 olcModulePath: ../../../servers/slapd/back-$BACKEND
306 olcModuleLoad: back_$BACKEND.la
309 if test $RC != 0 ; then
310 echo "ldapadd failed for backend config ($RC)!"
311 test $KILLSERVERS != no && kill -HUP $KILLPIDS
316 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
317 dn: olcDatabase={1}$BACKEND,cn=config
318 objectClass: olcDatabaseConfig
319 objectClass: olc${BACKEND}Config
320 olcDatabase: {1}$BACKEND
323 olcRootDN: $MANAGERDN
325 olcSyncRepl: rid=004 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
326 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
327 retry="5 5 300 5" timeout=3
328 olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
329 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
330 retry="5 5 300 5" timeout=3
331 olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
332 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
333 retry="5 5 300 5" timeout=3
336 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
338 objectClass: olcOverlayConfig
339 objectClass: olcSyncProvConfig
343 if test $RC != 0 ; then
344 echo "ldapadd failed for database config ($RC)!"
345 test $KILLSERVERS != no && kill -HUP $KILLPIDS
349 echo "Using ldapadd to populate producer..."
350 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
353 if test $RC != 0 ; then
354 echo "ldapadd failed for producer database ($RC)!"
355 test $KILLSERVERS != no && kill -HUP $KILLPIDS
360 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
363 echo "Using ldapadd to populate consumer1..."
364 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
367 if test $RC != 0 ; then
368 echo "ldapadd failed for consumer1 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 consumer2..."
378 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
379 << EOMODS >> $TESTOUT 2>&1
380 dn: cn=Consumer 2 Test,dc=example,dc=com
386 if test $RC != 0 ; then
387 echo "ldapadd failed for consumer2 database ($RC)!"
388 test $KILLSERVERS != no && kill -HUP $KILLPIDS
393 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
396 echo "Using ldapsearch to check that syncrepl received database changes..."
398 for i in 0 1 2 3 4 5; do
399 RESULT=`$LDAPSEARCH -H $URI2 \
400 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
401 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
402 if test "x$RESULT" = "xOK" ; then
406 echo "Waiting 5 seconds for syncrepl to receive changes..."
410 if test $RC != 0 ; then
411 echo "ldapsearch failed ($RC)!"
412 test $KILLSERVERS != no && kill -HUP $KILLPIDS
416 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
418 for i in 0 1 2 3 4 5; do
419 RESULT=`$LDAPSEARCH -H $URI3 \
420 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
421 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
422 if test "x$RESULT" = "xOK" ; then
426 echo "Waiting 5 seconds for syncrepl to receive changes..."
430 if test $RC != 0 ; then
431 echo "ldapsearch failed ($RC)!"
432 test $KILLSERVERS != no && kill -HUP $KILLPIDS
436 echo "Using ldapsearch to read config from the producer..."
437 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
438 'objectclass=*' > $MASTEROUT 2>&1
441 if test $RC != 0 ; then
442 echo "ldapsearch failed at producer ($RC)!"
443 test $KILLSERVERS != no && kill -HUP $KILLPIDS
447 echo "Using ldapsearch to read config from consumer1..."
448 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
449 'objectclass=*' > $SLAVEOUT 2>&1
452 if test $RC != 0 ; then
453 echo "ldapsearch failed at consumer1 ($RC)!"
454 test $KILLSERVERS != no && kill -HUP $KILLPIDS
458 echo "Using ldapsearch to read config from consumer2..."
459 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
460 'objectclass=*' > $SLAVE2OUT 2>&1
463 if test $RC != 0 ; then
464 echo "ldapsearch failed at consumer2 ($RC)!"
465 test $KILLSERVERS != no && kill -HUP $KILLPIDS
469 echo "Filtering producer results..."
470 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
471 echo "Filtering consumer1 results..."
472 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
473 echo "Filtering consumer2 results..."
474 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
476 echo "Comparing retrieved configs from producer and consumer1..."
477 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
479 if test $? != 0 ; then
480 echo "test failed - producer and consumer1 configs differ"
481 test $KILLSERVERS != no && kill -HUP $KILLPIDS
485 echo "Comparing retrieved configs from producer and consumer2..."
486 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
488 if test $? != 0 ; then
489 echo "test failed - producer and consumer2 configs differ"
490 test $KILLSERVERS != no && kill -HUP $KILLPIDS
494 echo "Using ldapsearch to read all the entries from the producer..."
495 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
496 'objectclass=*' > $MASTEROUT 2>&1
499 if test $RC != 0 ; then
500 echo "ldapsearch failed at producer ($RC)!"
501 test $KILLSERVERS != no && kill -HUP $KILLPIDS
505 echo "Using ldapsearch to read all the entries from consumer1..."
506 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
507 'objectclass=*' > $SLAVEOUT 2>&1
510 if test $RC != 0 ; then
511 echo "ldapsearch failed at consumer1 ($RC)!"
512 test $KILLSERVERS != no && kill -HUP $KILLPIDS
516 echo "Using ldapsearch to read all the entries from consumer2..."
517 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
518 'objectclass=*' > $SLAVE2OUT 2>&1
521 if test $RC != 0 ; then
522 echo "ldapsearch failed at consumer2 ($RC)!"
523 test $KILLSERVERS != no && kill -HUP $KILLPIDS
528 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
531 echo "Filtering producer results..."
532 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
533 echo "Filtering consumer1 results..."
534 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
535 echo "Filtering consumer2 results..."
536 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
538 echo "Comparing retrieved entries from producer and consumer1..."
539 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
541 if test $? != 0 ; then
542 echo "test failed - producer and consumer1 databases differ"
546 echo "Comparing retrieved entries from producer and consumer2..."
547 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
549 if test $? != 0 ; then
550 echo "test failed - producer and consumer2 databases differ"
555 # test $KILLSERVERS != no && wait
558 echo "Restarting servers..."
559 echo "Starting producer slapd on TCP/IP port $PORT1..."
561 echo "======================= RESTART =======================" >> $LOG1
562 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
564 if test $WAIT != 0 ; then
570 echo "Using ldapsearch to check that producer slapd is running..."
571 for i in 0 1 2 3 4 5; do
572 $LDAPSEARCH -s base -b "" -H $URI1 \
573 'objectclass=*' > /dev/null 2>&1
575 if test $RC = 0 ; then
578 echo "Waiting 5 seconds for slapd to start..."
582 if test $RC != 0 ; then
583 echo "ldapsearch failed ($RC)!"
584 test $KILLSERVERS != no && kill -HUP $KILLPIDS
588 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
590 echo "======================= RESTART =======================" >> $LOG2
591 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
593 if test $WAIT != 0 ; then
594 echo SLAVEPID $SLAVEPID
597 KILLPIDS="$KILLPIDS $SLAVEPID"
602 echo "Using ldapsearch to check that consumer1 slapd is running..."
603 for i in 0 1 2 3 4 5; do
604 $LDAPSEARCH -s base -b "" -H $URI2 \
605 'objectclass=*' > /dev/null 2>&1
607 if test $RC = 0 ; then
610 echo "Waiting 5 seconds for slapd to start..."
614 if test $RC != 0 ; then
615 echo "ldapsearch failed ($RC)!"
616 test $KILLSERVERS != no && kill -HUP $KILLPIDS
620 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
622 echo "======================= RESTART =======================" >> $LOG3
623 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
625 if test $WAIT != 0 ; then
626 echo SLAVE2PID $SLAVE2PID
629 KILLPIDS="$KILLPIDS $SLAVE2PID"
634 echo "Using ldapsearch to check that consumer2 slapd is running..."
635 for i in 0 1 2 3 4 5; do
636 $LDAPSEARCH -s base -b "" -H $URI3 \
637 'objectclass=*' > /dev/null 2>&1
639 if test $RC = 0 ; then
642 echo "Waiting 5 seconds for slapd to start..."
646 if test $RC != 0 ; then
647 echo "ldapsearch failed ($RC)!"
648 test $KILLSERVERS != no && kill -HUP $KILLPIDS
652 # Insert modifications and more tests here.
654 echo "Waiting $SLEEP seconds for servers to resync..."
657 test $KILLSERVERS != no && kill -HUP $KILLPIDS
659 echo ">>>>> Test succeeded"
661 test $KILLSERVERS != no && wait