]> git.sur5r.net Git - openldap/blob - tests/scripts/test050-syncrepl-multimaster
ITS#5810: Skip test for back-null
[openldap] / tests / scripts / test050-syncrepl-multimaster
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2009 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
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>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $SYNCPROV = syncprovno; then 
20         echo "Syncrepl provider overlay not available, test skipped"
21         exit 0
22 fi 
23
24 if test $BACKEND = null; then
25         echo "$BACKEND backend does not support cn=config, test skipped"
26         exit 0
27 fi
28
29 MMR=${MMR-4}
30
31 if [ $MMR -gt 9 ]; then
32 MMR=9
33 fi
34
35 XDIR=$TESTDIR/srv
36 TMP=$TESTDIR/tmp
37
38 mkdir -p $TESTDIR
39
40 $SLAPPASSWD -g -n >$CONFIGPWF
41
42 if test x"$SYNCMODE" = x ; then
43         SYNCMODE=rp
44 fi
45 case "$SYNCMODE" in
46         ro)
47                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
48                 ;;
49         rp)
50                 SYNCTYPE="type=refreshAndPersist"
51                 ;;
52         *)
53                 echo "unknown sync mode $SYNCMODE"
54                 exit 1;
55                 ;;
56 esac
57
58 #
59 # Test replication of dynamic config:
60 # - start servers
61 # - configure over ldap
62 # - populate over ldap
63 # - configure syncrepl over ldap
64 # - retrieve database over ldap and compare against expected results
65 #
66
67 echo "Initializing server configurations..."
68 n=1
69 while [ $n -le $MMR ]; do
70
71 DBDIR=${XDIR}$n/db
72 CFDIR=${XDIR}$n/slapd.d
73
74 mkdir -p ${XDIR}$n $DBDIR $CFDIR
75
76 $SLAPADD -F $CFDIR -n 0 <<EOF
77 dn: cn=config
78 objectClass: olcGlobal
79 cn: config
80 olcServerID: $n
81
82 dn: olcDatabase={0}config,cn=config
83 objectClass: olcDatabaseConfig
84 olcDatabase: {0}config
85 olcRootPW:< file://$CONFIGPWF
86 EOF
87
88 n=`expr $n + 1`
89 done
90
91 echo "Starting server 1 on TCP/IP port $PORT1..."
92 cd ${XDIR}1
93 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
94 PID=$!
95 if test $WAIT != 0 ; then
96     echo PID $PID
97     read foo
98 fi
99 KILLPIDS="$PID"
100 cd $TESTWD
101
102 sleep 1
103
104 echo "Using ldapsearch to check that server 1 is running..."
105 for i in 0 1 2 3 4 5; do
106         $LDAPSEARCH -s base -b "" -H $URI1 \
107                 'objectclass=*' > /dev/null 2>&1
108         RC=$?
109         if test $RC = 0 ; then
110                 break
111         fi
112         echo "Waiting 5 seconds for slapd to start..."
113         sleep 5
114 done
115
116 if test $RC != 0 ; then
117         echo "ldapsearch failed ($RC)!"
118         test $KILLSERVERS != no && kill -HUP $KILLPIDS
119         exit $RC
120 fi
121
122 echo "Inserting syncprov overlay on server 1..."
123 echo "" > $TMP
124 if [ "$SYNCPROV" = syncprovmod ]; then
125 cat <<EOF >> $TMP
126 dn: cn=module,cn=config
127 changetype: add
128 objectClass: olcModuleList
129 cn: module
130 olcModulePath: ../../../servers/slapd/overlays
131 olcModuleLoad: syncprov.la
132
133 EOF
134 fi
135 #
136 # Note that we configure a timeout here; it's possible for both
137 # servers to attempt to bind to each other while a modify to
138 # cn=config is in progress. When the modify pauses the thread pool
139 # neither server will progress. The timeout will drop the syncrepl
140 # attempt and allow the modifies to complete.
141 #
142 read CONFIGPW < $CONFIGPWF
143 echo "dn: cn=config" >> $TMP
144 echo "changetype: modify" >> $TMP
145 echo "replace: olcServerID" >> $TMP
146 n=1
147 while [ $n -le $MMR ]; do
148 PORT=`expr $BASEPORT + $n`
149 URI="ldap://${LOCALHOST}:$PORT/"
150 echo "olcServerID: $n $URI" >> $TMP
151 n=`expr $n + 1`
152 done
153
154 cat <<EOF >> $TMP
155
156 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
157 changetype: add
158 objectClass: olcOverlayConfig
159 objectClass: olcSyncProvConfig
160 olcOverlay: syncprov
161
162 dn: olcDatabase={0}config,cn=config
163 changetype: modify
164 add: olcSyncRepl
165 EOF
166
167 n=1
168 while [ $n -le $MMR ]; do
169 PORT=`expr $BASEPORT + $n`
170 URI="ldap://${LOCALHOST}:$PORT/"
171 echo "olcSyncRepl: rid=00$n provider=$URI binddn=\"cn=config\" bindmethod=simple" >> $TMP
172 echo "  credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
173 echo "  retry=\"3 10 300 5\" timeout=3" >> $TMP
174 n=`expr $n + 1`
175 done
176 echo "-" >> $TMP
177 echo "add: olcMirrorMode" >> $TMP
178 echo "olcMirrorMode: TRUE" >> $TMP
179 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >> $TESTOUT 2>&1
180 RC=$?
181 if test $RC != 0 ; then
182         echo "ldapmodify failed for syncrepl config ($RC)!"
183         test $KILLSERVERS != no && kill -HUP $KILLPIDS
184         exit $RC
185 fi
186
187 n=2
188 while [ $n -le $MMR ]; do
189 PORT=`expr $BASEPORT + $n`
190 URI="ldap://${LOCALHOST}:$PORT/"
191 LOG=$TESTDIR/slapd.$n.log
192 echo "Starting server $n on TCP/IP port $PORT..."
193 cd ${XDIR}$n
194 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING > $LOG 2>&1 &
195 SLAVEPID=$!
196 if test $WAIT != 0 ; then
197     echo SLAVEPID $SLAVEPID
198     read foo
199 fi
200 KILLPIDS="$KILLPIDS $SLAVEPID"
201 cd $TESTWD
202
203 sleep 1
204
205 echo "Using ldapsearch to check that server $n is running..."
206 for i in 0 1 2 3 4 5; do
207         $LDAPSEARCH -s base -b "" -H $URI \
208                 'objectclass=*' > /dev/null 2>&1
209         RC=$?
210         if test $RC = 0 ; then
211                 break
212         fi
213         echo "Waiting 5 seconds for slapd to start..."
214         sleep 5
215 done
216
217 if test $RC != 0 ; then
218         echo "ldapsearch failed ($RC)!"
219         test $KILLSERVERS != no && kill -HUP $KILLPIDS
220         exit $RC
221 fi
222
223 echo "Configuring syncrepl on server $n..."
224 cat <<EOF > $TMP
225 dn: olcDatabase={0}config,cn=config
226 changetype: modify
227 add: olcSyncRepl
228 EOF
229 j=1
230 while [ $j -le $MMR ]; do
231 P2=`expr $BASEPORT + $j`
232 U2="ldap://${LOCALHOST}:$P2/"
233 echo "olcSyncRepl: rid=00$j provider=$U2 binddn=\"cn=config\" bindmethod=simple" >> $TMP
234 echo "  credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
235 echo "  retry=\"3 10 300 5\" timeout=3" >> $TMP
236 j=`expr $j + 1`
237 done
238 cat <<EOF >> $TMP
239 -
240 add: olcMirrorMode
241 olcMirrorMode: TRUE
242 EOF
243 $LDAPMODIFY -D cn=config -H $URI -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
244 n=`expr $n + 1`
245 done
246
247 echo "Adding schema and databases on server 1..."
248 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
249 include: file://$ABS_SCHEMADIR/core.ldif
250
251 include: file://$ABS_SCHEMADIR/cosine.ldif
252
253 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
254
255 include: file://$ABS_SCHEMADIR/openldap.ldif
256
257 include: file://$ABS_SCHEMADIR/nis.ldif
258 EOF
259 RC=$?
260 if test $RC != 0 ; then
261         echo "ldapadd failed for schema config ($RC)!"
262         test $KILLSERVERS != no && kill -HUP $KILLPIDS
263         exit $RC
264 fi
265
266 echo "" > $TMP
267 if [ "$BACKENDTYPE" = mod ]; then
268 cat <<EOF >> $TMP
269 dn: cn=module,cn=config
270 objectClass: olcModuleList
271 cn: module
272 olcModulePath: ../../../servers/slapd/back-$BACKEND
273 olcModuleLoad: back_$BACKEND.la
274
275 EOF
276 fi
277
278 cat <<EOF >> $TMP
279 dn: olcDatabase={1}$BACKEND,cn=config
280 objectClass: olcDatabaseConfig
281 objectClass: olc${BACKEND}Config
282 olcDatabase: {1}$BACKEND
283 olcSuffix: $BASEDN
284 olcDbDirectory: ./db
285 olcRootDN: $MANAGERDN
286 olcRootPW: $PASSWD
287 EOF
288
289 n=1
290 while [ $n -le $MMR ]; do
291 PORT=`expr $BASEPORT + $n`
292 URI="ldap://${LOCALHOST}:$PORT/"
293
294 echo "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP
295 echo "  credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP
296 echo "  retry=\"3 10 300 5\" timeout=3" >> $TMP
297 n=`expr $n + 1`
298 done
299
300 cat <<EOF >> $TMP
301 olcMirrorMode: TRUE
302
303 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
304 objectClass: olcOverlayConfig
305 objectClass: olcSyncProvConfig
306 olcOverlay: syncprov
307 EOF
308 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
309 RC=$?
310 if test $RC != 0 ; then
311         echo "ldapadd failed for database config ($RC)!"
312         test $KILLSERVERS != no && kill -HUP $KILLPIDS
313         exit $RC
314 fi
315
316 case $BACKEND in
317 bdb | hdb)
318         $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
319 dn: olcDatabase={1}$BACKEND,cn=config
320 changetype: modify
321 add: olcDbIndex
322 olcDbIndex: objectClass,entryUUID,entryCSN eq
323 olcDbIndex: cn,uid pres,eq,sub
324 EOF
325         RC=$?
326         if test $RC != 0 ; then
327                 echo "ldapadd modify for database config ($RC)!"
328                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329                 exit $RC
330         fi
331         ;;
332 esac
333
334 echo "Using ldapadd to populate server 1..."
335 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
336         >> $TESTOUT 2>&1
337 RC=$?
338 if test $RC != 0 ; then
339         echo "ldapadd failed for server 1 database ($RC)!"
340         test $KILLSERVERS != no && kill -HUP $KILLPIDS
341         exit $RC
342 fi
343
344 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
345 sleep $SLEEP2
346
347 n=1
348 while [ $n -le $MMR ]; do
349 PORT=`expr $BASEPORT + $n`
350 URI="ldap://${LOCALHOST}:$PORT/"
351
352 echo "Using ldapsearch to read config from server $n..."
353 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF  \
354         'objectclass=*' > $TESTDIR/server$n.out 2>&1
355 RC=$?
356
357 if test $RC != 0 ; then
358         echo "ldapsearch failed at server $n ($RC)!"
359         test $KILLSERVERS != no && kill -HUP $KILLPIDS
360         exit $RC
361 fi
362
363 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
364
365 n=`expr $n + 1`
366 done
367
368 n=2
369 while [ $n -le $MMR ]; do
370 echo "Comparing retrieved configs from server 1 and server $n..."
371 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
372
373 if test $? != 0 ; then
374         echo "test failed - server 1 and server $n configs differ"
375         test $KILLSERVERS != no && kill -HUP $KILLPIDS
376         exit 1
377 fi
378 n=`expr $n + 1`
379 done
380
381 n=1
382 while [ $n -le $MMR ]; do
383 PORT=`expr $BASEPORT + $n`
384 URI="ldap://${LOCALHOST}:$PORT/"
385
386 echo "Using ldapsearch to read all the entries from server $n..."
387 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
388         'objectclass=*' > $TESTDIR/server$n.out 2>&1
389 RC=$?
390
391 if test $RC != 0 ; then
392         echo "ldapsearch failed at server $n ($RC)!"
393         test $KILLSERVERS != no && kill -HUP $KILLPIDS
394         exit $RC
395 fi
396 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
397 n=`expr $n + 1`
398 done
399
400 n=2
401 while [ $n -le $MMR ]; do
402 echo "Comparing retrieved entries from server 1 and server $n..."
403 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
404
405 if test $? != 0 ; then
406         echo "test failed - server 1 and server $n databases differ"
407         test $KILLSERVERS != no && kill -HUP $KILLPIDS
408         exit 1
409 fi
410 n=`expr $n + 1`
411 done
412
413 echo "Using ldapadd to populate server 2..."
414 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
415         >> $TESTOUT 2>&1
416 RC=$?
417 if test $RC != 0 ; then
418         echo "ldapadd failed for server 2 database ($RC)!"
419         test $KILLSERVERS != no && kill -HUP $KILLPIDS
420         exit $RC
421 fi
422
423 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
424 sleep $SLEEP1
425
426 n=1
427 while [ $n -le $MMR ]; do
428 PORT=`expr $BASEPORT + $n`
429 URI="ldap://${LOCALHOST}:$PORT/"
430
431 echo "Using ldapsearch to read all the entries from server $n..."
432 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
433         'objectclass=*' > $TESTDIR/server$n.out 2>&1
434 RC=$?
435
436 if test $RC != 0 ; then
437         echo "ldapsearch failed at server $n ($RC)!"
438         test $KILLSERVERS != no && kill -HUP $KILLPIDS
439         exit $RC
440 fi
441 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
442 n=`expr $n + 1`
443 done
444
445 n=2
446 while [ $n -le $MMR ]; do
447 echo "Comparing retrieved entries from server 1 and server $n..."
448 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
449
450 if test $? != 0 ; then
451         echo "test failed - server 1 and server $n databases differ"
452         test $KILLSERVERS != no && kill -HUP $KILLPIDS
453         exit 1
454 fi
455 n=`expr $n + 1`
456 done
457
458 echo "Using ldapadd to populate server 3..."
459 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
460         << EOMODS >> $TESTOUT 2>&1
461 dn: cn=Server 3 Test,dc=example,dc=com
462 changetype: add
463 objectClass: device
464 cn: Server 3 Test
465 EOMODS
466 RC=$?
467 if test $RC != 0 ; then
468         echo "ldapadd failed for server 3 database ($RC)!"
469         test $KILLSERVERS != no && kill -HUP $KILLPIDS
470         exit $RC
471 fi
472
473 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
474 sleep $SLEEP1
475
476 n=1
477 while [ $n -le $MMR ]; do
478 PORT=`expr $BASEPORT + $n`
479 URI="ldap://${LOCALHOST}:$PORT/"
480
481 echo "Using ldapsearch to read all the entries from server $n..."
482 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
483         'objectclass=*' > $TESTDIR/server$n.out 2>&1
484 RC=$?
485
486 if test $RC != 0 ; then
487         echo "ldapsearch failed at server $n ($RC)!"
488         test $KILLSERVERS != no && kill -HUP $KILLPIDS
489         exit $RC
490 fi
491 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
492 n=`expr $n + 1`
493 done
494
495 n=2
496 while [ $n -le $MMR ]; do
497 echo "Comparing retrieved entries from server 1 and server $n..."
498 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
499
500 if test $? != 0 ; then
501         echo "test failed - server 1 and server $n databases differ"
502         test $KILLSERVERS != no && kill -HUP $KILLPIDS
503         exit 1
504 fi
505 n=`expr $n + 1`
506 done
507
508 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
509 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
510         >> $TESTOUT 2>&1 << EOADDS
511 dn: cn=To be deleted by server 1,dc=example,dc=com
512 changetype: add
513 objectClass: device
514 # no distinguished values, will be added by DSA
515
516 dn: cn=To be deleted by server 2,dc=example,dc=com
517 changetype: add
518 objectClass: device
519 # no distinguished values, will be added by DSA
520
521 dn: cn=To be deleted by server 3,dc=example,dc=com
522 changetype: add
523 objectClass: device
524 # no distinguished values, will be added by DSA
525
526 dn: cn=To be deleted by server 1,dc=example,dc=com
527 changetype: delete
528 EOADDS
529 RC=$?
530 if test $RC != 0 ; then
531         echo "ldapmodify failed for server 1 database ($RC)!"
532         test $KILLSERVERS != no && kill -HUP $KILLPIDS
533         exit $RC
534 fi
535
536 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
537 sleep $SLEEP1
538
539 n=1
540 while [ $n -le $MMR ]; do
541 PORT=`expr $BASEPORT + $n`
542 URI="ldap://${LOCALHOST}:$PORT/"
543
544 echo "Using ldapsearch to read all the entries from server $n..."
545 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
546         'objectclass=*' > $TESTDIR/server$n.out 2>&1
547 RC=$?
548
549 if test $RC != 0 ; then
550         echo "ldapsearch failed at server $n ($RC)!"
551         test $KILLSERVERS != no && kill -HUP $KILLPIDS
552         exit $RC
553 fi
554 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
555 n=`expr $n + 1`
556 done
557
558 n=2
559 while [ $n -le $MMR ]; do
560 echo "Comparing retrieved entries from server 1 and server $n..."
561 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
562
563 if test $? != 0 ; then
564         echo "test failed - server 1 and server $n databases differ"
565         test $KILLSERVERS != no && kill -HUP $KILLPIDS
566         exit 1
567 fi
568 n=`expr $n + 1`
569 done
570
571 echo "Using ldapmodify to delete entries from server 2..."
572 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
573         >> $TESTOUT 2>&1 << EOADDS
574 dn: cn=To be deleted by server 2,dc=example,dc=com
575 changetype: delete
576 EOADDS
577 RC=$?
578 if test $RC != 0 ; then
579         echo "ldapmodify failed for server 2 database ($RC)!"
580         test $KILLSERVERS != no && kill -HUP $KILLPIDS
581         exit $RC
582 fi
583
584 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
585 sleep $SLEEP1
586
587 echo "Using ldapmodify to delete entries from server 3..."
588 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
589         >> $TESTOUT 2>&1 << EOADDS
590 dn: cn=To be deleted by server 3,dc=example,dc=com
591 changetype: delete
592 EOADDS
593 RC=$?
594 if test $RC != 0 ; then
595         echo "ldapmodify failed for server 3 database ($RC)!"
596         test $KILLSERVERS != no && kill -HUP $KILLPIDS
597         exit $RC
598 fi
599
600 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
601 sleep $SLEEP1
602
603 n=1
604 while [ $n -le $MMR ]; do
605 PORT=`expr $BASEPORT + $n`
606 URI="ldap://${LOCALHOST}:$PORT/"
607
608 echo "Using ldapsearch to read all the entries from server $n..."
609 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
610         'objectclass=*' > $TESTDIR/server$n.out 2>&1
611 RC=$?
612
613 if test $RC != 0 ; then
614         echo "ldapsearch failed at server $n ($RC)!"
615         test $KILLSERVERS != no && kill -HUP $KILLPIDS
616         exit $RC
617 fi
618 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
619 n=`expr $n + 1`
620 done
621
622 n=2
623 while [ $n -le $MMR ]; do
624 echo "Comparing retrieved entries from server 1 and server $n..."
625 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
626
627 if test $? != 0 ; then
628         echo "test failed - server 1 and server $n databases differ"
629         test $KILLSERVERS != no && kill -HUP $KILLPIDS
630         exit 1
631 fi
632 n=`expr $n + 1`
633 done
634
635 # kill!
636 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
637 kill -HUP $KILLPIDS
638
639 # kill!
640 # test $KILLSERVERS != no && wait
641 wait
642
643 echo "Restarting servers..."
644 KILLPIDS=""
645
646 echo "Starting server 1 on TCP/IP port $PORT1..."
647 echo "======================= RESTART =======================" >> $LOG1
648 cd ${XDIR}1
649 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
650 PID=$!
651 if test $WAIT != 0 ; then
652     echo PID $PID
653     read foo
654 fi
655 KILLPIDS="$PID"
656 cd $TESTWD
657
658 sleep 1
659
660 echo "Using ldapsearch to check that server 1 is running..."
661 for i in 0 1 2 3 4 5; do
662         $LDAPSEARCH -s base -b "" -H $URI1 \
663                 'objectclass=*' > /dev/null 2>&1
664         RC=$?
665         if test $RC = 0 ; then
666                 break
667         fi
668         echo "Waiting 5 seconds for slapd to start..."
669         sleep 5
670 done
671
672 if test $RC != 0 ; then
673         echo "ldapsearch failed ($RC)!"
674         test $KILLSERVERS != no && kill -HUP $KILLPIDS
675         exit $RC
676 fi
677
678 n=2
679 while [ $n -le $MMR ]; do
680 PORT=`expr $BASEPORT + $n`
681 URI="ldap://${LOCALHOST}:$PORT/"
682 LOG=$TESTDIR/slapd.$n.log
683 echo "Starting server $n on TCP/IP port $PORT..."
684 cd ${XDIR}$n
685 echo "======================= RESTART =======================" >> $LOG
686 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
687 PID=$!
688 if test $WAIT != 0 ; then
689     echo PID $PID
690     read foo
691 fi
692 KILLPIDS="$KILLPIDS $PID"
693 cd $TESTWD
694 n=`expr $n + 1`
695 done
696
697 n=2
698 while [ $n -le $MMR ]; do
699 PORT=`expr $BASEPORT + $n`
700 URI="ldap://${LOCALHOST}:$PORT/"
701 echo "Using ldapsearch to check that server $n is running..."
702 for i in 0 1 2 3 4 5; do
703         $LDAPSEARCH -s base -b "" -H $URI \
704                 'objectclass=*' > /dev/null 2>&1
705         RC=$?
706         if test $RC = 0 ; then
707                 break
708         fi
709         echo "Waiting 5 seconds for slapd to start..."
710         sleep 5
711 done
712
713 if test $RC != 0 ; then
714         echo "ldapsearch failed ($RC)!"
715         test $KILLSERVERS != no && kill -HUP $KILLPIDS
716         exit $RC
717 fi
718 n=`expr $n + 1`
719 done
720
721 # Insert modifications and more tests here.
722 echo "Waiting $SLEEP1 seconds for servers to resync..."
723 sleep $SLEEP1
724
725 echo "Using ldapmodify to add/modify/delete entries from server 1..."
726 for i in 1 2 3 4 5 6 7 8 9 10; do
727 echo "  iteration $i"
728 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
729         >> $TESTOUT 2>&1 << EOMODS
730 dn: cn=Add-Mod-Del,dc=example,dc=com
731 changetype: add
732 cn: Add-Mod-Del
733 objectclass: organizationalRole
734
735 dn: cn=Add-Mod-Del,dc=example,dc=com
736 changetype: modify
737 replace: description
738 description: guinea pig
739 -
740
741 dn: cn=Add-Mod-Del,dc=example,dc=com
742 changetype: delete
743 EOMODS
744 RC=$?
745 if test $RC != 0 ; then
746         echo "ldapmodify failed for server 1 database ($RC)!"
747         test $KILLSERVERS != no && kill -HUP $KILLPIDS
748         exit $RC
749 fi
750 done
751
752 echo "Waiting $SLEEP1 seconds for servers to resync..."
753 sleep $SLEEP1
754
755 n=1
756 while [ $n -le $MMR ]; do
757 PORT=`expr $BASEPORT + $n`
758 URI="ldap://${LOCALHOST}:$PORT/"
759
760 echo "Using ldapsearch to read all the entries from server $n..."
761 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
762         'objectclass=*' > $TESTDIR/server$n.out 2>&1
763 RC=$?
764
765 if test $RC != 0 ; then
766         echo "ldapsearch failed at server $n ($RC)!"
767         test $KILLSERVERS != no && kill -HUP $KILLPIDS
768         exit $RC
769 fi
770 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
771 n=`expr $n + 1`
772 done
773
774 n=2
775 while [ $n -le $MMR ]; do
776 echo "Comparing retrieved entries from server 1 and server $n..."
777 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
778
779 if test $? != 0 ; then
780         echo "test failed - server 1 and server $n databases differ"
781         test $KILLSERVERS != no && kill -HUP $KILLPIDS
782         exit 1
783 fi
784 n=`expr $n + 1`
785 done
786
787 test $KILLSERVERS != no && kill -HUP $KILLPIDS
788
789 echo ">>>>> Test succeeded"
790
791 test $KILLSERVERS != no && wait
792
793 exit 0