3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 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=1
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=1
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=1
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=1
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=1
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=1
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=1
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=1
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=1
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=1
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=1
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=1
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 database config ($RC)!"
352 test $KILLSERVERS != no && kill -HUP $KILLPIDS
357 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
360 echo "Using ldapsearch to check that syncrepl received database changes..."
362 for i in 0 1 2 3 4 5; do
363 RESULT=`$LDAPSEARCH -H $URI2 \
364 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
365 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
366 if test "x$RESULT" = "xOK" ; then
370 echo "Waiting 5 seconds for syncrepl to receive changes..."
374 if test $RC != 0 ; then
375 echo "ldapsearch failed ($RC)!"
376 test $KILLSERVERS != no && kill -HUP $KILLPIDS
380 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
382 for i in 0 1 2 3 4 5; do
383 RESULT=`$LDAPSEARCH -H $URI3 \
384 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
385 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
386 if test "x$RESULT" = "xOK" ; then
390 echo "Waiting 5 seconds for syncrepl to receive changes..."
394 if test $RC != 0 ; then
395 echo "ldapsearch failed ($RC)!"
396 test $KILLSERVERS != no && kill -HUP $KILLPIDS
400 echo "Using ldapsearch to read config from the producer..."
401 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
402 'objectclass=*' > $MASTEROUT 2>&1
405 if test $RC != 0 ; then
406 echo "ldapsearch failed at producer ($RC)!"
407 test $KILLSERVERS != no && kill -HUP $KILLPIDS
411 echo "Using ldapsearch to read config from the consumer..."
412 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
413 'objectclass=*' > $SLAVEOUT 2>&1
416 if test $RC != 0 ; then
417 echo "ldapsearch failed at consumer ($RC)!"
418 test $KILLSERVERS != no && kill -HUP $KILLPIDS
422 echo "Using ldapsearch to read config from consumer2..."
423 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
424 'objectclass=*' > $SLAVE2OUT 2>&1
427 if test $RC != 0 ; then
428 echo "ldapsearch failed at consumer2 ($RC)!"
429 test $KILLSERVERS != no && kill -HUP $KILLPIDS
433 echo "Filtering producer results..."
434 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
435 echo "Filtering consumer results..."
436 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
437 echo "Filtering consumer2 results..."
438 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
440 echo "Comparing retrieved configs from producer and consumer..."
441 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
443 if test $? != 0 ; then
444 echo "test failed - producer and consumer configs differ"
445 test $KILLSERVERS != no && kill -HUP $KILLPIDS
449 echo "Comparing retrieved configs from producer and consumer2..."
450 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
452 if test $? != 0 ; then
453 echo "test failed - producer and consumer2 configs differ"
454 test $KILLSERVERS != no && kill -HUP $KILLPIDS
458 echo "Using ldapsearch to read all the entries from the producer..."
459 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
460 'objectclass=*' > $MASTEROUT 2>&1
463 if test $RC != 0 ; then
464 echo "ldapsearch failed at producer ($RC)!"
465 test $KILLSERVERS != no && kill -HUP $KILLPIDS
469 echo "Using ldapsearch to read all the entries from the consumer..."
470 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
471 'objectclass=*' > $SLAVEOUT 2>&1
474 if test $RC != 0 ; then
475 echo "ldapsearch failed at consumer ($RC)!"
476 test $KILLSERVERS != no && kill -HUP $KILLPIDS
480 echo "Using ldapsearch to read all the entries from the consumer2..."
481 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD \
482 'objectclass=*' > $SLAVE2OUT 2>&1
485 if test $RC != 0 ; then
486 echo "ldapsearch failed at consumer2 ($RC)!"
487 test $KILLSERVERS != no && kill -HUP $KILLPIDS
492 test $KILLSERVERS != no && kill -HUP $KILLPIDS
494 echo "Filtering producer results..."
495 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
496 echo "Filtering consumer results..."
497 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
498 echo "Filtering consumer2 results..."
499 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
501 echo "Comparing retrieved entries from producer and consumer..."
502 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
504 if test $? != 0 ; then
505 echo "test failed - producer and consumer databases differ"
509 echo "Comparing retrieved entries from producer and consumer2..."
510 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
512 if test $? != 0 ; then
513 echo "test failed - producer and consumer2 databases differ"
517 test $KILLSERVERS != no && wait
519 echo "Restarting servers..."
520 echo "Starting producer slapd on TCP/IP port $PORT1..."
522 echo "======================= RESTART =======================" >> $LOG1
523 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
525 if test $WAIT != 0 ; then
531 echo "Using ldapsearch to check that producer slapd is running..."
532 for i in 0 1 2 3 4 5; do
533 $LDAPSEARCH -s base -b "" -H $URI1 \
534 'objectclass=*' > /dev/null 2>&1
536 if test $RC = 0 ; then
539 echo "Waiting 5 seconds for slapd to start..."
543 if test $RC != 0 ; then
544 echo "ldapsearch failed ($RC)!"
545 test $KILLSERVERS != no && kill -HUP $KILLPIDS
549 echo "Starting consumer slapd on TCP/IP port $PORT2..."
551 echo "======================= RESTART =======================" >> $LOG2
552 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
554 if test $WAIT != 0 ; then
555 echo SLAVEPID $SLAVEPID
558 KILLPIDS="$KILLPIDS $SLAVEPID"
563 echo "Using ldapsearch to check that consumer slapd is running..."
564 for i in 0 1 2 3 4 5; do
565 $LDAPSEARCH -s base -b "" -H $URI2 \
566 'objectclass=*' > /dev/null 2>&1
568 if test $RC = 0 ; then
571 echo "Waiting 5 seconds for slapd to start..."
575 if test $RC != 0 ; then
576 echo "ldapsearch failed ($RC)!"
577 test $KILLSERVERS != no && kill -HUP $KILLPIDS
581 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
583 echo "======================= RESTART =======================" >> $LOG3
584 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
586 if test $WAIT != 0 ; then
587 echo SLAVE2PID $SLAVE2PID
590 KILLPIDS="$KILLPIDS $SLAVE2PID"
595 echo "Using ldapsearch to check that consumer2 slapd is running..."
596 for i in 0 1 2 3 4 5; do
597 $LDAPSEARCH -s base -b "" -H $URI3 \
598 'objectclass=*' > /dev/null 2>&1
600 if test $RC = 0 ; then
603 echo "Waiting 5 seconds for slapd to start..."
607 if test $RC != 0 ; then
608 echo "ldapsearch failed ($RC)!"
609 test $KILLSERVERS != no && kill -HUP $KILLPIDS
613 # Insert modifications and more tests here.
615 echo "Waiting $SLEEP seconds for servers to resync..."
618 test $KILLSERVERS != no && kill -HUP $KILLPIDS
620 echo ">>>>> Test succeeded"
622 test $KILLSERVERS != no && wait