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