2 # $OpenLDAP: pkg/ldap/tests/scripts/test050-syncrepl-multimaster,v 1.3.2.8 2008/05/05 21:42:54 quanah Exp $
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
39 # Test replication of dynamic config:
43 # - configure over ldap
44 # - populate over ldap
45 # - configure syncrepl over ldap
46 # - retrieve database over ldap and compare against expected results
49 echo "Initializing server configurations..."
50 $SLAPADD -F $CFCON2 -n 0 <<EOF
52 objectClass: olcGlobal
56 dn: olcDatabase={0}config,cn=config
57 objectClass: olcDatabaseConfig
58 olcDatabase: {0}config
59 olcRootPW:< file://$CONFIGPWF
62 $SLAPADD -F $CFCON -n 0 <<EOF
64 objectClass: olcGlobal
68 dn: olcDatabase={0}config,cn=config
69 objectClass: olcDatabaseConfig
70 olcDatabase: {0}config
71 olcRootPW:< file://$CONFIGPWF
74 $SLAPADD -F $CFPRO -n 0 <<EOF
76 objectClass: olcGlobal
80 dn: olcDatabase={0}config,cn=config
81 objectClass: olcDatabaseConfig
82 olcDatabase: {0}config
83 olcRootPW:< file://$CONFIGPWF
86 echo "Starting producer slapd on TCP/IP port $PORT1..."
88 $SLAPD -F slapd.d
-h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
90 if test $WAIT != 0 ; then
99 echo "Using ldapsearch to check that producer slapd is running..."
100 for i
in 0 1 2 3 4 5; do
101 $LDAPSEARCH -s base
-b "" -H $URI1 \
102 'objectclass=*' > /dev
/null
2>&1
104 if test $RC = 0 ; then
107 echo "Waiting 5 seconds for slapd to start..."
111 if test $RC != 0 ; then
112 echo "ldapsearch failed ($RC)!"
113 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
117 echo "Inserting syncprov overlay on producer..."
118 if [ "$SYNCPROV" = syncprovmod
]; then
119 $LDAPADD -D cn
=config
-H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
120 dn: cn=module,cn=config
121 objectClass: olcModuleList
123 olcModulePath: ../../../servers/slapd/overlays
124 olcModuleLoad: syncprov.la
127 if test $RC != 0 ; then
128 echo "ldapadd failed for moduleLoad ($RC)!"
129 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
134 # Note that we configure a timeout here; it's possible for both
135 # servers to attempt to bind to each other while a modify to
136 # cn=config is in progress. When the modify pauses the thread pool
137 # neither server will progress. The timeout will drop the syncrepl
138 # attempt and allow the modifies to complete.
140 read CONFIGPW
< $CONFIGPWF
141 $LDAPMODIFY -D cn
=config
-H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
149 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
151 objectClass: olcOverlayConfig
152 objectClass: olcSyncProvConfig
155 dn: olcDatabase={0}config,cn=config
158 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
159 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
160 retry="5 5 300 5" timeout=3
161 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
162 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
163 retry="5 5 300 5" timeout=3
164 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
165 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
166 retry="5 5 300 5" timeout=3
172 if test $RC != 0 ; then
173 echo "ldapmodify failed for syncrepl config ($RC)!"
174 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
178 echo "Starting consumer slapd on TCP/IP port $PORT2..."
180 $SLAPD -F .
/slapd.d
-h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
182 if test $WAIT != 0 ; then
183 echo SLAVEPID
$SLAVEPID
186 KILLPIDS
="$KILLPIDS $SLAVEPID"
191 echo "Using ldapsearch to check that consumer slapd is running..."
192 for i
in 0 1 2 3 4 5; do
193 $LDAPSEARCH -s base
-b "" -H $URI2 \
194 'objectclass=*' > /dev
/null
2>&1
196 if test $RC = 0 ; then
199 echo "Waiting 5 seconds for slapd to start..."
203 if test $RC != 0 ; then
204 echo "ldapsearch failed ($RC)!"
205 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
209 echo "Configuring syncrepl on consumer..."
210 $LDAPMODIFY -D cn
=config
-H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
211 dn: olcDatabase={0}config,cn=config
214 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
215 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
216 retry="5 5 300 5" timeout=3
217 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
218 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
219 retry="5 5 300 5" timeout=3
220 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
221 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
222 retry="5 5 300 5" timeout=3
228 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
230 $SLAPD -F .
/slapd.d
-h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
232 if test $WAIT != 0 ; then
233 echo SLAVE2PID
$SLAVE2PID
236 KILLPIDS
="$KILLPIDS $SLAVE2PID"
241 echo "Using ldapsearch to check that consumer2 slapd is running..."
242 for i
in 0 1 2 3 4 5; do
243 $LDAPSEARCH -s base
-b "" -H $URI3 \
244 'objectclass=*' > /dev
/null
2>&1
246 if test $RC = 0 ; then
249 echo "Waiting 5 seconds for slapd to start..."
253 if test $RC != 0 ; then
254 echo "ldapsearch failed ($RC)!"
255 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
259 echo "Configuring syncrepl on consumer2..."
260 $LDAPMODIFY -D cn
=config
-H $URI3 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
261 dn: olcDatabase={0}config,cn=config
264 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
265 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
266 retry="5 5 300 5" timeout=3
267 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
268 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
269 retry="5 5 300 5" timeout=3
270 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
271 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
272 retry="5 5 300 5" timeout=3
278 echo "Adding schema and databases on producer..."
279 $LDAPADD -D cn
=config
-H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
280 include: file://$ABS_SCHEMADIR/core.ldif
282 include: file://$ABS_SCHEMADIR/cosine.ldif
284 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
286 include: file://$ABS_SCHEMADIR/openldap.ldif
288 include: file://$ABS_SCHEMADIR/nis.ldif
291 if test $RC != 0 ; then
292 echo "ldapadd failed for schema config ($RC)!"
293 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
297 if [ "$BACKENDTYPE" = mod
]; then
298 $LDAPADD -D cn
=config
-H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
299 dn: cn=module,cn=config
300 objectClass: olcModuleList
302 olcModulePath: ../../../servers/slapd/back-$BACKEND
303 olcModuleLoad: back_$BACKEND.la
306 if test $RC != 0 ; then
307 echo "ldapadd failed for backend config ($RC)!"
308 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
313 $LDAPADD -D cn
=config
-H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
314 dn: olcDatabase={1}$BACKEND,cn=config
315 objectClass: olcDatabaseConfig
316 objectClass: olc${BACKEND}Config
317 olcDatabase: {1}$BACKEND
320 olcRootDN: $MANAGERDN
322 olcSyncRepl: rid=004 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
323 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
324 interval=00:00:00:10 retry="5 5 300 5" timeout=3
325 olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
326 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
327 interval=00:00:00:10 retry="5 5 300 5" timeout=3
328 olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
329 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
330 interval=00:00:00:10 retry="5 5 300 5" timeout=3
333 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
335 objectClass: olcOverlayConfig
336 objectClass: olcSyncProvConfig
340 if test $RC != 0 ; then
341 echo "ldapadd failed for database config ($RC)!"
342 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
346 echo "Using ldapadd to populate producer..."
347 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
350 if test $RC != 0 ; then
351 echo "ldapadd failed for producer database ($RC)!"
352 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
357 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
360 echo "Using ldapadd to populate consumer..."
361 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
364 if test $RC != 0 ; then
365 echo "ldapadd failed for consumer database ($RC)!"
366 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
371 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
374 echo "Using ldapsearch to check that syncrepl received database changes..."
376 for i
in 0 1 2 3 4 5; do
377 RESULT
=`$LDAPSEARCH -H $URI2 \
378 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
379 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
380 if test "x$RESULT" = "xOK" ; then
384 echo "Waiting 5 seconds for syncrepl to receive changes..."
388 if test $RC != 0 ; then
389 echo "ldapsearch failed ($RC)!"
390 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
394 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
396 for i
in 0 1 2 3 4 5; do
397 RESULT
=`$LDAPSEARCH -H $URI3 \
398 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
399 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
400 if test "x$RESULT" = "xOK" ; then
404 echo "Waiting 5 seconds for syncrepl to receive changes..."
408 if test $RC != 0 ; then
409 echo "ldapsearch failed ($RC)!"
410 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
414 echo "Using ldapsearch to read config from the producer..."
415 $LDAPSEARCH -b cn
=config
-D cn
=config
-H $URI1 -y $CONFIGPWF \
416 'objectclass=*' > $MASTEROUT 2>&1
419 if test $RC != 0 ; then
420 echo "ldapsearch failed at producer ($RC)!"
421 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
425 echo "Using ldapsearch to read config from the consumer..."
426 $LDAPSEARCH -b cn
=config
-D cn
=config
-H $URI2 -y $CONFIGPWF \
427 'objectclass=*' > $SLAVEOUT 2>&1
430 if test $RC != 0 ; then
431 echo "ldapsearch failed at consumer ($RC)!"
432 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
436 echo "Using ldapsearch to read config from consumer2..."
437 $LDAPSEARCH -b cn
=config
-D cn
=config
-H $URI3 -y $CONFIGPWF \
438 'objectclass=*' > $SLAVE2OUT 2>&1
441 if test $RC != 0 ; then
442 echo "ldapsearch failed at consumer2 ($RC)!"
443 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
447 echo "Filtering producer results..."
448 .
$LDIFFILTER < $MASTEROUT > $MASTERFLT
449 echo "Filtering consumer results..."
450 .
$LDIFFILTER < $SLAVEOUT > $SLAVEFLT
451 echo "Filtering consumer2 results..."
452 .
$LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
454 echo "Comparing retrieved configs from producer and consumer..."
455 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
457 if test $?
!= 0 ; then
458 echo "test failed - producer and consumer configs differ"
459 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
463 echo "Comparing retrieved configs from producer and consumer2..."
464 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
466 if test $?
!= 0 ; then
467 echo "test failed - producer and consumer2 configs differ"
468 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
472 echo "Using ldapsearch to read all the entries from the producer..."
473 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
474 'objectclass=*' > $MASTEROUT 2>&1
477 if test $RC != 0 ; then
478 echo "ldapsearch failed at producer ($RC)!"
479 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
483 echo "Using ldapsearch to read all the entries from the consumer..."
484 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
485 'objectclass=*' > $SLAVEOUT 2>&1
488 if test $RC != 0 ; then
489 echo "ldapsearch failed at consumer ($RC)!"
490 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
494 echo "Using ldapsearch to read all the entries from the consumer2..."
495 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
496 'objectclass=*' > $SLAVE2OUT 2>&1
499 if test $RC != 0 ; then
500 echo "ldapsearch failed at consumer2 ($RC)!"
501 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
506 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
508 echo "Filtering producer results..."
509 .
$LDIFFILTER < $MASTEROUT > $MASTERFLT
510 echo "Filtering consumer results..."
511 .
$LDIFFILTER < $SLAVEOUT > $SLAVEFLT
512 echo "Filtering consumer2 results..."
513 .
$LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
515 echo "Comparing retrieved entries from producer and consumer..."
516 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
518 if test $?
!= 0 ; then
519 echo "test failed - producer and consumer databases differ"
523 echo "Comparing retrieved entries from producer and consumer2..."
524 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
526 if test $?
!= 0 ; then
527 echo "test failed - producer and consumer2 databases differ"
531 test $KILLSERVERS != no
&& wait
533 echo "Restarting servers..."
534 echo "Starting producer slapd on TCP/IP port $PORT1..."
536 echo "======================= RESTART =======================" >> $LOG1
537 $SLAPD -F .
/slapd.d
-h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
539 if test $WAIT != 0 ; then
545 echo "Using ldapsearch to check that producer slapd is running..."
546 for i
in 0 1 2 3 4 5; do
547 $LDAPSEARCH -s base
-b "" -H $URI1 \
548 'objectclass=*' > /dev
/null
2>&1
550 if test $RC = 0 ; then
553 echo "Waiting 5 seconds for slapd to start..."
557 if test $RC != 0 ; then
558 echo "ldapsearch failed ($RC)!"
559 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
563 echo "Starting consumer slapd on TCP/IP port $PORT2..."
565 echo "======================= RESTART =======================" >> $LOG2
566 $SLAPD -F .
/slapd.d
-h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
568 if test $WAIT != 0 ; then
569 echo SLAVEPID
$SLAVEPID
572 KILLPIDS
="$KILLPIDS $SLAVEPID"
577 echo "Using ldapsearch to check that consumer slapd is running..."
578 for i
in 0 1 2 3 4 5; do
579 $LDAPSEARCH -s base
-b "" -H $URI2 \
580 'objectclass=*' > /dev
/null
2>&1
582 if test $RC = 0 ; then
585 echo "Waiting 5 seconds for slapd to start..."
589 if test $RC != 0 ; then
590 echo "ldapsearch failed ($RC)!"
591 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
595 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
597 echo "======================= RESTART =======================" >> $LOG3
598 $SLAPD -F .
/slapd.d
-h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
600 if test $WAIT != 0 ; then
601 echo SLAVE2PID
$SLAVE2PID
604 KILLPIDS
="$KILLPIDS $SLAVE2PID"
609 echo "Using ldapsearch to check that consumer2 slapd is running..."
610 for i
in 0 1 2 3 4 5; do
611 $LDAPSEARCH -s base
-b "" -H $URI3 \
612 'objectclass=*' > /dev
/null
2>&1
614 if test $RC = 0 ; then
617 echo "Waiting 5 seconds for slapd to start..."
621 if test $RC != 0 ; then
622 echo "ldapsearch failed ($RC)!"
623 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
627 # Insert modifications and more tests here.
629 echo "Waiting $SLEEP seconds for servers to resync..."
632 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
634 echo ">>>>> Test succeeded"
636 test $KILLSERVERS != no
&& wait