]> git.sur5r.net Git - openldap/blob - tests/scripts/test050-syncrepl-multimaster
56f184d1bce2ecb2eaf942842be3c1981a4f578e
[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-2017 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 if test $INDEXDB = indexdb ; then
315         $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
316 dn: olcDatabase={1}$BACKEND,cn=config
317 changetype: modify
318 add: olcDbIndex
319 olcDbIndex: objectClass,entryUUID,entryCSN eq
320 olcDbIndex: cn,uid pres,eq,sub
321 EOF
322         RC=$?
323         if test $RC != 0 ; then
324                 echo "ldapadd modify for database config ($RC)!"
325                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
326                 exit $RC
327         fi
328 fi
329
330 echo "Using ldapadd to populate server 1..."
331 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
332         >> $TESTOUT 2>&1
333 RC=$?
334 if test $RC != 0 ; then
335         echo "ldapadd failed for server 1 database ($RC)!"
336         test $KILLSERVERS != no && kill -HUP $KILLPIDS
337         exit $RC
338 fi
339
340 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
341 sleep $SLEEP2
342
343 n=1
344 while [ $n -le $MMR ]; do
345 PORT=`expr $BASEPORT + $n`
346 URI="ldap://${LOCALHOST}:$PORT/"
347
348 echo "Using ldapsearch to read config from server $n..."
349 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF  \
350         'objectclass=*' > $TESTDIR/server$n.out 2>&1
351 RC=$?
352
353 if test $RC != 0 ; then
354         echo "ldapsearch failed at server $n ($RC)!"
355         test $KILLSERVERS != no && kill -HUP $KILLPIDS
356         exit $RC
357 fi
358
359 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
360
361 n=`expr $n + 1`
362 done
363
364 n=2
365 while [ $n -le $MMR ]; do
366 echo "Comparing retrieved configs from server 1 and server $n..."
367 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
368
369 if test $? != 0 ; then
370         echo "test failed - server 1 and server $n configs differ"
371         test $KILLSERVERS != no && kill -HUP $KILLPIDS
372         exit 1
373 fi
374 n=`expr $n + 1`
375 done
376
377 n=1
378 while [ $n -le $MMR ]; do
379 PORT=`expr $BASEPORT + $n`
380 URI="ldap://${LOCALHOST}:$PORT/"
381
382 echo "Using ldapsearch to read all the entries from server $n..."
383 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
384         'objectclass=*' > $TESTDIR/server$n.out 2>&1
385 RC=$?
386
387 if test $RC != 0 ; then
388         echo "ldapsearch failed at server $n ($RC)!"
389         test $KILLSERVERS != no && kill -HUP $KILLPIDS
390         exit $RC
391 fi
392 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
393 n=`expr $n + 1`
394 done
395
396 n=2
397 while [ $n -le $MMR ]; do
398 echo "Comparing retrieved entries from server 1 and server $n..."
399 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
400
401 if test $? != 0 ; then
402         echo "test failed - server 1 and server $n databases differ"
403         test $KILLSERVERS != no && kill -HUP $KILLPIDS
404         exit 1
405 fi
406 n=`expr $n + 1`
407 done
408
409 echo "Using ldapadd to populate server 2..."
410 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
411         >> $TESTOUT 2>&1
412 RC=$?
413 if test $RC != 0 ; then
414         echo "ldapadd failed for server 2 database ($RC)!"
415         test $KILLSERVERS != no && kill -HUP $KILLPIDS
416         exit $RC
417 fi
418
419 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
420 sleep $SLEEP1
421
422 n=1
423 while [ $n -le $MMR ]; do
424 PORT=`expr $BASEPORT + $n`
425 URI="ldap://${LOCALHOST}:$PORT/"
426
427 echo "Using ldapsearch to read all the entries from server $n..."
428 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
429         'objectclass=*' > $TESTDIR/server$n.out 2>&1
430 RC=$?
431
432 if test $RC != 0 ; then
433         echo "ldapsearch failed at server $n ($RC)!"
434         test $KILLSERVERS != no && kill -HUP $KILLPIDS
435         exit $RC
436 fi
437 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
438 n=`expr $n + 1`
439 done
440
441 n=2
442 while [ $n -le $MMR ]; do
443 echo "Comparing retrieved entries from server 1 and server $n..."
444 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
445
446 if test $? != 0 ; then
447         echo "test failed - server 1 and server $n databases differ"
448         test $KILLSERVERS != no && kill -HUP $KILLPIDS
449         exit 1
450 fi
451 n=`expr $n + 1`
452 done
453
454 echo "Using ldapadd to populate server 3..."
455 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
456         << EOMODS >> $TESTOUT 2>&1
457 dn: cn=Server 3 Test,dc=example,dc=com
458 changetype: add
459 objectClass: device
460 cn: Server 3 Test
461 EOMODS
462 RC=$?
463 if test $RC != 0 ; then
464         echo "ldapadd failed for server 3 database ($RC)!"
465         test $KILLSERVERS != no && kill -HUP $KILLPIDS
466         exit $RC
467 fi
468
469 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
470 sleep $SLEEP1
471
472 n=1
473 while [ $n -le $MMR ]; do
474 PORT=`expr $BASEPORT + $n`
475 URI="ldap://${LOCALHOST}:$PORT/"
476
477 echo "Using ldapsearch to read all the entries from server $n..."
478 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
479         'objectclass=*' > $TESTDIR/server$n.out 2>&1
480 RC=$?
481
482 if test $RC != 0 ; then
483         echo "ldapsearch failed at server $n ($RC)!"
484         test $KILLSERVERS != no && kill -HUP $KILLPIDS
485         exit $RC
486 fi
487 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
488 n=`expr $n + 1`
489 done
490
491 n=2
492 while [ $n -le $MMR ]; do
493 echo "Comparing retrieved entries from server 1 and server $n..."
494 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
495
496 if test $? != 0 ; then
497         echo "test failed - server 1 and server $n databases differ"
498         test $KILLSERVERS != no && kill -HUP $KILLPIDS
499         exit 1
500 fi
501 n=`expr $n + 1`
502 done
503
504 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
505 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
506         >> $TESTOUT 2>&1 << EOADDS
507 dn: cn=To be deleted by server 1,dc=example,dc=com
508 changetype: add
509 objectClass: device
510 # no distinguished values, will be added by DSA
511
512 dn: cn=To be deleted by server 2,dc=example,dc=com
513 changetype: add
514 objectClass: device
515 # no distinguished values, will be added by DSA
516
517 dn: cn=To be deleted by server 3,dc=example,dc=com
518 changetype: add
519 objectClass: device
520 # no distinguished values, will be added by DSA
521
522 dn: cn=To be deleted by server 1,dc=example,dc=com
523 changetype: delete
524 EOADDS
525 RC=$?
526 if test $RC != 0 ; then
527         echo "ldapmodify failed for server 1 database ($RC)!"
528         test $KILLSERVERS != no && kill -HUP $KILLPIDS
529         exit $RC
530 fi
531
532 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
533 sleep $SLEEP1
534
535 n=1
536 while [ $n -le $MMR ]; do
537 PORT=`expr $BASEPORT + $n`
538 URI="ldap://${LOCALHOST}:$PORT/"
539
540 echo "Using ldapsearch to read all the entries from server $n..."
541 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
542         'objectclass=*' > $TESTDIR/server$n.out 2>&1
543 RC=$?
544
545 if test $RC != 0 ; then
546         echo "ldapsearch failed at server $n ($RC)!"
547         test $KILLSERVERS != no && kill -HUP $KILLPIDS
548         exit $RC
549 fi
550 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
551 n=`expr $n + 1`
552 done
553
554 n=2
555 while [ $n -le $MMR ]; do
556 echo "Comparing retrieved entries from server 1 and server $n..."
557 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
558
559 if test $? != 0 ; then
560         echo "test failed - server 1 and server $n databases differ"
561         test $KILLSERVERS != no && kill -HUP $KILLPIDS
562         exit 1
563 fi
564 n=`expr $n + 1`
565 done
566
567 echo "Using ldapmodify to delete entries from server 2..."
568 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
569         >> $TESTOUT 2>&1 << EOADDS
570 dn: cn=To be deleted by server 2,dc=example,dc=com
571 changetype: delete
572 EOADDS
573 RC=$?
574 if test $RC != 0 ; then
575         echo "ldapmodify failed for server 2 database ($RC)!"
576         test $KILLSERVERS != no && kill -HUP $KILLPIDS
577         exit $RC
578 fi
579
580 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
581 sleep $SLEEP1
582
583 echo "Using ldapmodify to delete entries from server 3..."
584 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
585         >> $TESTOUT 2>&1 << EOADDS
586 dn: cn=To be deleted by server 3,dc=example,dc=com
587 changetype: delete
588 EOADDS
589 RC=$?
590 if test $RC != 0 ; then
591         echo "ldapmodify failed for server 3 database ($RC)!"
592         test $KILLSERVERS != no && kill -HUP $KILLPIDS
593         exit $RC
594 fi
595
596 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
597 sleep $SLEEP1
598
599 n=1
600 while [ $n -le $MMR ]; do
601 PORT=`expr $BASEPORT + $n`
602 URI="ldap://${LOCALHOST}:$PORT/"
603
604 echo "Using ldapsearch to read all the entries from server $n..."
605 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
606         'objectclass=*' > $TESTDIR/server$n.out 2>&1
607 RC=$?
608
609 if test $RC != 0 ; then
610         echo "ldapsearch failed at server $n ($RC)!"
611         test $KILLSERVERS != no && kill -HUP $KILLPIDS
612         exit $RC
613 fi
614 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
615 n=`expr $n + 1`
616 done
617
618 n=2
619 while [ $n -le $MMR ]; do
620 echo "Comparing retrieved entries from server 1 and server $n..."
621 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
622
623 if test $? != 0 ; then
624         echo "test failed - server 1 and server $n databases differ"
625         test $KILLSERVERS != no && kill -HUP $KILLPIDS
626         exit 1
627 fi
628 n=`expr $n + 1`
629 done
630
631 # kill!
632 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
633 kill -HUP $KILLPIDS
634
635 # kill!
636 # test $KILLSERVERS != no && wait
637 wait
638
639 echo "Restarting servers..."
640 KILLPIDS=""
641
642 echo "Starting server 1 on TCP/IP port $PORT1..."
643 echo "======================= RESTART =======================" >> $LOG1
644 cd ${XDIR}1
645 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
646 PID=$!
647 if test $WAIT != 0 ; then
648     echo PID $PID
649     read foo
650 fi
651 KILLPIDS="$PID"
652 cd $TESTWD
653
654 sleep 1
655
656 echo "Using ldapsearch to check that server 1 is running..."
657 for i in 0 1 2 3 4 5; do
658         $LDAPSEARCH -s base -b "" -H $URI1 \
659                 'objectclass=*' > /dev/null 2>&1
660         RC=$?
661         if test $RC = 0 ; then
662                 break
663         fi
664         echo "Waiting 5 seconds for slapd to start..."
665         sleep 5
666 done
667
668 if test $RC != 0 ; then
669         echo "ldapsearch failed ($RC)!"
670         test $KILLSERVERS != no && kill -HUP $KILLPIDS
671         exit $RC
672 fi
673
674 n=2
675 while [ $n -le $MMR ]; do
676 PORT=`expr $BASEPORT + $n`
677 URI="ldap://${LOCALHOST}:$PORT/"
678 LOG=$TESTDIR/slapd.$n.log
679 echo "Starting server $n on TCP/IP port $PORT..."
680 cd ${XDIR}$n
681 echo "======================= RESTART =======================" >> $LOG
682 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
683 PID=$!
684 if test $WAIT != 0 ; then
685     echo PID $PID
686     read foo
687 fi
688 KILLPIDS="$KILLPIDS $PID"
689 cd $TESTWD
690 n=`expr $n + 1`
691 done
692
693 n=2
694 while [ $n -le $MMR ]; do
695 PORT=`expr $BASEPORT + $n`
696 URI="ldap://${LOCALHOST}:$PORT/"
697 echo "Using ldapsearch to check that server $n is running..."
698 for i in 0 1 2 3 4 5; do
699         $LDAPSEARCH -s base -b "" -H $URI \
700                 'objectclass=*' > /dev/null 2>&1
701         RC=$?
702         if test $RC = 0 ; then
703                 break
704         fi
705         echo "Waiting 5 seconds for slapd to start..."
706         sleep 5
707 done
708
709 if test $RC != 0 ; then
710         echo "ldapsearch failed ($RC)!"
711         test $KILLSERVERS != no && kill -HUP $KILLPIDS
712         exit $RC
713 fi
714 n=`expr $n + 1`
715 done
716
717 # Insert modifications and more tests here.
718 echo "Waiting $SLEEP1 seconds for servers to resync..."
719 sleep $SLEEP1
720
721 echo "Using ldapmodify to add/modify/delete entries from server 1..."
722 for i in 1 2 3 4 5 6 7 8 9 10; do
723 echo "  iteration $i"
724 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
725         >> $TESTOUT 2>&1 << EOMODS
726 dn: cn=Add-Mod-Del,dc=example,dc=com
727 changetype: add
728 cn: Add-Mod-Del
729 objectclass: organizationalRole
730
731 dn: cn=Add-Mod-Del,dc=example,dc=com
732 changetype: modify
733 replace: description
734 description: guinea pig
735 -
736
737 dn: cn=Add-Mod-Del,dc=example,dc=com
738 changetype: delete
739 EOMODS
740 RC=$?
741 if test $RC != 0 ; then
742         echo "ldapmodify failed for server 1 database ($RC)!"
743         test $KILLSERVERS != no && kill -HUP $KILLPIDS
744         exit $RC
745 fi
746 done
747
748 echo "Waiting $SLEEP1 seconds for servers to resync..."
749 sleep $SLEEP1
750
751 n=1
752 while [ $n -le $MMR ]; do
753 PORT=`expr $BASEPORT + $n`
754 URI="ldap://${LOCALHOST}:$PORT/"
755
756 echo "Using ldapsearch to read all the entries from server $n..."
757 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
758         'objectclass=*' > $TESTDIR/server$n.out 2>&1
759 RC=$?
760
761 if test $RC != 0 ; then
762         echo "ldapsearch failed at server $n ($RC)!"
763         test $KILLSERVERS != no && kill -HUP $KILLPIDS
764         exit $RC
765 fi
766 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
767 n=`expr $n + 1`
768 done
769
770 n=2
771 while [ $n -le $MMR ]; do
772 echo "Comparing retrieved entries from server 1 and server $n..."
773 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
774
775 if test $? != 0 ; then
776         echo "test failed - server 1 and server $n databases differ"
777         test $KILLSERVERS != no && kill -HUP $KILLPIDS
778         exit 1
779 fi
780 n=`expr $n + 1`
781 done
782
783 test $KILLSERVERS != no && kill -HUP $KILLPIDS
784
785 echo ">>>>> Test succeeded"
786
787 test $KILLSERVERS != no && wait
788
789 exit 0