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