]> git.sur5r.net Git - openldap/blob - tests/scripts/test050-syncrepl-multimaster
add indexes when supported; syncrepl on configuration should always be refreshAndPersist
[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-2008 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/con
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:10"
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="5 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="5 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="5 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="5 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="5 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="5 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="5 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="5 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="5 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="5 5 300 5" timeout=3
341 olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
342   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
343   retry="5 5 300 5" timeout=3
344 olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
345   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
346   retry="5 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 SLEEP=20
391 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
392 sleep $SLEEP
393
394 echo "Using ldapadd to populate consumer1..."
395 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
396         >> $TESTOUT 2>&1
397 RC=$?
398 if test $RC != 0 ; then
399         echo "ldapadd failed for consumer1 database ($RC)!"
400         test $KILLSERVERS != no && kill -HUP $KILLPIDS
401         exit $RC
402 fi
403
404 SLEEP=20
405 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
406 sleep $SLEEP
407
408 echo "Using ldapadd to populate consumer2..."
409 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
410         << EOMODS >> $TESTOUT 2>&1
411 dn: cn=Consumer 2 Test,dc=example,dc=com
412 changetype: add
413 objectClass: device
414 cn: Consumer 2 Test
415 EOMODS
416 RC=$?
417 if test $RC != 0 ; then
418         echo "ldapadd failed for consumer2 database ($RC)!"
419         test $KILLSERVERS != no && kill -HUP $KILLPIDS
420         exit $RC
421 fi
422
423 SLEEP=20
424 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
425 sleep $SLEEP
426
427 echo "Using ldapmodify to add to the producer entries that will be deleted..."
428 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
429         >> $TESTOUT 2>&1 << EOADDS
430 dn: cn=To be deleted by producer,dc=example,dc=com
431 changetype: add
432 objectClass: device
433 # no distinguished values, will be added by DSA
434
435 dn: cn=To be deleted by consumer1,dc=example,dc=com
436 changetype: add
437 objectClass: device
438 # no distinguished values, will be added by DSA
439
440 dn: cn=To be deleted by consumer2,dc=example,dc=com
441 changetype: add
442 objectClass: device
443 # no distinguished values, will be added by DSA
444
445 dn: cn=To be deleted by producer,dc=example,dc=com
446 changetype: delete
447 EOADDS
448 RC=$?
449 if test $RC != 0 ; then
450         echo "ldapmodify failed for producer database ($RC)!"
451         test $KILLSERVERS != no && kill -HUP $KILLPIDS
452         exit $RC
453 fi
454
455 SLEEP=20
456 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
457 sleep $SLEEP
458
459 echo "Using ldapmodify to delete entries from consumer1..."
460 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
461         >> $TESTOUT 2>&1 << EOADDS
462 dn: cn=To be deleted by consumer1,dc=example,dc=com
463 changetype: delete
464 EOADDS
465 RC=$?
466 if test $RC != 0 ; then
467         echo "ldapmodify failed for consumer2 database ($RC)!"
468         test $KILLSERVERS != no && kill -HUP $KILLPIDS
469         exit $RC
470 fi
471
472 SLEEP=20
473 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
474 sleep $SLEEP
475
476 echo "Using ldapmodify to delete entries from consumer2..."
477 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
478         >> $TESTOUT 2>&1 << EOADDS
479 dn: cn=To be deleted by consumer2,dc=example,dc=com
480 changetype: delete
481 EOADDS
482 RC=$?
483 if test $RC != 0 ; then
484         echo "ldapmodify failed for consumer2 database ($RC)!"
485         test $KILLSERVERS != no && kill -HUP $KILLPIDS
486         exit $RC
487 fi
488
489 SLEEP=20
490 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
491 sleep $SLEEP
492
493 echo "Using ldapsearch to check that syncrepl received database changes..."
494 RC=32
495 for i in 0 1 2 3 4 5; do
496         RESULT=`$LDAPSEARCH -H $URI2 \
497                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
498                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
499         if test "x$RESULT" = "xOK" ; then
500                 RC=0
501                 break
502         fi
503         echo "Waiting 5 seconds for syncrepl to receive changes..."
504         sleep 5
505 done
506
507 if test $RC != 0 ; then
508         echo "ldapsearch failed ($RC)!"
509         test $KILLSERVERS != no && kill -HUP $KILLPIDS
510         exit $RC
511 fi
512
513 echo "Using ldapsearch to check that syncrepl received database changes on consumer2..."
514 RC=32
515 for i in 0 1 2 3 4 5; do
516         RESULT=`$LDAPSEARCH -H $URI3 \
517                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
518                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
519         if test "x$RESULT" = "xOK" ; then
520                 RC=0
521                 break
522         fi
523         echo "Waiting 5 seconds for syncrepl to receive changes..."
524         sleep 5
525 done
526
527 if test $RC != 0 ; then
528         echo "ldapsearch failed ($RC)!"
529         test $KILLSERVERS != no && kill -HUP $KILLPIDS
530         exit $RC
531 fi
532
533 echo "Using ldapsearch to read config from the producer..."
534 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
535         'objectclass=*' > $MASTEROUT 2>&1
536 RC=$?
537
538 if test $RC != 0 ; then
539         echo "ldapsearch failed at producer ($RC)!"
540         test $KILLSERVERS != no && kill -HUP $KILLPIDS
541         exit $RC
542 fi
543
544 echo "Using ldapsearch to read config from consumer1..."
545 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
546         'objectclass=*' > $SLAVEOUT 2>&1
547 RC=$?
548
549 if test $RC != 0 ; then
550         echo "ldapsearch failed at consumer1 ($RC)!"
551         test $KILLSERVERS != no && kill -HUP $KILLPIDS
552         exit $RC
553 fi
554
555 echo "Using ldapsearch to read config from consumer2..."
556 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
557         'objectclass=*' > $SLAVE2OUT 2>&1
558 RC=$?
559
560 if test $RC != 0 ; then
561         echo "ldapsearch failed at consumer2 ($RC)!"
562         test $KILLSERVERS != no && kill -HUP $KILLPIDS
563         exit $RC
564 fi
565
566 echo "Filtering producer results..."
567 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
568 echo "Filtering consumer1 results..."
569 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
570 echo "Filtering consumer2 results..."
571 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
572
573 echo "Comparing retrieved configs from producer and consumer1..."
574 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
575
576 if test $? != 0 ; then
577         echo "test failed - producer and consumer1 configs differ"
578         test $KILLSERVERS != no && kill -HUP $KILLPIDS
579         exit 1
580 fi
581
582 echo "Comparing retrieved configs from producer and consumer2..."
583 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
584
585 if test $? != 0 ; then
586         echo "test failed - producer and consumer2 configs differ"
587         test $KILLSERVERS != no && kill -HUP $KILLPIDS
588         exit 1
589 fi
590
591 echo "Using ldapsearch to read all the entries from the producer..."
592 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
593         'objectclass=*' > $MASTEROUT 2>&1
594 RC=$?
595
596 if test $RC != 0 ; then
597         echo "ldapsearch failed at producer ($RC)!"
598         test $KILLSERVERS != no && kill -HUP $KILLPIDS
599         exit $RC
600 fi
601
602 echo "Using ldapsearch to read all the entries from consumer1..."
603 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
604         'objectclass=*' > $SLAVEOUT 2>&1
605 RC=$?
606
607 if test $RC != 0 ; then
608         echo "ldapsearch failed at consumer1 ($RC)!"
609         test $KILLSERVERS != no && kill -HUP $KILLPIDS
610         exit $RC
611 fi
612
613 echo "Using ldapsearch to read all the entries from consumer2..."
614 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD  \
615         'objectclass=*' > $SLAVE2OUT 2>&1
616 RC=$?
617
618 if test $RC != 0 ; then
619         echo "ldapsearch failed at consumer2 ($RC)!"
620         test $KILLSERVERS != no && kill -HUP $KILLPIDS
621         exit $RC
622 fi
623
624 # kill!
625 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
626 kill -HUP $KILLPIDS
627
628 echo "Filtering producer results..."
629 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
630 echo "Filtering consumer1 results..."
631 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
632 echo "Filtering consumer2 results..."
633 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
634
635 echo "Comparing retrieved entries from producer and consumer1..."
636 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
637
638 if test $? != 0 ; then
639         echo "test failed - producer and consumer1 databases differ"
640         exit 1
641 fi
642
643 echo "Comparing retrieved entries from producer and consumer2..."
644 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
645
646 if test $? != 0 ; then
647         echo "test failed - producer and consumer2 databases differ"
648         exit 1
649 fi
650
651 # kill!
652 # test $KILLSERVERS != no && wait
653 wait
654
655 echo "Restarting servers..."
656 echo "Starting producer slapd on TCP/IP port $PORT1..."
657 cd $PRODIR
658 echo "======================= RESTART =======================" >> $LOG1
659 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
660 PID=$!
661 if test $WAIT != 0 ; then
662     echo PID $PID
663     read foo
664 fi
665 KILLPIDS="$PID"
666 cd $TESTWD
667 echo "Using ldapsearch to check that producer slapd is running..."
668 for i in 0 1 2 3 4 5; do
669         $LDAPSEARCH -s base -b "" -H $URI1 \
670                 'objectclass=*' > /dev/null 2>&1
671         RC=$?
672         if test $RC = 0 ; then
673                 break
674         fi
675         echo "Waiting 5 seconds for slapd to start..."
676         sleep 5
677 done
678
679 if test $RC != 0 ; then
680         echo "ldapsearch failed ($RC)!"
681         test $KILLSERVERS != no && kill -HUP $KILLPIDS
682         exit $RC
683 fi
684 #exit 0
685 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
686 cd $CONDIR
687 echo "======================= RESTART =======================" >> $LOG2
688 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
689 SLAVEPID=$!
690 if test $WAIT != 0 ; then
691     echo SLAVEPID $SLAVEPID
692     read foo
693 fi
694 KILLPIDS="$KILLPIDS $SLAVEPID"
695 cd $TESTWD
696
697 sleep 1
698
699 echo "Using ldapsearch to check that consumer1 slapd is running..."
700 for i in 0 1 2 3 4 5; do
701         $LDAPSEARCH -s base -b "" -H $URI2 \
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
717 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
718 cd $CONDIR2
719 echo "======================= RESTART =======================" >> $LOG3
720 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
721 SLAVE2PID=$!
722 if test $WAIT != 0 ; then
723     echo SLAVE2PID $SLAVE2PID
724     read foo
725 fi
726 KILLPIDS="$KILLPIDS $SLAVE2PID"
727 cd $TESTWD
728
729 sleep 1
730
731 echo "Using ldapsearch to check that consumer2 slapd is running..."
732 for i in 0 1 2 3 4 5; do
733         $LDAPSEARCH -s base -b "" -H $URI3 \
734                 'objectclass=*' > /dev/null 2>&1
735         RC=$?
736         if test $RC = 0 ; then
737                 break
738         fi
739         echo "Waiting 5 seconds for slapd to start..."
740         sleep 5
741 done
742
743 if test $RC != 0 ; then
744         echo "ldapsearch failed ($RC)!"
745         test $KILLSERVERS != no && kill -HUP $KILLPIDS
746         exit $RC
747 fi
748
749 # Insert modifications and more tests here.
750 SLEEP=10
751 echo "Waiting $SLEEP seconds for servers to resync..."
752 sleep $SLEEP
753
754 test $KILLSERVERS != no && kill -HUP $KILLPIDS
755
756 echo ">>>>> Test succeeded"
757
758 test $KILLSERVERS != no && wait
759
760 exit 0