]> git.sur5r.net Git - openldap/blob - tests/scripts/test050-syncrepl-multimaster
ITS#5988 Added another server, compare server contents after each modify.
[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 CONDIR3=$TESTDIR/con3
28 DBPRO=$PRODIR/db
29 DBCON=$CONDIR/db
30 DBCON2=$CONDIR2/db
31 DBCON3=$CONDIR3/db
32 CFPRO=$PRODIR/slapd.d
33 CFCON=$CONDIR/slapd.d
34 CFCON2=$CONDIR2/slapd.d
35 CFCON3=$CONDIR3/slapd.d
36
37 mkdir -p $TESTDIR $PRODIR $CONDIR $CONDIR2 $CONDIR3 $DBPRO $DBCON $DBCON2 $DBCON3 $CFPRO $CFCON $CFCON2 $CFCON3
38
39 $SLAPPASSWD -g -n >$CONFIGPWF
40
41 if test x"$SYNCMODE" = x ; then
42         SYNCMODE=rp
43 fi
44 case "$SYNCMODE" in
45         ro)
46                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
47                 ;;
48         rp)
49                 SYNCTYPE="type=refreshAndPersist"
50                 ;;
51         *)
52                 echo "unknown sync mode $SYNCMODE"
53                 exit 1;
54                 ;;
55 esac
56
57 #
58 # Test replication of dynamic config:
59 # - start producer
60 # - start consumer1
61 # - start consumer2
62 # - start consumer3
63 # - configure over ldap
64 # - populate over ldap
65 # - configure syncrepl over ldap
66 # - retrieve database over ldap and compare against expected results
67 #
68
69 echo "Initializing server configurations..."
70 $SLAPADD -F $CFCON2 -n 0 <<EOF
71 dn: cn=config
72 objectClass: olcGlobal
73 cn: config
74 olcServerID: 3
75
76 dn: olcDatabase={0}config,cn=config
77 objectClass: olcDatabaseConfig
78 olcDatabase: {0}config
79 olcRootPW:< file://$CONFIGPWF
80 EOF
81
82 $SLAPADD -F $CFCON3 -n 0 <<EOF
83 dn: cn=config
84 objectClass: olcGlobal
85 cn: config
86 olcServerID: 4
87
88 dn: olcDatabase={0}config,cn=config
89 objectClass: olcDatabaseConfig
90 olcDatabase: {0}config
91 olcRootPW:< file://$CONFIGPWF
92 EOF
93
94 $SLAPADD -F $CFCON -n 0 <<EOF
95 dn: cn=config
96 objectClass: olcGlobal
97 cn: config
98 olcServerID: 2
99
100 dn: olcDatabase={0}config,cn=config
101 objectClass: olcDatabaseConfig
102 olcDatabase: {0}config
103 olcRootPW:< file://$CONFIGPWF
104 EOF
105
106 $SLAPADD -F $CFPRO -n 0 <<EOF
107 dn: cn=config
108 objectClass: olcGlobal
109 cn: config
110 olcServerID: 1
111
112 dn: olcDatabase={0}config,cn=config
113 objectClass: olcDatabaseConfig
114 olcDatabase: {0}config
115 olcRootPW:< file://$CONFIGPWF
116 EOF
117
118 echo "Starting producer slapd on TCP/IP port $PORT1..."
119 cd $PRODIR
120 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
121 PID=$!
122 if test $WAIT != 0 ; then
123     echo PID $PID
124     read foo
125 fi
126 KILLPIDS="$PID"
127 cd $TESTWD
128
129 sleep 1
130
131 echo "Using ldapsearch to check that producer slapd is running..."
132 for i in 0 1 2 3 4 5; do
133         $LDAPSEARCH -s base -b "" -H $URI1 \
134                 'objectclass=*' > /dev/null 2>&1
135         RC=$?
136         if test $RC = 0 ; then
137                 break
138         fi
139         echo "Waiting 5 seconds for slapd to start..."
140         sleep 5
141 done
142
143 if test $RC != 0 ; then
144         echo "ldapsearch failed ($RC)!"
145         test $KILLSERVERS != no && kill -HUP $KILLPIDS
146         exit $RC
147 fi
148
149 echo "Inserting syncprov overlay on producer..."
150 if [ "$SYNCPROV" = syncprovmod ]; then
151         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
152 dn: cn=module,cn=config
153 objectClass: olcModuleList
154 cn: module
155 olcModulePath: ../../../servers/slapd/overlays
156 olcModuleLoad: syncprov.la
157 EOF
158         RC=$?
159         if test $RC != 0 ; then
160                 echo "ldapadd failed for moduleLoad ($RC)!"
161                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
162                 exit $RC
163         fi
164 fi
165 #
166 # Note that we configure a timeout here; it's possible for both
167 # servers to attempt to bind to each other while a modify to
168 # cn=config is in progress. When the modify pauses the thread pool
169 # neither server will progress. The timeout will drop the syncrepl
170 # attempt and allow the modifies to complete.
171 #
172 read CONFIGPW < $CONFIGPWF
173 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
174 dn: cn=config
175 changetype: modify
176 replace: olcServerID
177 olcServerID: 1 $URI1
178 olcServerID: 2 $URI2
179 olcServerID: 3 $URI3
180 olcServerID: 4 $URI4
181
182 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
183 changetype: add
184 objectClass: olcOverlayConfig
185 objectClass: olcSyncProvConfig
186 olcOverlay: syncprov
187
188 dn: olcDatabase={0}config,cn=config
189 changetype: modify
190 add: olcSyncRepl
191 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
192   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
193   retry="3 5 300 5" timeout=3
194 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
195   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
196   retry="3 5 300 5" timeout=3
197 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
198   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
199   retry="3 5 300 5" timeout=3
200 olcSyncRepl: rid=004 provider=$URI4 binddn="cn=config" bindmethod=simple
201   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
202   retry="3 5 300 5" timeout=3
203 -
204 add: olcMirrorMode
205 olcMirrorMode: TRUE
206 EOF
207 RC=$?
208 if test $RC != 0 ; then
209         echo "ldapmodify failed for syncrepl config ($RC)!"
210         test $KILLSERVERS != no && kill -HUP $KILLPIDS
211         exit $RC
212 fi
213
214 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
215 cd $CONDIR
216 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
217 SLAVEPID=$!
218 if test $WAIT != 0 ; then
219     echo SLAVEPID $SLAVEPID
220     read foo
221 fi
222 KILLPIDS="$KILLPIDS $SLAVEPID"
223 cd $TESTWD
224
225 sleep 1
226
227 echo "Using ldapsearch to check that consumer1 slapd is running..."
228 for i in 0 1 2 3 4 5; do
229         $LDAPSEARCH -s base -b "" -H $URI2 \
230                 'objectclass=*' > /dev/null 2>&1
231         RC=$?
232         if test $RC = 0 ; then
233                 break
234         fi
235         echo "Waiting 5 seconds for slapd to start..."
236         sleep 5
237 done
238
239 if test $RC != 0 ; then
240         echo "ldapsearch failed ($RC)!"
241         test $KILLSERVERS != no && kill -HUP $KILLPIDS
242         exit $RC
243 fi
244
245 echo "Configuring syncrepl on consumer1..."
246 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
247 dn: olcDatabase={0}config,cn=config
248 changetype: modify
249 add: olcSyncRepl
250 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
251   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
252   retry="3 5 300 5" timeout=3
253 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
254   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
255   retry="3 5 300 5" timeout=3
256 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
257   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
258   retry="3 5 300 5" timeout=3
259 olcSyncRepl: rid=004 provider=$URI4 binddn="cn=config" bindmethod=simple
260   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
261   retry="3 5 300 5" timeout=3
262 -
263 add: olcMirrorMode
264 olcMirrorMode: TRUE
265 EOF
266
267 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
268 cd $CONDIR2
269 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
270 SLAVE2PID=$!
271 if test $WAIT != 0 ; then
272     echo SLAVE2PID $SLAVE2PID
273     read foo
274 fi
275 KILLPIDS="$KILLPIDS $SLAVE2PID"
276 cd $TESTWD
277
278 sleep 1
279
280 echo "Using ldapsearch to check that consumer2 slapd is running..."
281 for i in 0 1 2 3 4 5; do
282         $LDAPSEARCH -s base -b "" -H $URI3 \
283                 'objectclass=*' > /dev/null 2>&1
284         RC=$?
285         if test $RC = 0 ; then
286                 break
287         fi
288         echo "Waiting 5 seconds for slapd to start..."
289         sleep 5
290 done
291
292 if test $RC != 0 ; then
293         echo "ldapsearch failed ($RC)!"
294         test $KILLSERVERS != no && kill -HUP $KILLPIDS
295         exit $RC
296 fi
297
298 echo "Configuring syncrepl on consumer2..."
299 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
300 dn: olcDatabase={0}config,cn=config
301 changetype: modify
302 add: olcSyncRepl
303 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
304   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
305   retry="3 5 300 5" timeout=3
306 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
307   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
308   retry="3 5 300 5" timeout=3
309 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
310   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
311   retry="3 5 300 5" timeout=3
312 olcSyncRepl: rid=004 provider=$URI4 binddn="cn=config" bindmethod=simple
313   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
314   retry="3 5 300 5" timeout=3
315 -
316 add: olcMirrorMode
317 olcMirrorMode: TRUE
318 EOF
319
320 echo "Starting consumer3 slapd on TCP/IP port $PORT4..."
321 cd $CONDIR3
322 $SLAPD -F ./slapd.d -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
323 SLAVE3PID=$!
324 if test $WAIT != 0 ; then
325     echo SLAVE3PID $SLAVE3PID
326     read foo
327 fi
328 KILLPIDS="$KILLPIDS $SLAVE3PID"
329 cd $TESTWD
330
331 sleep 1
332
333 echo "Using ldapsearch to check that consumer3 slapd is running..."
334 for i in 0 1 2 3 4 5; do
335         $LDAPSEARCH -s base -b "" -H $URI4 \
336                 'objectclass=*' > /dev/null 2>&1
337         RC=$?
338         if test $RC = 0 ; then
339                 break
340         fi
341         echo "Waiting 5 seconds for slapd to start..."
342         sleep 5
343 done
344
345 if test $RC != 0 ; then
346         echo "ldapsearch failed ($RC)!"
347         test $KILLSERVERS != no && kill -HUP $KILLPIDS
348         exit $RC
349 fi
350
351 echo "Configuring syncrepl on consumer3..."
352 $LDAPMODIFY -D cn=config -H $URI4 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
353 dn: olcDatabase={0}config,cn=config
354 changetype: modify
355 add: olcSyncRepl
356 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
357   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
358   retry="3 5 300 5" timeout=3
359 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
360   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
361   retry="3 5 300 5" timeout=3
362 olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
363   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
364   retry="3 5 300 5" timeout=3
365 olcSyncRepl: rid=004 provider=$URI4 binddn="cn=config" bindmethod=simple
366   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
367   retry="3 5 300 5" timeout=3
368 -
369 add: olcMirrorMode
370 olcMirrorMode: TRUE
371 EOF
372
373 echo "Adding schema and databases on producer..."
374 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
375 include: file://$ABS_SCHEMADIR/core.ldif
376
377 include: file://$ABS_SCHEMADIR/cosine.ldif
378
379 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
380
381 include: file://$ABS_SCHEMADIR/openldap.ldif
382
383 include: file://$ABS_SCHEMADIR/nis.ldif
384 EOF
385 RC=$?
386 if test $RC != 0 ; then
387         echo "ldapadd failed for schema config ($RC)!"
388         test $KILLSERVERS != no && kill -HUP $KILLPIDS
389         exit $RC
390 fi
391
392 if [ "$BACKENDTYPE" = mod ]; then
393         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
394 dn: cn=module,cn=config
395 objectClass: olcModuleList
396 cn: module
397 olcModulePath: ../../../servers/slapd/back-$BACKEND
398 olcModuleLoad: back_$BACKEND.la
399 EOF
400         RC=$?
401         if test $RC != 0 ; then
402                 echo "ldapadd failed for backend config ($RC)!"
403                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
404                 exit $RC
405         fi
406 fi
407
408 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
409 dn: olcDatabase={1}$BACKEND,cn=config
410 objectClass: olcDatabaseConfig
411 objectClass: olc${BACKEND}Config
412 olcDatabase: {1}$BACKEND
413 olcSuffix: $BASEDN
414 olcDbDirectory: ./db
415 olcRootDN: $MANAGERDN
416 olcRootPW: $PASSWD
417 olcSyncRepl: rid=005 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
418   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
419   retry="3 5 300 5" timeout=3
420 olcSyncRepl: rid=006 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
421   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
422   retry="3 5 300 5" timeout=3
423 olcSyncRepl: rid=007 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
424   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
425   retry="3 5 300 5" timeout=3
426 olcSyncRepl: rid=008 provider=$URI4 binddn="$MANAGERDN" bindmethod=simple
427   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
428   retry="3 5 300 5" timeout=3
429 olcMirrorMode: TRUE
430
431 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
432 changetype: add
433 objectClass: olcOverlayConfig
434 objectClass: olcSyncProvConfig
435 olcOverlay: syncprov
436 EOF
437 RC=$?
438 if test $RC != 0 ; then
439         echo "ldapadd failed for database config ($RC)!"
440         test $KILLSERVERS != no && kill -HUP $KILLPIDS
441         exit $RC
442 fi
443
444 case $BACKEND in
445 bdb | hdb)
446         $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
447 dn: olcDatabase={1}$BACKEND,cn=config
448 changetype: modify
449 add: olcDbIndex
450 olcDbIndex: objectClass,entryUUID,entryCSN eq
451 olcDbIndex: cn,uid pres,eq,sub
452 EOF
453         RC=$?
454         if test $RC != 0 ; then
455                 echo "ldapadd modify for database config ($RC)!"
456                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
457                 exit $RC
458         fi
459         ;;
460 esac
461
462 echo "Using ldapadd to populate producer..."
463 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
464         >> $TESTOUT 2>&1
465 RC=$?
466 if test $RC != 0 ; then
467         echo "ldapadd failed for producer database ($RC)!"
468         test $KILLSERVERS != no && kill -HUP $KILLPIDS
469         exit $RC
470 fi
471
472 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
473 sleep $SLEEP1
474
475 echo "Using ldapsearch to read config from the producer..."
476 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
477         'objectclass=*' > $MASTEROUT 2>&1
478 RC=$?
479
480 if test $RC != 0 ; then
481         echo "ldapsearch failed at producer ($RC)!"
482         test $KILLSERVERS != no && kill -HUP $KILLPIDS
483         exit $RC
484 fi
485
486 echo "Using ldapsearch to read config from consumer1..."
487 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
488         'objectclass=*' > $SLAVEOUT 2>&1
489 RC=$?
490
491 if test $RC != 0 ; then
492         echo "ldapsearch failed at consumer1 ($RC)!"
493         test $KILLSERVERS != no && kill -HUP $KILLPIDS
494         exit $RC
495 fi
496
497 echo "Using ldapsearch to read config from consumer2..."
498 $LDAPSEARCH -b cn=config -D cn=config -H $URI3 -y $CONFIGPWF \
499         'objectclass=*' > $SLAVE2OUT 2>&1
500 RC=$?
501
502 if test $RC != 0 ; then
503         echo "ldapsearch failed at consumer2 ($RC)!"
504         test $KILLSERVERS != no && kill -HUP $KILLPIDS
505         exit $RC
506 fi
507
508 echo "Using ldapsearch to read config from consumer3..."
509 $LDAPSEARCH -b cn=config -D cn=config -H $URI4 -y $CONFIGPWF \
510         'objectclass=*' > $SERVER4OUT 2>&1
511 RC=$?
512
513 if test $RC != 0 ; then
514         echo "ldapsearch failed at consumer3 ($RC)!"
515         test $KILLSERVERS != no && kill -HUP $KILLPIDS
516         exit $RC
517 fi
518
519 echo "Filtering producer results..."
520 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
521 echo "Filtering consumer1 results..."
522 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
523 echo "Filtering consumer2 results..."
524 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
525 echo "Filtering consumer3 results..."
526 . $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
527
528 echo "Comparing retrieved configs from producer and consumer1..."
529 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
530
531 if test $? != 0 ; then
532         echo "test failed - producer and consumer1 configs differ"
533         test $KILLSERVERS != no && kill -HUP $KILLPIDS
534         exit 1
535 fi
536
537 echo "Comparing retrieved configs from producer and consumer2..."
538 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
539
540 if test $? != 0 ; then
541         echo "test failed - producer and consumer2 configs differ"
542         test $KILLSERVERS != no && kill -HUP $KILLPIDS
543         exit 1
544 fi
545
546 echo "Comparing retrieved configs from producer and consumer3..."
547 $CMP $MASTERFLT $SERVER4FLT > $CMPOUT
548
549 if test $? != 0 ; then
550         echo "test failed - producer and consumer3 configs differ"
551         test $KILLSERVERS != no && kill -HUP $KILLPIDS
552         exit 1
553 fi
554
555 echo "Using ldapsearch to read all the entries from the producer..."
556 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
557         'objectclass=*' > $MASTEROUT 2>&1
558 RC=$?
559
560 if test $RC != 0 ; then
561         echo "ldapsearch failed at producer ($RC)!"
562         test $KILLSERVERS != no && kill -HUP $KILLPIDS
563         exit $RC
564 fi
565
566 echo "Using ldapsearch to read all the entries from consumer1..."
567 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
568         'objectclass=*' > $SLAVEOUT 2>&1
569 RC=$?
570
571 if test $RC != 0 ; then
572         echo "ldapsearch failed at consumer1 ($RC)!"
573         test $KILLSERVERS != no && kill -HUP $KILLPIDS
574         exit $RC
575 fi
576
577 echo "Using ldapsearch to read all the entries from consumer2..."
578 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD  \
579         'objectclass=*' > $SLAVE2OUT 2>&1
580 RC=$?
581
582 if test $RC != 0 ; then
583         echo "ldapsearch failed at consumer2 ($RC)!"
584         test $KILLSERVERS != no && kill -HUP $KILLPIDS
585         exit $RC
586 fi
587
588 echo "Using ldapsearch to read all the entries from consumer3..."
589 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI4 -w $PASSWD  \
590         'objectclass=*' > $SERVER4OUT 2>&1
591 RC=$?
592
593 if test $RC != 0 ; then
594         echo "ldapsearch failed at consumer3 ($RC)!"
595         test $KILLSERVERS != no && kill -HUP $KILLPIDS
596         exit $RC
597 fi
598
599 echo "Filtering producer results..."
600 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
601 echo "Filtering consumer1 results..."
602 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
603 echo "Filtering consumer2 results..."
604 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
605 echo "Filtering consumer3 results..."
606 . $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
607
608 echo "Comparing retrieved entries from producer and consumer1..."
609 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
610
611 if test $? != 0 ; then
612         echo "test failed - producer and consumer1 databases differ"
613         exit 1
614 fi
615
616 echo "Comparing retrieved entries from producer and consumer2..."
617 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
618
619 if test $? != 0 ; then
620         echo "test failed - producer and consumer2 databases differ"
621         exit 1
622 fi
623
624 echo "Comparing retrieved entries from producer and consumer3..."
625 $CMP $MASTERFLT $SERVER4FLT > $CMPOUT
626
627 if test $? != 0 ; then
628         echo "test failed - producer and consumer3 databases differ"
629         exit 1
630 fi
631
632 echo "Using ldapadd to populate consumer1..."
633 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
634         >> $TESTOUT 2>&1
635 RC=$?
636 if test $RC != 0 ; then
637         echo "ldapadd failed for consumer1 database ($RC)!"
638         test $KILLSERVERS != no && kill -HUP $KILLPIDS
639         exit $RC
640 fi
641
642 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
643 sleep $SLEEP1
644
645 echo "Using ldapsearch to read all the entries from the producer..."
646 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
647         'objectclass=*' > $MASTEROUT 2>&1
648 RC=$?
649
650 if test $RC != 0 ; then
651         echo "ldapsearch failed at producer ($RC)!"
652         test $KILLSERVERS != no && kill -HUP $KILLPIDS
653         exit $RC
654 fi
655
656 echo "Using ldapsearch to read all the entries from consumer1..."
657 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
658         'objectclass=*' > $SLAVEOUT 2>&1
659 RC=$?
660
661 if test $RC != 0 ; then
662         echo "ldapsearch failed at consumer1 ($RC)!"
663         test $KILLSERVERS != no && kill -HUP $KILLPIDS
664         exit $RC
665 fi
666
667 echo "Using ldapsearch to read all the entries from consumer2..."
668 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD  \
669         'objectclass=*' > $SLAVE2OUT 2>&1
670 RC=$?
671
672 if test $RC != 0 ; then
673         echo "ldapsearch failed at consumer2 ($RC)!"
674         test $KILLSERVERS != no && kill -HUP $KILLPIDS
675         exit $RC
676 fi
677
678 echo "Using ldapsearch to read all the entries from consumer3..."
679 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI4 -w $PASSWD  \
680         'objectclass=*' > $SERVER4OUT 2>&1
681 RC=$?
682
683 if test $RC != 0 ; then
684         echo "ldapsearch failed at consumer3 ($RC)!"
685         test $KILLSERVERS != no && kill -HUP $KILLPIDS
686         exit $RC
687 fi
688
689 echo "Filtering producer results..."
690 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
691 echo "Filtering consumer1 results..."
692 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
693 echo "Filtering consumer2 results..."
694 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
695 echo "Filtering consumer3 results..."
696 . $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
697
698 echo "Comparing retrieved entries from producer and consumer1..."
699 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
700
701 if test $? != 0 ; then
702         echo "test failed - producer and consumer1 databases differ"
703         exit 1
704 fi
705
706 echo "Comparing retrieved entries from producer and consumer2..."
707 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
708
709 if test $? != 0 ; then
710         echo "test failed - producer and consumer2 databases differ"
711         exit 1
712 fi
713
714 echo "Comparing retrieved entries from producer and consumer3..."
715 $CMP $MASTERFLT $SERVER4FLT > $CMPOUT
716
717 if test $? != 0 ; then
718         echo "test failed - producer and consumer3 databases differ"
719         exit 1
720 fi
721
722 echo "Using ldapadd to populate consumer2..."
723 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
724         << EOMODS >> $TESTOUT 2>&1
725 dn: cn=Consumer 2 Test,dc=example,dc=com
726 changetype: add
727 objectClass: device
728 cn: Consumer 2 Test
729 EOMODS
730 RC=$?
731 if test $RC != 0 ; then
732         echo "ldapadd failed for consumer2 database ($RC)!"
733         test $KILLSERVERS != no && kill -HUP $KILLPIDS
734         exit $RC
735 fi
736
737 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
738 sleep $SLEEP1
739
740 echo "Using ldapsearch to read all the entries from the producer..."
741 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
742         'objectclass=*' > $MASTEROUT 2>&1
743 RC=$?
744
745 if test $RC != 0 ; then
746         echo "ldapsearch failed at producer ($RC)!"
747         test $KILLSERVERS != no && kill -HUP $KILLPIDS
748         exit $RC
749 fi
750
751 echo "Using ldapsearch to read all the entries from consumer1..."
752 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
753         'objectclass=*' > $SLAVEOUT 2>&1
754 RC=$?
755
756 if test $RC != 0 ; then
757         echo "ldapsearch failed at consumer1 ($RC)!"
758         test $KILLSERVERS != no && kill -HUP $KILLPIDS
759         exit $RC
760 fi
761
762 echo "Using ldapsearch to read all the entries from consumer2..."
763 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD  \
764         'objectclass=*' > $SLAVE2OUT 2>&1
765 RC=$?
766
767 if test $RC != 0 ; then
768         echo "ldapsearch failed at consumer2 ($RC)!"
769         test $KILLSERVERS != no && kill -HUP $KILLPIDS
770         exit $RC
771 fi
772
773 echo "Using ldapsearch to read all the entries from consumer3..."
774 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI4 -w $PASSWD  \
775         'objectclass=*' > $SERVER4OUT 2>&1
776 RC=$?
777
778 if test $RC != 0 ; then
779         echo "ldapsearch failed at consumer3 ($RC)!"
780         test $KILLSERVERS != no && kill -HUP $KILLPIDS
781         exit $RC
782 fi
783
784 echo "Filtering producer results..."
785 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
786 echo "Filtering consumer1 results..."
787 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
788 echo "Filtering consumer2 results..."
789 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
790 echo "Filtering consumer3 results..."
791 . $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
792
793 echo "Comparing retrieved entries from producer and consumer1..."
794 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
795
796 if test $? != 0 ; then
797         echo "test failed - producer and consumer1 databases differ"
798         exit 1
799 fi
800
801 echo "Comparing retrieved entries from producer and consumer2..."
802 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
803
804 if test $? != 0 ; then
805         echo "test failed - producer and consumer2 databases differ"
806         exit 1
807 fi
808
809 echo "Comparing retrieved entries from producer and consumer3..."
810 $CMP $MASTERFLT $SERVER4FLT > $CMPOUT
811
812 if test $? != 0 ; then
813         echo "test failed - producer and consumer3 databases differ"
814         exit 1
815 fi
816
817 echo "Using ldapmodify to add to the producer entries that will be deleted..."
818 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
819         >> $TESTOUT 2>&1 << EOADDS
820 dn: cn=To be deleted by producer,dc=example,dc=com
821 changetype: add
822 objectClass: device
823 # no distinguished values, will be added by DSA
824
825 dn: cn=To be deleted by consumer1,dc=example,dc=com
826 changetype: add
827 objectClass: device
828 # no distinguished values, will be added by DSA
829
830 dn: cn=To be deleted by consumer2,dc=example,dc=com
831 changetype: add
832 objectClass: device
833 # no distinguished values, will be added by DSA
834
835 dn: cn=To be deleted by producer,dc=example,dc=com
836 changetype: delete
837 EOADDS
838 RC=$?
839 if test $RC != 0 ; then
840         echo "ldapmodify failed for producer database ($RC)!"
841         test $KILLSERVERS != no && kill -HUP $KILLPIDS
842         exit $RC
843 fi
844
845 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
846 sleep $SLEEP1
847
848 echo "Using ldapsearch to read all the entries from the producer..."
849 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
850         'objectclass=*' > $MASTEROUT 2>&1
851 RC=$?
852
853 if test $RC != 0 ; then
854         echo "ldapsearch failed at producer ($RC)!"
855         test $KILLSERVERS != no && kill -HUP $KILLPIDS
856         exit $RC
857 fi
858
859 echo "Using ldapsearch to read all the entries from consumer1..."
860 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
861         'objectclass=*' > $SLAVEOUT 2>&1
862 RC=$?
863
864 if test $RC != 0 ; then
865         echo "ldapsearch failed at consumer1 ($RC)!"
866         test $KILLSERVERS != no && kill -HUP $KILLPIDS
867         exit $RC
868 fi
869
870 echo "Using ldapsearch to read all the entries from consumer2..."
871 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD  \
872         'objectclass=*' > $SLAVE2OUT 2>&1
873 RC=$?
874
875 if test $RC != 0 ; then
876         echo "ldapsearch failed at consumer2 ($RC)!"
877         test $KILLSERVERS != no && kill -HUP $KILLPIDS
878         exit $RC
879 fi
880
881 echo "Using ldapsearch to read all the entries from consumer3..."
882 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI4 -w $PASSWD  \
883         'objectclass=*' > $SERVER4OUT 2>&1
884 RC=$?
885
886 if test $RC != 0 ; then
887         echo "ldapsearch failed at consumer3 ($RC)!"
888         test $KILLSERVERS != no && kill -HUP $KILLPIDS
889         exit $RC
890 fi
891
892 echo "Filtering producer results..."
893 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
894 echo "Filtering consumer1 results..."
895 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
896 echo "Filtering consumer2 results..."
897 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
898 echo "Filtering consumer3 results..."
899 . $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
900
901 echo "Comparing retrieved entries from producer and consumer1..."
902 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
903
904 if test $? != 0 ; then
905         echo "test failed - producer and consumer1 databases differ"
906         exit 1
907 fi
908
909 echo "Comparing retrieved entries from producer and consumer2..."
910 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
911
912 if test $? != 0 ; then
913         echo "test failed - producer and consumer2 databases differ"
914         exit 1
915 fi
916
917 echo "Comparing retrieved entries from producer and consumer3..."
918 $CMP $MASTERFLT $SERVER4FLT > $CMPOUT
919
920 if test $? != 0 ; then
921         echo "test failed - producer and consumer3 databases differ"
922         exit 1
923 fi
924
925 echo "Using ldapmodify to delete entries from consumer1..."
926 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
927         >> $TESTOUT 2>&1 << EOADDS
928 dn: cn=To be deleted by consumer1,dc=example,dc=com
929 changetype: delete
930 EOADDS
931 RC=$?
932 if test $RC != 0 ; then
933         echo "ldapmodify failed for consumer1 database ($RC)!"
934         test $KILLSERVERS != no && kill -HUP $KILLPIDS
935         exit $RC
936 fi
937
938 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
939 sleep $SLEEP1
940
941 echo "Using ldapmodify to delete entries from consumer2..."
942 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
943         >> $TESTOUT 2>&1 << EOADDS
944 dn: cn=To be deleted by consumer2,dc=example,dc=com
945 changetype: delete
946 EOADDS
947 RC=$?
948 if test $RC != 0 ; then
949         echo "ldapmodify failed for consumer2 database ($RC)!"
950         test $KILLSERVERS != no && kill -HUP $KILLPIDS
951         exit $RC
952 fi
953
954 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
955 sleep $SLEEP1
956
957 echo "Using ldapsearch to read all the entries from the producer..."
958 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
959         'objectclass=*' > $MASTEROUT 2>&1
960 RC=$?
961
962 if test $RC != 0 ; then
963         echo "ldapsearch failed at producer ($RC)!"
964         test $KILLSERVERS != no && kill -HUP $KILLPIDS
965         exit $RC
966 fi
967
968 echo "Using ldapsearch to read all the entries from consumer1..."
969 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
970         'objectclass=*' > $SLAVEOUT 2>&1
971 RC=$?
972
973 if test $RC != 0 ; then
974         echo "ldapsearch failed at consumer1 ($RC)!"
975         test $KILLSERVERS != no && kill -HUP $KILLPIDS
976         exit $RC
977 fi
978
979 echo "Using ldapsearch to read all the entries from consumer2..."
980 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI3 -w $PASSWD  \
981         'objectclass=*' > $SLAVE2OUT 2>&1
982 RC=$?
983
984 if test $RC != 0 ; then
985         echo "ldapsearch failed at consumer2 ($RC)!"
986         test $KILLSERVERS != no && kill -HUP $KILLPIDS
987         exit $RC
988 fi
989
990 echo "Using ldapsearch to read all the entries from consumer3..."
991 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI4 -w $PASSWD  \
992         'objectclass=*' > $SERVER4OUT 2>&1
993 RC=$?
994
995 if test $RC != 0 ; then
996         echo "ldapsearch failed at consumer3 ($RC)!"
997         test $KILLSERVERS != no && kill -HUP $KILLPIDS
998         exit $RC
999 fi
1000
1001 # kill!
1002 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
1003 kill -HUP $KILLPIDS
1004
1005 echo "Filtering producer results..."
1006 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
1007 echo "Filtering consumer1 results..."
1008 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
1009 echo "Filtering consumer2 results..."
1010 . $LDIFFILTER < $SLAVE2OUT > $SLAVE2FLT
1011 echo "Filtering consumer3 results..."
1012 . $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
1013
1014 echo "Comparing retrieved entries from producer and consumer1..."
1015 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
1016
1017 if test $? != 0 ; then
1018         echo "test failed - producer and consumer1 databases differ"
1019         exit 1
1020 fi
1021
1022 echo "Comparing retrieved entries from producer and consumer2..."
1023 $CMP $MASTERFLT $SLAVE2FLT > $CMPOUT
1024
1025 if test $? != 0 ; then
1026         echo "test failed - producer and consumer2 databases differ"
1027         exit 1
1028 fi
1029
1030 echo "Comparing retrieved entries from producer and consumer3..."
1031 $CMP $MASTERFLT $SERVER4FLT > $CMPOUT
1032
1033 if test $? != 0 ; then
1034         echo "test failed - producer and consumer3 databases differ"
1035         exit 1
1036 fi
1037
1038 # kill!
1039 # test $KILLSERVERS != no && wait
1040 wait
1041
1042 echo "Restarting servers..."
1043 echo "Starting producer slapd on TCP/IP port $PORT1..."
1044 cd $PRODIR
1045 echo "======================= RESTART =======================" >> $LOG1
1046 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
1047 PID=$!
1048 if test $WAIT != 0 ; then
1049     echo PID $PID
1050     read foo
1051 fi
1052 KILLPIDS="$PID"
1053 cd $TESTWD
1054 echo "Using ldapsearch to check that producer slapd is running..."
1055 for i in 0 1 2 3 4 5; do
1056         $LDAPSEARCH -s base -b "" -H $URI1 \
1057                 'objectclass=*' > /dev/null 2>&1
1058         RC=$?
1059         if test $RC = 0 ; then
1060                 break
1061         fi
1062         echo "Waiting 5 seconds for slapd to start..."
1063         sleep 5
1064 done
1065
1066 if test $RC != 0 ; then
1067         echo "ldapsearch failed ($RC)!"
1068         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1069         exit $RC
1070 fi
1071 #exit 0
1072 echo "Starting consumer1 slapd on TCP/IP port $PORT2..."
1073 cd $CONDIR
1074 echo "======================= RESTART =======================" >> $LOG2
1075 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
1076 SLAVEPID=$!
1077 if test $WAIT != 0 ; then
1078     echo SLAVEPID $SLAVEPID
1079     read foo
1080 fi
1081 KILLPIDS="$KILLPIDS $SLAVEPID"
1082 cd $TESTWD
1083
1084 sleep 1
1085
1086 echo "Using ldapsearch to check that consumer1 slapd is running..."
1087 for i in 0 1 2 3 4 5; do
1088         $LDAPSEARCH -s base -b "" -H $URI2 \
1089                 'objectclass=*' > /dev/null 2>&1
1090         RC=$?
1091         if test $RC = 0 ; then
1092                 break
1093         fi
1094         echo "Waiting 5 seconds for slapd to start..."
1095         sleep 5
1096 done
1097
1098 if test $RC != 0 ; then
1099         echo "ldapsearch failed ($RC)!"
1100         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1101         exit $RC
1102 fi
1103
1104 echo "Starting consumer2 slapd on TCP/IP port $PORT3..."
1105 cd $CONDIR2
1106 echo "======================= RESTART =======================" >> $LOG3
1107 $SLAPD -F ./slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1108 SLAVE2PID=$!
1109 if test $WAIT != 0 ; then
1110     echo SLAVE2PID $SLAVE2PID
1111     read foo
1112 fi
1113 KILLPIDS="$KILLPIDS $SLAVE2PID"
1114 cd $TESTWD
1115
1116 sleep 1
1117
1118 echo "Using ldapsearch to check that consumer2 slapd is running..."
1119 for i in 0 1 2 3 4 5; do
1120         $LDAPSEARCH -s base -b "" -H $URI3 \
1121                 'objectclass=*' > /dev/null 2>&1
1122         RC=$?
1123         if test $RC = 0 ; then
1124                 break
1125         fi
1126         echo "Waiting 5 seconds for slapd to start..."
1127         sleep 5
1128 done
1129
1130 if test $RC != 0 ; then
1131         echo "ldapsearch failed ($RC)!"
1132         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1133         exit $RC
1134 fi
1135
1136 echo "Starting consumer3 slapd on TCP/IP port $PORT4..."
1137 cd $CONDIR3
1138 echo "======================= RESTART =======================" >> $LOG4
1139 $SLAPD -F ./slapd.d -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
1140 SLAVE3PID=$!
1141 if test $WAIT != 0 ; then
1142     echo SLAVE3PID $SLAVE3PID
1143     read foo
1144 fi
1145 KILLPIDS="$KILLPIDS $SLAVE3PID"
1146 cd $TESTWD
1147
1148 sleep 1
1149
1150 echo "Using ldapsearch to check that consumer3 slapd is running..."
1151 for i in 0 1 2 3 4 5; do
1152         $LDAPSEARCH -s base -b "" -H $URI4 \
1153                 'objectclass=*' > /dev/null 2>&1
1154         RC=$?
1155         if test $RC = 0 ; then
1156                 break
1157         fi
1158         echo "Waiting 5 seconds for slapd to start..."
1159         sleep 5
1160 done
1161
1162 if test $RC != 0 ; then
1163         echo "ldapsearch failed ($RC)!"
1164         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1165         exit $RC
1166 fi
1167
1168 # Insert modifications and more tests here.
1169 echo "Waiting $SLEEP1 seconds for servers to resync..."
1170 sleep $SLEEP1
1171
1172 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1173
1174 echo ">>>>> Test succeeded"
1175
1176 test $KILLSERVERS != no && wait
1177
1178 exit 0