]> git.sur5r.net Git - openldap/blob - tests/scripts/test058-syncrepl-asymmetric
Wait for central master to start after final restart.
[openldap] / tests / scripts / test058-syncrepl-asymmetric
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 # This script tests a configuration scenario as described in these URLs:
17 #
18 # http://www.openldap.org/lists/openldap-devel/200806/msg00041.html
19 # http://www.openldap.org/lists/openldap-devel/200806/msg00054.html
20 #
21 # Search for "TEST:" to find each major test this script performs.
22
23 # The configuration here consist of 3 "sites", each with a "master" and
24 # a "search" server. One of the sites is the "central", the other two
25 # are called "site1" and "site2".
26
27 # The following notations are used in variable names below to identify
28 # these servers, the first number defines the $URL# and $PORT# variable
29 # that server uses:
30 #
31 # 1: SMC_*      Site Master Central
32 # 2: SM1_*      Site Master 1
33 # 3: SM2_*      Site Master 2
34 # 4: SSC_*      Search Site Central
35 # 5: SS1_*      Search Site 1
36 # 6: SS2_*      Search Site 2
37
38 # The master servers all have a set of subordinate databases glued below
39 # the same suffix database.  Each of the masters are the master for at
40 # least one of these subordinate databases, but there are never more
41 # than one master for any single database.  I.e, this is neither a
42 # traditional single-master configuration, nor what most people think
43 # of as multi-master, but more what can be called multiple masters.
44
45 # The central master replicates to the two other masters, and receives
46 # updates from them of the backends they are the master for.  There is
47 # no direct connection between the other two master servers.  All of the
48 # masters have the syncprov overlay configured on the glue database.
49
50 # The search servers replicates from the master server at their site.
51 # They all have a single database with the glue suffix, but their
52 # database configuration doesn't matter much in this test.  (This
53 # database layout was originally created before gluing was introduced
54 # in OpenLDAP, which is why the search servers doesn't use it).
55
56 # The primary objective for gluing the backend databases is not to make
57 # them look like one huge database but to create a common search suffix
58 # for the clients.  Searching is mostly done on the search servers, only
59 # updates are done on the masters.
60
61 # It varies which backends that are replicated to which server (hence
62 # the name asymmetric in this test).  Access control rules on the
63 # masters are used to control what their consumers receives.  The table
64 # below gives an overview of which backend (the columns) that are
65 # replicated to which server (the rows).  A "M" defines the master for
66 # the backend, a "S" is a slave, and "-" means it is not replicated
67 # there.  Oh, the table probably looks wrong without the 4-position
68 # tab-stops OpenLDAP uses...
69
70 #               glue    ou1             ou2             sm1ou1  sm1ou2  sm2ou1  sm2ou2
71 # smc   M               M               M               S               S               S               -
72 # sm1   S               S               -               M               M               -               -
73 # sm2   S               S               S               S               -               M               M
74 # ssc   S               S               -               -               S               -               -
75 # ss1   S               S               -               S               S               -               -
76 # ss2   S               S               S               -               -               S               S
77
78 # On the central master syncrepl is configured on the subordinate
79 # databases, as it varies which backends that exists on its providers.
80 # Had it been used on the glue database then syncrepl would have removed
81 # the backends replicated from site1 but not present on site2 when it
82 # synchronizes with site2 (and vice versa).
83 #
84 # All the other servers uses syncrepl on the glue database, since
85 # replicating more than one subordinate database from the same master
86 # creates (as of the writing of this test script) race conditions that
87 # causes the replication to fail, as the race tests at the end shows.
88
89 # The databases controlled by syncrepl all have $UPDATEDN as their
90 # RootDN, while the master servers has other RootDN values for the
91 # backends they are the backend for them self.  This violates the current
92 # guidelines for gluing databases, which states that the same rootdn
93 # should be used on all of them.  Unfortunately, this cannot be done on
94 # site masters 1 and 2.  The backends they manage locally are either not
95 # present on the central master, or when so they are not replicated back
96 # to their source, which causes syncrepl to try to remove the content of
97 # these backends when it synchronizes with the central master.  The
98 # differing rootdn values used on the backends controlled by syncrepl
99 # and those managed locally prevents it from succeeding in this.  As
100 # noted above, moving syncrepl to the subordinate databases is currently
101 # not an option since that creates race conditions.
102
103 # The binddn values used in the syncrepl configurations are chosen to
104 # make the configuration and access control rules easiest to set up.  It
105 # occasionally uses a DN that is also used as a RootDN.  This is not a
106 # good practice and should not be taken as an example for real
107 # configurations!
108
109 # This script will print the content of any invalid contextCSN values it
110 # detects if the environment variable CSN_VERBOSE is non-empty.  The
111 # environment variable RACE_TESTS can be set to the number of race test
112 # iterations the script should perform.
113
114 case "$BACKEND" in ldif | null)
115         # LDIF lacks ACL support, NULL lacks cn=config support
116         echo "This test does not support the $BACKEND backend"
117         exit 0;;
118 esac
119
120 echo "running defines.sh"
121 . $SRCDIR/scripts/defines.sh
122
123 if test $SYNCPROV = syncprovno; then
124         echo "Syncrepl provider overlay not available, test skipped"
125         exit 0
126 fi
127
128 SMC_DIR=$TESTDIR/smc
129 SM1_DIR=$TESTDIR/sm1
130 SM2_DIR=$TESTDIR/sm2
131 SS1_DIR=$TESTDIR/ss1
132 SS2_DIR=$TESTDIR/ss2
133 SSC_DIR=$TESTDIR/ssc
134
135 mkdir -p $TESTDIR
136
137 for dir in $SMC_DIR $SM1_DIR $SM2_DIR $SS1_DIR $SS2_DIR $SSC_DIR; do
138         mkdir -p $dir $dir/slapd.d $dir/db
139 done
140
141 mkdir -p $SMC_DIR/ou1 $SMC_DIR/sm1ou1 $SMC_DIR/sm1ou2
142 mkdir -p $SMC_DIR/ou2 $SMC_DIR/sm2ou1
143 mkdir -p $SM1_DIR/ou1 $SM1_DIR/sm1ou1 $SM1_DIR/sm1ou2
144 mkdir -p $SM2_DIR/ou2 $SM2_DIR/sm1ou1 $SM2_DIR/sm2ou1 $SM2_DIR/sm2ou2
145
146 cd $TESTDIR
147
148 KILLPIDS=
149
150 $SLAPPASSWD -g -n >$CONFIGPWF
151
152 ID=1
153
154 if test $WAIT != 0 ; then
155         RETRY="1 60"
156 else
157         RETRY="1 10"
158 fi
159
160 echo "Initializing master configurations..."
161 for dir in $SMC_DIR $SM1_DIR $SM2_DIR; do
162         $SLAPADD -F $dir/slapd.d -n 0 <<EOF
163 dn: cn=config
164 objectClass: olcGlobal
165 cn: config
166 olcServerID: $ID
167
168 dn: olcDatabase={0}config,cn=config
169 objectClass: olcDatabaseConfig
170 olcDatabase: {0}config
171 olcRootPW:< file://$CONFIGPWF
172
173 EOF
174         ID=`expr $ID + 1`
175 done
176
177 echo "Initializing search configurations..."
178 for dir in $SS1_DIR $SS2_DIR $SSC_DIR; do
179         $SLAPADD -F $dir/slapd.d -n 0 <<EOF
180 dn: cn=config
181 objectClass: olcGlobal
182 cn: config
183
184 dn: olcDatabase={0}config,cn=config
185 objectClass: olcDatabaseConfig
186 olcDatabase: {0}config
187 olcRootPW:< file://$CONFIGPWF
188
189 EOF
190 done
191
192 echo "Starting central master slapd on TCP/IP port $PORT1..."
193 cd $SMC_DIR
194 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
195 SMC_PID=$!
196 if test $WAIT != 0 ; then
197         echo PID $SMC_PID
198         read foo
199 fi
200 KILLPIDS="$KILLPIDS $SMC_PID"
201 cd $TESTWD
202 sleep 1
203 echo "Using ldapsearch to check that central master slapd is running..."
204 for i in 1 2 3 4 5; do
205         $LDAPSEARCH -s base -b "" -H $URI1 \
206                 'objectclass=*' > /dev/null 2>&1
207         RC=$?
208         test $RC = 0 && break
209         echo "Waiting $i seconds for slapd to start..."
210         sleep $i
211 done
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 "Starting site1 master slapd on TCP/IP port $PORT2..."
219 cd $SM1_DIR
220 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
221 SM1_PID=$!
222 if test $WAIT != 0 ; then
223         echo PID $SM1_PID
224         read foo
225 fi
226 KILLPIDS="$KILLPIDS $SM1_PID"
227 cd $TESTWD
228 sleep 1
229 echo "Using ldapsearch to check that site1 master is running..."
230 for i in 1 2 3 4 5; do
231         $LDAPSEARCH -s base -b "" -H $URI2 \
232                 'objectclass=*' > /dev/null 2>&1
233         RC=$?
234         test $RC = 0 && break
235         echo "Waiting $i seconds for slapd to start..."
236         sleep $i
237 done
238 if test $RC != 0 ; then
239         echo "ldapsearch failed ($RC)!"
240         test $KILLSERVERS != no && kill -HUP $KILLPIDS
241         exit $RC
242 fi
243
244 echo "Starting site2 master slapd on TCP/IP port $PORT3..."
245 cd $SM2_DIR
246 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
247 SM2_PID=$!
248 if test $WAIT != 0 ; then
249         echo PID $SM2_PID
250         read foo
251 fi
252 KILLPIDS="$KILLPIDS $SM2_PID"
253 cd $TESTWD
254 sleep 1
255 echo "Using ldapsearch to check that site2 master is running..."
256 for i in 1 2 3 4 5; do
257         $LDAPSEARCH -s base -b "" -H $URI3 \
258                 'objectclass=*' > /dev/null 2>&1
259         RC=$?
260         test $RC = 0 && break
261         echo "Waiting $i seconds for slapd to start..."
262         sleep $i
263 done
264 if test $RC != 0 ; then
265         echo "ldapsearch failed ($RC)!"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit $RC
268 fi
269
270 echo "Starting central search slapd on TCP/IP port $PORT4..."
271 cd $SSC_DIR
272 $SLAPD -F slapd.d -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
273 SSC_PID=$!
274 if test $WAIT != 0 ; then
275         echo PID $SSC_PID
276         read foo
277 fi
278 KILLPIDS="$KILLPIDS $SSC_PID"
279 cd $TESTWD
280 sleep 1
281 echo "Using ldapsearch to check that central search slapd is running..."
282 for i in 1 2 3 4 5; do
283         $LDAPSEARCH -s base -b "" -H $URI4 \
284                 'objectclass=*' > /dev/null 2>&1
285         RC=$?
286         test $RC = 0 && break
287         echo "Waiting $i seconds for slapd to start..."
288         sleep $i
289 done
290 if test $RC != 0 ; then
291         echo "ldapsearch failed ($RC)!"
292         test $KILLSERVERS != no && kill -HUP $KILLPIDS
293         exit $RC
294 fi
295
296
297 echo "Starting site1 search slapd on TCP/IP port $PORT5..."
298 cd $SS1_DIR
299 $SLAPD -F slapd.d -h $URI5 -d $LVL $TIMING > $LOG5 2>&1 &
300 SS1_PID=$!
301 if test $WAIT != 0 ; then
302         echo PID $SS1_PID
303         read foo
304 fi
305 KILLPIDS="$KILLPIDS $SS1_PID"
306 cd $TESTWD
307 sleep 1
308 echo "Using ldapsearch to check that site1 search slapd is running..."
309 for i in 1 2 3 4 5; do
310         $LDAPSEARCH -s base -b "" -H $URI5 \
311                 'objectclass=*' > /dev/null 2>&1
312         RC=$?
313         test $RC = 0 && break
314         echo "Waiting $i seconds for slapd to start..."
315         sleep $i
316 done
317 if test $RC != 0 ; then
318         echo "ldapsearch failed ($RC)!"
319         test $KILLSERVERS != no && kill -HUP $KILLPIDS
320         exit $RC
321 fi
322
323
324 echo "Starting site2 search slapd on TCP/IP port $PORT6..."
325 cd $SS2_DIR
326 $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING > $LOG6 2>&1 &
327 SS2_PID=$!
328 if test $WAIT != 0 ; then
329         echo PID $SS2_PID
330         read foo
331 fi
332 KILLPIDS="$KILLPIDS $SS2_PID"
333 cd $TESTWD
334 sleep 1
335 echo "Using ldapsearch to check that site2 search slapd is running..."
336 for i in 1 2 3 4 5; do
337         $LDAPSEARCH -s base -b "" -H $URI6 \
338                 'objectclass=*' > /dev/null 2>&1
339         RC=$?
340         test $RC = 0 && break
341         echo "Waiting $i seconds for slapd to start..."
342         sleep $i
343 done
344 if test $RC != 0 ; then
345         echo "ldapsearch failed ($RC)!"
346         test $KILLSERVERS != no && kill -HUP $KILLPIDS
347         exit $RC
348 fi
349
350 for uri in $URI1 $URI2 $URI3 $URI4 $URI5 $URI6; do
351         echo "Adding schema on $uri..."
352         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
353 include: file://$ABS_SCHEMADIR/core.ldif
354
355 include: file://$ABS_SCHEMADIR/cosine.ldif
356
357 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
358
359 include: file://$ABS_SCHEMADIR/openldap.ldif
360
361 include: file://$ABS_SCHEMADIR/nis.ldif
362 EOF
363         RC=$?
364         if test $RC != 0 ; then
365                 echo "ldapadd failed for schema config ($RC)!"
366                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
367                 exit $RC
368         fi
369
370         [ "$BACKENDTYPE" = mod ] || continue
371
372         echo "Adding backend module on $uri..."
373         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
374 dn: cn=module,cn=config
375 objectClass: olcModuleList
376 cn: module
377 olcModulePath: ../../../servers/slapd/back-$BACKEND
378 olcModuleLoad: back_$BACKEND.la
379 EOF
380         RC=$?
381         if test $RC != 0 ; then
382                 echo "ldapadd failed for backend module ($RC)!"
383                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
384                 exit $RC
385         fi
386 done
387
388 echo "Adding database config on central master..."
389 if [ "$SYNCPROV" = syncprovmod ]; then
390         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
391 dn: cn=module,cn=config
392 objectClass: olcModuleList
393 cn: module
394 olcModulePath: ../../../servers/slapd/overlays
395 olcModuleLoad: syncprov.la
396
397 EOF
398         RC=$?
399         if test $RC != 0 ; then
400                 echo "ldapadd failed for moduleLoad ($RC)!"
401                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
402                 exit $RC
403         fi
404 fi
405
406 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
407 dn: olcDatabase={1}$BACKEND,cn=config
408 objectClass: olcDatabaseConfig
409 objectClass: olc${BACKEND}Config
410 olcDatabase: {1}$BACKEND
411 olcDbDirectory: $SMC_DIR/db
412 olcSuffix: $BASEDN
413 olcRootDN: $MANAGERDN
414 olcRootPW: $PASSWD
415
416 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
417 objectClass: olcOverlayConfig
418 olcOverlay: {0}glue
419
420 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
421 objectClass: olcOverlayConfig
422 objectClass: olcSyncProvConfig
423 olcOverlay: {1}syncprov
424 olcSpCheckpoint: 3 1
425
426 dn: olcDatabase={1}$BACKEND,cn=config
427 objectClass: olcDatabaseConfig
428 objectClass: olc${BACKEND}Config
429 olcDatabase: {1}$BACKEND
430 olcDbDirectory: $SMC_DIR/ou1
431 olcSubordinate: TRUE
432 olcSuffix: ou=ou1,$BASEDN
433 olcRootDN: $MANAGERDN
434
435 dn: olcDatabase={2}$BACKEND,cn=config
436 objectClass: olcDatabaseConfig
437 objectClass: olc${BACKEND}Config
438 olcDatabase: {2}$BACKEND
439 olcDbDirectory: $SMC_DIR/ou2
440 olcSubordinate: TRUE
441 olcSuffix: ou=ou2,$BASEDN
442 olcRootDN: $MANAGERDN
443
444 dn: olcDatabase={3}$BACKEND,cn=config
445 objectClass: olcDatabaseConfig
446 objectClass: olc${BACKEND}Config
447 olcDatabase: {3}$BACKEND
448 olcDbDirectory: $SMC_DIR/sm1ou1
449 olcSubordinate: TRUE
450 olcSuffix: ou=sm1ou1,$BASEDN
451 olcRootDN: $UPDATEDN
452
453 dn: olcDatabase={4}$BACKEND,cn=config
454 objectClass: olcDatabaseConfig
455 objectClass: olc${BACKEND}Config
456 olcDatabase: {4}$BACKEND
457 olcDbDirectory: $SMC_DIR/sm1ou2
458 olcSubordinate: TRUE
459 olcSuffix: ou=sm1ou2,$BASEDN
460 olcRootDN: $UPDATEDN
461
462 dn: olcDatabase={5}$BACKEND,cn=config
463 objectClass: olcDatabaseConfig
464 objectClass: olc${BACKEND}Config
465 olcDatabase: {5}$BACKEND
466 olcDbDirectory: $SMC_DIR/sm2ou1
467 olcSubordinate: TRUE
468 olcSuffix: ou=sm2ou1,$BASEDN
469 olcRootDN: $UPDATEDN
470
471 EOF
472 RC=$?
473 if test $RC != 0 ; then
474         echo "ldapadd failed for central master database config ($RC)!"
475         test $KILLSERVERS != no && kill -HUP $KILLPIDS
476         exit $RC
477 fi
478
479 echo "Adding database config on site1 master..."
480 if [ "$SYNCPROV" = syncprovmod ]; then
481         $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
482 dn: cn=module,cn=config
483 objectClass: olcModuleList
484 cn: module
485 olcModulePath: ../../../servers/slapd/overlays
486 olcModuleLoad: syncprov.la
487
488 EOF
489         RC=$?
490         if test $RC != 0 ; then
491                 echo "ldapadd failed for moduleLoad ($RC)!"
492                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
493                 exit $RC
494         fi
495 fi
496
497 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
498 dn: olcDatabase={1}$BACKEND,cn=config
499 objectClass: olcDatabaseConfig
500 objectClass: olc${BACKEND}Config
501 olcDatabase: {1}$BACKEND
502 olcDbDirectory: $SM1_DIR/db
503 olcSuffix: $BASEDN
504 olcRootDN: $UPDATEDN
505
506 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
507 objectClass: olcOverlayConfig
508 olcOverlay: {0}glue
509
510 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
511 objectClass: olcOverlayConfig
512 objectClass: olcSyncProvConfig
513 olcOverlay: {1}syncprov
514
515 dn: olcDatabase={1}$BACKEND,cn=config
516 objectClass: olcDatabaseConfig
517 objectClass: olc${BACKEND}Config
518 olcDatabase: {1}$BACKEND
519 olcDbDirectory: $SM1_DIR/ou1
520 olcSubordinate: TRUE
521 olcSuffix: ou=ou1,$BASEDN
522 olcRootDN: $UPDATEDN
523
524 dn: olcDatabase={2}$BACKEND,cn=config
525 objectClass: olcDatabaseConfig
526 objectClass: olc${BACKEND}Config
527 olcDatabase: {2}$BACKEND
528 olcDbDirectory: $SM1_DIR/sm1ou1
529 olcSubordinate: TRUE
530 olcSuffix: ou=sm1ou1,$BASEDN
531 olcRootDN: ou=sm1ou1,$BASEDN
532 olcRootPW: $PASSWD
533
534 dn: olcDatabase={3}$BACKEND,cn=config
535 objectClass: olcDatabaseConfig
536 objectClass: olc${BACKEND}Config
537 olcDatabase: {3}$BACKEND
538 olcDbDirectory: $SM1_DIR/sm1ou2
539 olcSubordinate: TRUE
540 olcSuffix: ou=sm1ou2,$BASEDN
541 olcRootDN: ou=sm1ou1,$BASEDN
542
543 EOF
544
545 RC=$?
546 if test $RC != 0 ; then
547         echo "ldapadd failed for site1 master database config ($RC)!"
548         test $KILLSERVERS != no && kill -HUP $KILLPIDS
549         exit $RC
550 fi
551
552 echo "Adding database config on site2 master..."
553 if [ "$SYNCPROV" = syncprovmod ]; then
554         $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
555 dn: cn=module,cn=config
556 objectClass: olcModuleList
557 cn: module
558 olcModulePath: ../../../servers/slapd/overlays
559 olcModuleLoad: syncprov.la
560
561 EOF
562         RC=$?
563         if test $RC != 0 ; then
564                 echo "ldapadd failed for moduleLoad ($RC)!"
565                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
566                 exit $RC
567         fi
568 fi
569
570 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
571 dn: olcDatabase={1}$BACKEND,cn=config
572 objectClass: olcDatabaseConfig
573 objectClass: olc${BACKEND}Config
574 olcDatabase: {1}$BACKEND
575 olcDbDirectory: $SM2_DIR/db
576 olcSuffix: $BASEDN
577 olcRootDN: $UPDATEDN
578
579 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
580 objectClass: olcOverlayConfig
581 olcOverlay: {0}glue
582
583 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
584 objectClass: olcOverlayConfig
585 objectClass: olcSyncProvConfig
586 olcOverlay: {1}syncprov
587 olcSpCheckpoint: 1 1
588
589 dn: olcDatabase={1}$BACKEND,cn=config
590 objectClass: olcDatabaseConfig
591 objectClass: olc${BACKEND}Config
592 olcDatabase: {1}$BACKEND
593 olcDbDirectory: $SM2_DIR/ou2
594 olcSubordinate: TRUE
595 olcSuffix: ou=ou2,$BASEDN
596 olcRootDN: $UPDATEDN
597
598 dn: olcDatabase={2}$BACKEND,cn=config
599 objectClass: olcDatabaseConfig
600 objectClass: olc${BACKEND}Config
601 olcDatabase: {2}$BACKEND
602 olcDbDirectory: $SM2_DIR/sm1ou1
603 olcSubordinate: TRUE
604 olcSuffix: ou=sm1ou1,$BASEDN
605 olcRootDN: $UPDATEDN
606
607 dn: olcDatabase={3}$BACKEND,cn=config
608 objectClass: olcDatabaseConfig
609 objectClass: olc${BACKEND}Config
610 olcDatabase: {3}$BACKEND
611 olcDbDirectory: $SM2_DIR/sm2ou1
612 olcSubordinate: TRUE
613 olcSuffix: ou=sm2ou1,$BASEDN
614 olcRootDN: ou=sm2ou1,$BASEDN
615 olcRootPW: $PASSWD
616
617 dn: olcDatabase={4}$BACKEND,cn=config
618 objectClass: olcDatabaseConfig
619 objectClass: olc${BACKEND}Config
620 olcDatabase: {4}$BACKEND
621 olcDbDirectory: $SM2_DIR/sm2ou2
622 olcSubordinate: TRUE
623 olcSuffix: ou=sm2ou2,$BASEDN
624 olcRootDN: ou=sm2ou1,$BASEDN
625
626 EOF
627
628 RC=$?
629 if test $RC != 0 ; then
630         echo "ldapadd failed for site2 master database config ($RC)!"
631         test $KILLSERVERS != no && kill -HUP $KILLPIDS
632         exit $RC
633 fi
634
635 echo "Adding access rules on central master..."
636 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
637 dn: olcDatabase={-1}frontend,cn=config
638 changetype: modify
639 add: olcAccess
640 olcAccess: to dn.exact=dc=example,dc=com
641   by * read
642 olcAccess: to dn.subtree=ou=ou1,dc=example,dc=com
643   by * read
644 olcAccess: to dn.subtree=ou=ou2,dc=example,dc=com
645   by dn.exact=ou=ou1,dc=example,dc=com none
646   by dn.exact=ou=ou2,dc=example,dc=com read
647   by dn.exact=dc=example,dc=com none
648   by * read
649 olcAccess: to dn.subtree=ou=sm1ou1,dc=example,dc=com
650   by dn.exact=ou=ou1,dc=example,dc=com none
651   by dn.exact=ou=ou2,dc=example,dc=com read
652   by dn.exact=dc=example,dc=com none
653   by * read
654 olcAccess: to dn.subtree=ou=sm1ou2,dc=example,dc=com
655   by dn.exact=ou=ou1,dc=example,dc=com none
656   by dn.exact=ou=ou2,dc=example,dc=com none
657   by dn.exact=dc=example,dc=com read
658   by * read
659 olcAccess: to dn.subtree=ou=sm2ou1,dc=example,dc=com
660   by dn.exact=ou=ou1,dc=example,dc=com none
661   by dn.exact=ou=ou2,dc=example,dc=com none
662   by dn.exact=dc=example,dc=com none
663   by * read
664 olcAccess: to * by * read
665
666 EOF
667 RC=$?
668 if test $RC != 0 ; then
669         echo "ldapmodify failed for central master access config ($RC)!"
670         test $KILLSERVERS != no && kill -HUP $KILLPIDS
671         exit $RC
672 fi
673
674 echo "Adding access rules on site1 master..."
675 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
676 dn: olcDatabase={-1}frontend,cn=config
677 changetype: modify
678 add: olcAccess
679 olcAccess: to dn.subtree=dc=example,dc=com
680   by * read
681 olcAccess: to * by * read
682
683 EOF
684 RC=$?
685 if test $RC != 0 ; then
686         echo "ldapmodify failed for site1 master access config ($RC)!"
687         test $KILLSERVERS != no && kill -HUP $KILLPIDS
688         exit $RC
689 fi
690
691 echo "Adding access rules on site2 master..."
692 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
693 dn: olcDatabase={-1}frontend,cn=config
694 changetype: modify
695 add: olcAccess
696 olcAccess: to dn.exact=dc=example,dc=com
697   by * read
698 olcAccess: to dn.subtree=ou=ou2,dc=example,dc=com
699   by * read
700 olcAccess: to dn.subtree=ou=sm1ou1,dc=example,dc=com
701   by users none
702   by * read
703 olcAccess: to dn.subtree=ou=sm2ou1,dc=example,dc=com
704   by * read
705 olcAccess: to dn.subtree=ou=sm2ou2,dc=example,dc=com
706   by dn.exact=dc=example,dc=com read
707   by users none
708   by * read
709 olcAccess: to * by * read
710
711 EOF
712 RC=$?
713 if test $RC != 0 ; then
714         echo "ldapmodify failed for site2 master access config ($RC)!"
715         test $KILLSERVERS != no && kill -HUP $KILLPIDS
716         exit $RC
717 fi
718
719 echo "Adding database config on central search..."
720 $LDAPADD -D cn=config -H $URI4 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
721 dn: olcDatabase={1}$BACKEND,cn=config
722 objectClass: olcDatabaseConfig
723 objectClass: olc${BACKEND}Config
724 olcDatabase: {1}$BACKEND
725 olcDbDirectory: $SSC_DIR/db
726 olcSuffix: $BASEDN
727 olcRootDN: $UPDATEDN
728
729 EOF
730 RC=$?
731 if test $RC != 0 ; then
732         echo "ldapadd failed for central search database config ($RC)!"
733         test $KILLSERVERS != no && kill -HUP $KILLPIDS
734         exit $RC
735 fi
736
737 echo "Adding database config on site1 search..."
738 $LDAPADD -D cn=config -H $URI5 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
739 dn: olcDatabase={1}$BACKEND,cn=config
740 objectClass: olcDatabaseConfig
741 objectClass: olc${BACKEND}Config
742 olcDatabase: {1}$BACKEND
743 olcDbDirectory: $SS1_DIR/db
744 olcSuffix: $BASEDN
745 olcRootDN: $UPDATEDN
746
747 EOF
748 RC=$?
749 if test $RC != 0 ; then
750         echo "ldapadd failed for site1 search database config ($RC)!"
751         test $KILLSERVERS != no && kill -HUP $KILLPIDS
752         exit $RC
753 fi
754
755 echo "Adding database config on site2 search..."
756 $LDAPADD -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
757 dn: olcDatabase={1}$BACKEND,cn=config
758 objectClass: olcDatabaseConfig
759 objectClass: olc${BACKEND}Config
760 olcDatabase: {1}$BACKEND
761 olcDbDirectory: $SS2_DIR/db
762 olcSuffix: $BASEDN
763 olcRootDN: $UPDATEDN
764
765 EOF
766 RC=$?
767 if test $RC != 0 ; then
768         echo "ldapadd failed for site2 search database config ($RC)!"
769         test $KILLSERVERS != no && kill -HUP $KILLPIDS
770         exit $RC
771 fi
772
773 echo "Populating central master..."
774 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
775 dn: dc=example,dc=com
776 objectClass: top
777 objectClass: organization
778 objectClass: dcObject
779 dc: example
780 o: Example, Inc
781 userPassword: $PASSWD
782
783 dn: ou=ou1,dc=example,dc=com
784 objectClass: top
785 objectClass: organizationalUnit
786 ou: ou1
787 userPassword: $PASSWD
788
789 dn: ou=ou2,dc=example,dc=com
790 objectClass: top
791 objectClass: organizationalUnit
792 ou: ou2
793 userPassword: $PASSWD
794
795 EOF
796 RC=$?
797 if test $RC != 0 ; then
798         echo "ldapadd failed to populate central master entry ($RC)!"
799         test $KILLSERVERS != no && kill -HUP $KILLPIDS
800         exit $RC
801 fi
802
803 echo "Adding syncrepl on site1 master..."
804 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
805 dn: olcDatabase={4}$BACKEND,cn=config
806 changetype: modify
807 add: olcSyncRepl
808 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
809   binddn="ou=ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
810   type=refreshAndPersist retry="$RETRY" timeout=1
811
812 EOF
813 RC=$?
814 if test $RC != 0 ; then
815         echo "ldapmodify failed to add syncrepl on site1 master ($RC)!"
816         test $KILLSERVERS != no && kill -HUP $KILLPIDS
817         exit $RC
818 fi
819
820 echo "Adding syncrepl on site2 master..."
821 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
822 dn: olcDatabase={5}$BACKEND,cn=config
823 changetype: modify
824 add: olcSyncRepl
825 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
826   binddn="ou=ou2,$BASEDN" bindmethod=simple credentials=$PASSWD
827   type=refreshAndPersist retry="$RETRY" timeout=1
828
829 EOF
830 RC=$?
831 if test $RC != 0 ; then
832         echo "ldapmodify failed to add syncrepl on site2 master ($RC)!"
833         test $KILLSERVERS != no && kill -HUP $KILLPIDS
834         exit $RC
835 fi
836 sleep 1
837
838 echo "Using ldapsearch to check that site1 master received changes..."
839 RC=32
840 for i in 1 2 3 4 5; do
841         RESULT=`$LDAPSEARCH -H $URI2 \
842                 -s base -b "ou=ou1,$BASEDN" \
843                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
844         if test "x$RESULT" = "xOK" ; then
845                 RC=0
846                 break
847         fi
848         echo "Waiting $i seconds for syncrepl to receive changes..."
849         sleep $i
850 done
851 if test $RC != 0 ; then
852         echo "ldapsearch failed ($RC)!"
853         test $KILLSERVERS != no && kill -HUP $KILLPIDS
854         exit $RC
855 fi
856
857 echo "Using ldapsearch to check that site2 master received changes..."
858 RC=32
859 for i in 1 2 3 4 5; do
860         RESULT=`$LDAPSEARCH -H $URI3 \
861                 -s base -b "ou=ou1,$BASEDN" \
862                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
863         if test "x$RESULT" = "xOK" ; then
864                 RC=0
865                 break
866         fi
867         echo "Waiting $i seconds for syncrepl to receive changes..."
868         sleep $i
869 done
870 if test $RC != 0 ; then
871         echo "ldapsearch failed ($RC)!"
872         test $KILLSERVERS != no && kill -HUP $KILLPIDS
873         exit $RC
874 fi
875
876 sleep 1
877
878 echo "Populating site1 master..."
879 $LDAPADD -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
880 dn: ou=sm1ou1,dc=example,dc=com
881 objectClass: top
882 objectClass: organizationalUnit
883 ou: sm1ou1
884
885 dn: ou=sm1ou2,dc=example,dc=com
886 objectClass: top
887 objectClass: organizationalUnit
888 ou: sm1ou2
889
890 EOF
891 RC=$?
892 if test $RC != 0 ; then
893         echo "ldapadd failed to populate site1 master ($RC)!"
894         test $KILLSERVERS != no && kill -HUP $KILLPIDS
895         exit $RC
896 fi
897
898 sleep 1
899
900 echo "Populating site2 master..."
901 $LDAPADD -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
902 dn: ou=sm2ou1,dc=example,dc=com
903 objectClass: top
904 objectClass: organizationalUnit
905 ou: sm2ou1
906
907 dn: ou=sm2ou2,dc=example,dc=com
908 objectClass: top
909 objectClass: organizationalUnit
910 ou: sm2ou2
911
912 EOF
913 RC=$?
914 if test $RC != 0 ; then
915         echo "ldapadd failed to populate site2 master ($RC)!"
916         test $KILLSERVERS != no && kill -HUP $KILLPIDS
917         exit $RC
918 fi
919
920 ERRORS=0
921
922 # TEST:
923 # Stop site1 master when adding syncrepl to the central master.  When
924 # site1 master is started again both it and the central master will have
925 # the same number of contextCSN values, but the ones on central master
926 # will be the newest.  The central master will not update its contextCSN
927 # values unless the bug in ITS#5597 have been fixed.
928 echo "Stopping site1 master..."
929 kill -HUP "$SM1_PID"
930 wait "$SM1_PID"
931 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SM1_PID / /"`;
932 SM1_PID=
933
934 echo "Adding syncrepl on central master..."
935 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
936 dn: olcDatabase={3}$BACKEND,cn=config
937 changetype: modify
938 add: olcSyncRepl
939 olcSyncRepl: rid=3 provider=$URI2 searchbase="ou=sm1ou1,$BASEDN"
940   binddn="ou=sm1ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
941   type=refreshAndPersist retry="$RETRY" timeout=1
942
943 dn: olcDatabase={5}$BACKEND,cn=config
944 changetype: modify
945 add: olcSyncRepl
946 olcSyncRepl: rid=5 provider=$URI3 searchbase="ou=sm2ou1,$BASEDN"
947   binddn="ou=sm2ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
948   type=refreshAndPersist retry="$RETRY" timeout=1
949
950 EOF
951 RC=$?
952 if test $RC != 0 ; then
953         echo "ldapmodify failed to add syncrepl on central master ($RC)!"
954         test $KILLSERVERS != no && kill -HUP $KILLPIDS
955         exit $RC
956 fi
957 sleep 1
958 echo "Using ldapsearch to check that central master received site2 entries..."
959 RC=32
960 for i in 1 2 3 4 5; do
961         RESULT=`$LDAPSEARCH -H $URI1 \
962                 -s base -b "ou=sm2ou1,$BASEDN" \
963                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
964         if test "x$RESULT" = "xOK" ; then
965                 RC=0
966                 break
967         fi
968         echo "Waiting $i seconds for syncrepl to receive changes..."
969         sleep $i
970 done
971 if test $RC != 0 ; then
972         echo "ldapsearch failed ($RC)!"
973         test $KILLSERVERS != no && kill -HUP $KILLPIDS
974         exit $RC
975 fi
976
977 if test -z "$SM1_PID" ; then
978         echo "Restarting site1 master slapd on TCP/IP port $PORT2..."
979         cd $SM1_DIR
980         $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
981         SM1_PID=$!
982         if test $WAIT != 0 ; then
983             echo PID $SM1_PID
984             read foo
985         fi
986         KILLPIDS="$KILLPIDS $SM1_PID"
987         cd $TESTWD
988         sleep 1
989 fi
990 sleep 1
991 echo "Using ldapsearch to check that site1 master is running..."
992 for i in 1 2 3 4 5; do
993         $LDAPSEARCH -s base -b "" -H $URI2 \
994                 'objectclass=*' > /dev/null 2>&1
995         RC=$?
996         test $RC = 0 && break
997         echo "Waiting $i seconds for slapd to start..."
998         sleep $i
999 done
1000 if test $RC != 0 ; then
1001         echo "ldapsearch failed ($RC)!"
1002         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1003         exit $RC
1004 fi
1005
1006 echo "Using ldapsearch to check that central master received site1 entries..."
1007 RC=32
1008 for i in 1 2 3 4 5; do
1009         RESULT=`$LDAPSEARCH -H $URI1 \
1010                 -s base -b "ou=sm1ou1,$BASEDN" \
1011                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1012         if test "x$RESULT" = "xOK" ; then
1013                 RC=0
1014                 break
1015         fi
1016         echo "Waiting $i seconds for syncrepl to receive changes..."
1017         sleep $i
1018 done
1019 if test $RC != 0 ; then
1020         echo "ldapsearch failed ($RC)!"
1021         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1022         exit $RC
1023 fi
1024
1025 # Test done, now some more intialization...
1026
1027 echo "Adding syncrepl consumer on central search..."
1028 $LDAPMODIFY -D cn=config -H $URI4 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
1029 dn: olcDatabase={1}$BACKEND,cn=config
1030 changetype: modify
1031 add: olcSyncRepl
1032 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
1033   binddn="$BASEDN" bindmethod=simple credentials=$PASSWD
1034   type=refreshAndPersist retry="$RETRY" timeout=1
1035
1036 EOF
1037 RC=$?
1038 if test $RC != 0 ; then
1039         echo "ldapmodify failed to add syncrepl on site1 search ($RC)!"
1040         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1041         exit $RC
1042 fi
1043
1044 echo "Adding syncrepl consumer on site1 search..."
1045 $LDAPMODIFY -D cn=config -H $URI5 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
1046 dn: olcDatabase={1}$BACKEND,cn=config
1047 changetype: modify
1048 add: olcSyncRepl
1049 olcSyncRepl: rid=1 provider=$URI2 searchbase="$BASEDN"
1050   binddn="$BASEDN" bindmethod=simple credentials=$PASSWD
1051   type=refreshAndPersist retry="$RETRY" timeout=1
1052
1053 EOF
1054 RC=$?
1055 if test $RC != 0 ; then
1056         echo "ldapmodify failed to add syncrepl on site1 search ($RC)!"
1057         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1058         exit $RC
1059 fi
1060
1061 echo "Adding syncrepl consumer on site2 search..."
1062 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
1063 dn: olcDatabase={1}$BACKEND,cn=config
1064 changetype: modify
1065 add: olcSyncRepl
1066 olcSyncRepl: rid=1 provider=$URI3 searchbase="$BASEDN"
1067   binddn="$BASEDN" bindmethod=simple credentials=$PASSWD
1068   type=refreshAndPersist retry="$RETRY" timeout=1
1069
1070 EOF
1071 RC=$?
1072 if test $RC != 0 ; then
1073         echo "ldapmodify failed to add syncrepl on site2 search ($RC)!"
1074         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1075         exit $RC
1076 fi
1077 sleep 1
1078
1079 echo "Using ldapsearch to check that central search received changes..."
1080 RC=32
1081 for i in 1 2 3 4 5; do
1082         RESULT=`$LDAPSEARCH -H $URI4 \
1083                 -s base -b "$BASEDN" \
1084                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1085         if test "x$RESULT" = "xOK" ; then
1086                 RC=0
1087                 break
1088         fi
1089         echo "Waiting $i seconds for syncrepl to receive changes..."
1090         sleep $i
1091 done
1092 if test $RC != 0 ; then
1093         echo "ldapsearch failed ($RC)!"
1094         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1095         exit $RC
1096 fi
1097
1098 echo "Using ldapsearch to check that site1 search received changes..."
1099 RC=32
1100 for i in 1 2 3 4 5; do
1101         RESULT=`$LDAPSEARCH -H $URI5 \
1102                 -s base -b "$BASEDN" \
1103                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1104         if test "x$RESULT" = "xOK" ; then
1105                 RC=0
1106                 break
1107         fi
1108         echo "Waiting $i seconds for syncrepl to receive changes..."
1109         sleep $i
1110 done
1111 if test $RC != 0 ; then
1112         echo "ldapsearch failed ($RC)!"
1113         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1114         exit $RC
1115 fi
1116
1117 echo "Using ldapsearch to check that site2 search received changes..."
1118 RC=32
1119 for i in 1 2 3 4 5; do
1120         RESULT=`$LDAPSEARCH -H $URI6 \
1121                 -s base -b "$BASEDN" \
1122                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1123         if test "x$RESULT" = "xOK" ; then
1124                 RC=0
1125                 break
1126         fi
1127         echo "Waiting $i seconds for syncrepl to receive changes..."
1128         sleep $i
1129 done
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 # Create a script that will check the contextCSN values of all servers,
1137 # and restart them to re-synchronize if it finds any errors:
1138 cat > $TESTDIR/checkcsn.sh <<'EOF'
1139 #!/bin/sh
1140
1141 CSN_ERRORS=0
1142
1143 CSN1=`$LDAPSEARCH -H $URI1 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1144 CSN2=`$LDAPSEARCH -H $URI2 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1145 CSN3=`$LDAPSEARCH -H $URI3 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1146 CSN4=`$LDAPSEARCH -H $URI4 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1147 CSN5=`$LDAPSEARCH -H $URI5 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1148 CSN6=`$LDAPSEARCH -H $URI6 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1149
1150 if test -z "$CSN1" ; then
1151         echo "ERROR: contextCSN empty on central master"
1152         CSN_ERRORS=`expr $CSN_ERRORS + 1`
1153 fi
1154 nCSN=`echo "$CSN1" | wc -l`
1155 if test "$nCSN" -ne 3 ; then
1156         echo "ERROR: Wrong contextCSN count on central master, should be 3"
1157         CSN_ERRORS=`expr $CSN_ERRORS + 1`
1158         if test -n "$CSN_VERBOSE"; then
1159                 echo "$CSN1"
1160         fi
1161 fi
1162 if  test -z "$CSN2" -o "$CSN1" != "$CSN2" ; then
1163         echo "ERROR: contextCSN mismatch between central master and site1 master"
1164         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1165         if test -n "$CSN_VERBOSE"; then
1166                 echo "contextCSN on central master:"
1167                 echo "$CSN1"
1168                 echo "contextCSN on site1 master:"
1169                 echo "$CSN2"
1170         fi
1171 fi
1172 if  test -z "$CSN3" -o "$CSN1" != "$CSN3" ; then
1173         echo "ERROR: contextCSN mismatch between central master and site2 master"
1174         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1175         if test -n "$CSN_VERBOSE"; then
1176                 echo "contextCSN on central master:"
1177                 echo "$CSN1"
1178                 echo "contextCSN on site2 master:"
1179                 echo "$CSN3"
1180         fi
1181 fi
1182 if  test -z "$CSN4" -o "$CSN1" != "$CSN4" ; then
1183         echo "ERROR: contextCSN mismatch between central master and central search"
1184         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1185         if test -n "$CSN_VERBOSE"; then
1186                 echo "contextCSN on central master:"
1187                 echo "$CSN1"
1188                 echo "contextCSN on central search:"
1189                 echo "$CSN4"
1190         fi
1191 fi
1192 if  test -z "$CSN5" -o "$CSN2" != "$CSN5" ; then
1193         echo "ERROR: contextCSN mismatch between site1 master and site1 search"
1194         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1195         if test -n "$CSN_VERBOSE"; then
1196                 echo "contextCSN on site1 master:"
1197                 echo "$CSN2"
1198                 echo "contextCSN on site1 search:"
1199                 echo "$CSN5"
1200         fi
1201 fi
1202 if  test -z "$CSN6" -o "$CSN3" != "$CSN6" ; then
1203         echo "ERROR: contextCSN mismatch between site2 master and site2 search:"
1204         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1205         if test -n "$CSN_VERBOSE"; then
1206                 echo "contextCSN on site2 master:"
1207                 echo "$CSN3"
1208                 echo "contextCSN on site2 search:"
1209                 echo "$CSN6"
1210         fi
1211 fi
1212
1213 if test $CSN_ERRORS != 0 ; then
1214         echo "Stopping all servers to synchronize contextCSN..."
1215         kill -HUP  $KILLPIDS
1216         for pid in $KILLPIDS ; do wait $pid ; done
1217         KILLPIDS=
1218
1219         echo "Restarting site1 master slapd on TCP/IP port $PORT2..."
1220         cd $SM1_DIR
1221         $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
1222         SM1_PID=$!
1223         if test $WAIT != 0 ; then
1224                 echo PID $SM1_PID
1225                 read foo
1226         fi
1227         KILLPIDS="$KILLPIDS $SM1_PID"
1228         cd $TESTWD
1229         sleep 1
1230         echo "Using ldapsearch to check that site1 master is running..."
1231         for i in 1 2 3 4 5; do
1232                 $LDAPSEARCH -s base -b "" -H $URI2 \
1233                         'objectclass=*' > /dev/null 2>&1
1234                 RC=$?
1235                 test $RC = 0 && break
1236                 echo "Waiting $i seconds for slapd to start..."
1237                 sleep $i
1238         done
1239         if test $RC != 0 ; then
1240                 echo "ldapsearch failed ($RC)!"
1241                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1242                 exit $RC
1243         fi
1244
1245         echo "Restarting site2 master slapd on TCP/IP port $PORT3..."
1246         cd $SM2_DIR
1247         $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1248         SM2_PID=$!
1249         if test $WAIT != 0 ; then
1250                 echo PID $SM2_PID
1251                 read foo
1252         fi
1253         KILLPIDS="$KILLPIDS $SM2_PID "
1254         cd $TESTWD
1255         sleep 1
1256         echo "Using ldapsearch to check that site2 master is running..."
1257         for i in 1 2 3 4 5; do
1258                 $LDAPSEARCH -s base -b "" -H $URI3 \
1259                         'objectclass=*' > /dev/null 2>&1
1260                 RC=$?
1261                 test $RC = 0 && break
1262                 echo "Waiting $i seconds for slapd to start..."
1263                 sleep $i
1264         done
1265         if test $RC != 0 ; then
1266                 echo "ldapsearch failed ($RC)!"
1267                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1268                 exit $RC
1269         fi
1270
1271         echo "Restarting central master slapd on TCP/IP port $PORT1..."
1272         cd $SMC_DIR
1273         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
1274         SMC_PID=$!
1275         if test $WAIT != 0 ; then
1276                 echo PID $SMC_PID
1277                 read foo
1278         fi
1279         KILLPIDS="$KILLPIDS $SMC_PID"
1280         cd $TESTWD
1281         sleep 1
1282         echo "Using ldapsearch to check that central master slapd is running..."
1283         for i in 1 2 3 4 5; do
1284                 $LDAPSEARCH -s base -b "" -H $URI1 \
1285                         'objectclass=*' > /dev/null 2>&1
1286                 RC=$?
1287                 test $RC = 0 && break
1288                 echo "Waiting $i seconds for slapd to start..."
1289                 sleep $i
1290         done
1291         if test $RC != 0 ; then
1292                 echo "ldapsearch failed ($RC)!"
1293                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1294                 exit $RC
1295         fi
1296
1297         echo "Sleeping 5 seconds to allow contextCSN to synchronize..."
1298         sleep 5
1299
1300         echo "Stopping site1 and site2 master..."
1301         kill -HUP  $SM1_PID $SM2_PID
1302         for pid in $SM1_PID $SM2_PID ; do wait $pid ; done
1303         KILLPIDS=" $SMC_PID"
1304
1305         echo "Restarting site1 master slapd on TCP/IP port $PORT2..."
1306         cd $SM1_DIR
1307         $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
1308         SM1_PID=$!
1309         if test $WAIT != 0 ; then
1310                 echo PID $SM1_PID
1311                 read foo
1312         fi
1313         KILLPIDS="$KILLPIDS $SM1_PID"
1314         cd $TESTWD
1315         sleep 1
1316         echo "Using ldapsearch to check that site1 master is running..."
1317         for i in 1 2 3 4 5; do
1318                 $LDAPSEARCH -s base -b "" -H $URI2 \
1319                         'objectclass=*' > /dev/null 2>&1
1320                 RC=$?
1321                 test $RC = 0 && break
1322                 echo "Waiting $i seconds for slapd to start..."
1323                 sleep $i
1324         done
1325         if test $RC != 0 ; then
1326                 echo "ldapsearch failed ($RC)!"
1327                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1328                 exit $RC
1329         fi
1330
1331         echo "Restarting site2 master slapd on TCP/IP port $PORT3..."
1332         cd $SM2_DIR
1333         $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1334         SM2_PID=$!
1335         if test $WAIT != 0 ; then
1336                 echo PID $SM2_PID
1337                 read foo
1338         fi
1339         KILLPIDS="$KILLPIDS $SM2_PID"
1340         cd $TESTWD
1341         sleep 1
1342         echo "Using ldapsearch to check that site2 master is running..."
1343         for i in 1 2 3 4 5; do
1344                 $LDAPSEARCH -s base -b "" -H $URI3 \
1345                         'objectclass=*' > /dev/null 2>&1
1346                 RC=$?
1347                 test $RC = 0 && break
1348                 echo "Waiting $i seconds for slapd to start..."
1349                 sleep $i
1350         done
1351         if test $RC != 0 ; then
1352                 echo "ldapsearch failed ($RC)!"
1353                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1354                 exit $RC
1355         fi
1356
1357         echo "Sleeping 5 seconds to allow contextCSN to synchronize..."
1358         sleep 5
1359
1360         echo "Restarting central search slapd on TCP/IP port $PORT4..."
1361         cd $SSC_DIR
1362         $SLAPD -F slapd.d -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
1363         SSC_PID=$!
1364         if test $WAIT != 0 ; then
1365                 echo PID $SSC_PID
1366                 read foo
1367         fi
1368         KILLPIDS="$KILLPIDS $SSC_PID"
1369         cd $TESTWD
1370         sleep 1
1371         echo "Using ldapsearch to check that central search slapd is running..."
1372         for i in 1 2 3 4 5; do
1373                 $LDAPSEARCH -s base -b "" -H $URI4 \
1374                         'objectclass=*' > /dev/null 2>&1
1375                 RC=$?
1376                 test $RC = 0 && break
1377                 echo "Waiting $i seconds for slapd to start..."
1378                 sleep $i
1379         done
1380         if test $RC != 0 ; then
1381                 echo "ldapsearch failed ($RC)!"
1382                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1383                 exit $RC
1384         fi
1385
1386         echo "Restarting site1 search slapd on TCP/IP port $PORT5..."
1387         cd $SS1_DIR
1388         $SLAPD -F slapd.d -h $URI5 -d $LVL $TIMING >> $LOG5 2>&1 &
1389         SS1_PID=$!
1390         if test $WAIT != 0 ; then
1391                 echo PID $SS1_PID
1392                 read foo
1393         fi
1394         KILLPIDS="$KILLPIDS $SS1_PID"
1395         cd $TESTWD
1396         sleep 1
1397         echo "Using ldapsearch to check that site1 search slapd is running..."
1398         for i in 1 2 3 4 5; do
1399                 $LDAPSEARCH -s base -b "" -H $URI5 \
1400                         'objectclass=*' > /dev/null 2>&1
1401                 RC=$?
1402                 test $RC = 0 && break
1403                 echo "Waiting $i seconds for slapd to start..."
1404                 sleep $i
1405         done
1406         if test $RC != 0 ; then
1407                 echo "ldapsearch failed ($RC)!"
1408                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1409                 exit $RC
1410         fi
1411
1412         echo "Restarting site2 search slapd on TCP/IP port $PORT6..."
1413         cd $SS2_DIR
1414         $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING >> $LOG6 2>&1 &
1415         SS2_PID=$!
1416         if test $WAIT != 0 ; then
1417                 echo PID $SS2_PID
1418                 read foo
1419         fi
1420         KILLPIDS="$KILLPIDS $SS2_PID"
1421         cd $TESTWD
1422         sleep 1
1423         echo "Using ldapsearch to check that site2 search slapd is running..."
1424         for i in 1 2 3 4 5; do
1425                 $LDAPSEARCH -s base -b "" -H $URI6 \
1426                         'objectclass=*' > /dev/null 2>&1
1427                 RC=$?
1428                 test $RC = 0 && break
1429                 echo "Waiting $i seconds for slapd to start..."
1430                 sleep $i
1431         done
1432         if test $RC != 0 ; then
1433                 echo "ldapsearch failed ($RC)!"
1434                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1435                 exit $RC
1436         fi
1437
1438         echo "Sleeping 5 seconds to allow contextCSN to synchronize..."
1439         sleep 5
1440
1441         echo "Checking contextCSN after restart..."
1442         CSN1=`$LDAPSEARCH -H $URI1 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1443         CSN2=`$LDAPSEARCH -H $URI2 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1444         CSN3=`$LDAPSEARCH -H $URI3 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1445         CSN4=`$LDAPSEARCH -H $URI4 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1446         CSN5=`$LDAPSEARCH -H $URI5 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1447         CSN6=`$LDAPSEARCH -H $URI6 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1448         if test -z "$CSN1" ; then
1449                 echo "ERROR: contextCSN empty on central master"
1450                 CSN_ERRORS=`expr $CSN_ERRORS + 1`
1451         fi
1452
1453         if  test -z "$CSN2" -o "$CSN1" != "$CSN2" ; then
1454                 echo "ERROR: contextCSN mismatch between central master and site1 master"
1455                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1456                 if test -n "$CSN_VERBOSE"; then
1457                         echo "contextCSN on central master:"
1458                         echo "$CSN1"
1459                         echo "contextCSN on site1 master:"
1460                         echo "$CSN2"
1461                 fi
1462         fi
1463         if  test -z "$CSN3" -o "$CSN1" != "$CSN3" ; then
1464                 echo "ERROR: contextCSN mismatch between central master and site2 master"
1465                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1466                 if test -n "$CSN_VERBOSE"; then
1467                         echo "contextCSN on central master:"
1468                         echo "$CSN1"
1469                         echo "contextCSN on site2 master:"
1470                         echo "$CSN3"
1471                 fi
1472         fi
1473         if  test -z "$CSN4" -o "$CSN1" != "$CSN4" ; then
1474                 echo "ERROR: contextCSN mismatch between central master and central search"
1475                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1476                 if test -n "$CSN_VERBOSE"; then
1477                         echo "contextCSN on central master:"
1478                         echo "$CSN1"
1479                         echo "contextCSN on central search:"
1480                         echo "$CSN4"
1481                 fi
1482         fi
1483         if  test -z "$CSN5" -o "$CSN2" != "$CSN5" ; then
1484                 echo "ERROR: contextCSN mismatch between site1 master and site1 search"
1485                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1486                 if test -n "$CSN_VERBOSE"; then
1487                         echo "contextCSN on site1 master:"
1488                         echo "$CSN2"
1489                         echo "contextCSN on site1 search:"
1490                         echo "$CSN5"
1491                 fi
1492         fi
1493         if  test -z "$CSN6" -o "$CSN3" != "$CSN6" ; then
1494                 echo "ERROR: contextCSN mismatch between site2 master and site2 search:"
1495                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1496                 if test -n "$CSN_VERBOSE"; then
1497                         echo "contextCSN on site2 master:"
1498                         echo "$CSN3"
1499                         echo "contextCSN on site2 search:"
1500                         echo "$CSN6"
1501                 fi
1502         fi
1503 fi
1504
1505 ERRORS=`expr $ERRORS + $CSN_ERRORS`
1506
1507 EOF
1508
1509 chmod +x $TESTDIR/checkcsn.sh
1510
1511
1512 echo "Checking contextCSN after initial replication..."
1513 . $TESTDIR/checkcsn.sh
1514
1515 MNUM=1
1516
1517 # TEST:
1518 # Test that updates to the first backend on central master, which should
1519 # be replicated to all servers actually is so, and that the contextCSN is
1520 # updated everywhere:
1521 echo "Using ldapmodify to modify first backend on central master..."
1522 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1523 dn: ou=ou1,dc=example,dc=com
1524 changetype: modify
1525 add: description
1526 description: Modify$MNUM
1527
1528 EOF
1529 RC=$?
1530 if test $RC != 0 ; then
1531         echo "ldapmodify failed ($RC)!"
1532         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1533         exit $RC
1534 fi
1535 sleep 1
1536
1537 echo "Using ldapsearch to check replication to central search..."
1538 RC=32
1539 for i in 1 2 3 4 5; do
1540         RESULT=`$LDAPSEARCH -H $URI4 \
1541                 -s base -b "ou=ou1,$BASEDN" \
1542                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1543         if test "x$RESULT" = "xOK" ; then
1544                 RC=0
1545                 break
1546         fi
1547         echo "Waiting $i seconds for syncrepl to receive changes..."
1548         sleep $i
1549 done
1550 if test $RC != 0 ; then
1551         echo "ldapsearch failed ($RC)!"
1552         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1553         exit $RC
1554 fi
1555
1556 echo "Using ldapsearch to check replication to site1 search..."
1557 RC=32
1558 for i in 1 2 3 4 5; do
1559         RESULT=`$LDAPSEARCH -H $URI5 \
1560                 -s base -b "ou=ou1,$BASEDN" \
1561                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1562         if test "x$RESULT" = "xOK" ; then
1563                 RC=0
1564                 break
1565         fi
1566         echo "Waiting $i seconds for syncrepl to receive changes..."
1567         sleep $i
1568 done
1569 if test $RC != 0 ; then
1570         echo "ldapsearch failed ($RC)!"
1571         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1572         exit $RC
1573 fi
1574
1575 echo "Using ldapsearch to check replication to site2 search..."
1576 RC=32
1577 for i in 1 2 3 4 5; do
1578         RESULT=`$LDAPSEARCH -H $URI6 \
1579                 -s base -b "ou=ou1,$BASEDN" \
1580                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1581         if test "x$RESULT" = "xOK" ; then
1582                 RC=0
1583                 break
1584         fi
1585         echo "Waiting $i seconds for syncrepl to receive changes..."
1586         sleep $i
1587 done
1588 if test $RC != 0 ; then
1589         echo "ldapsearch failed ($RC)!"
1590         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1591         exit $RC
1592 fi
1593
1594 echo "Checking contextCSN after modify of first backend on central master..."
1595 . $TESTDIR/checkcsn.sh
1596
1597 # TEST:
1598 # Test that updates to the second backend on central master is only
1599 # replicated to those search servers that should receive that backend.
1600 # The contextCSN should still be updated everywhere:
1601 MNUM=`expr $MNUM + 1`
1602 echo "Using ldapmodify to modify second backend on central master..."
1603 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1604 dn: ou=ou2,dc=example,dc=com
1605 changetype: modify
1606 add: description
1607 description: Modify$MNUM
1608
1609 EOF
1610 RC=$?
1611 if test $RC != 0 ; then
1612         echo "ldapmodify failed ($RC)!"
1613         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1614         exit $RC
1615 fi
1616 sleep 1
1617
1618 echo "Using ldapsearch to check replication to site2 search..."
1619 RC=32
1620 for i in 1 2 3 4 5; do
1621         RESULT=`$LDAPSEARCH -H $URI6 \
1622                 -s base -b "ou=ou2,$BASEDN" \
1623                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1624         if test "x$RESULT" = "xOK" ; then
1625                 RC=0
1626                 break
1627         fi
1628         echo "Waiting $i seconds for syncrepl to receive changes..."
1629         sleep $i
1630 done
1631 if test $RC != 0 ; then
1632         echo "ldapsearch failed ($RC)!"
1633         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1634         exit $RC
1635 fi
1636
1637 echo "Using ldapsearch to check no replication to site1 master..."
1638 for i in 1 2 3 4 5; do
1639         RESULT=`$LDAPSEARCH -H $URI2 \
1640                 -s base -b "ou=ou2,$BASEDN" \
1641                 "(description=Modify$NMUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1642         if test "x$RESULT" = "xNOK" ; then
1643                 echo "Change was replicated to site1 search!"
1644                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1645                 exit 1
1646         fi
1647         sleep 1
1648 done
1649
1650 echo "Using ldapsearch to check no replication to central search..."
1651 for i in 1 2 3 4 5; do
1652         RESULT=`$LDAPSEARCH -H $URI4 \
1653                 -s base -b "ou=ou2,$BASEDN" \
1654                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1655         if test "x$RESULT" = "xNOK" ; then
1656                 echo "Change was replicated to central search!"
1657                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1658                 exit 1
1659         fi
1660         sleep 1
1661 done
1662
1663 echo "Checking contextCSN after modify of second backend on central master..."
1664 . $TESTDIR/checkcsn.sh
1665
1666 # TEST:
1667 # Test that updates to the first backend on site1 master, which should be
1668 # replicated everywhere except to central and site2 search.  The contextCSN
1669 # should be updated on all servers:
1670 MNUM=`expr $MNUM + 1`
1671 echo "Using ldapmodify to modify first backend on site1 master..."
1672 $LDAPMODIFY -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1673 dn: ou=sm1ou1,dc=example,dc=com
1674 changetype: modify
1675 add: description
1676 description: Modify$MNUM
1677
1678 EOF
1679 RC=$?
1680 if test $RC != 0 ; then
1681         echo "ldapmodify failed ($RC)!"
1682         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1683         exit $RC
1684 fi
1685 sleep 1
1686
1687 echo "Using ldapsearch to check replication to site1 search..."
1688 RC=32
1689 for i in 1 2 3 4 5; do
1690         RESULT=`$LDAPSEARCH -H $URI5 \
1691                 -s base -b "ou=sm1ou1,$BASEDN" \
1692                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1693         if test "x$RESULT" = "xOK" ; then
1694                 RC=0
1695                 break
1696         fi
1697         echo "Waiting $i seconds for syncrepl to receive changes..."
1698         sleep $i
1699 done
1700 if test $RC != 0 ; then
1701         echo "ldapsearch failed ($RC)!"
1702         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1703         exit $RC
1704 fi
1705
1706 echo "Using ldapsearch to check replication to site2 master..."
1707 RC=32
1708 for i in 1 2 3 4 5; do
1709         RESULT=`$LDAPSEARCH -H $URI3 \
1710                 -s base -b "ou=sm1ou1,$BASEDN" \
1711                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1712         if test "x$RESULT" = "xOK" ; then
1713                 RC=0
1714                 break
1715         fi
1716         echo "Waiting $i seconds for syncrepl to receive changes..."
1717         sleep $i
1718 done
1719 if test $RC != 0 ; then
1720         echo "ldapsearch failed ($RC)!"
1721         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1722         exit $RC
1723 fi
1724
1725 echo "Using ldapsearch to check no replication to site2 search..."
1726 for i in 1 2 3 4 5; do
1727         RESULT=`$LDAPSEARCH -H $URI6 \
1728                 -s base -b "ou=sm1ou2,$BASEDN" \
1729                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1730         if test "x$RESULT" = "xNOK" ; then
1731                 echo "Change was replicated to central search!"
1732                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1733                 exit 1
1734         fi
1735         sleep 1
1736 done
1737
1738 echo "Using ldapsearch to check no replication to central search..."
1739 for i in 1 2 3 4 5; do
1740         RESULT=`$LDAPSEARCH -H $URI4 \
1741                 -s base -b "ou=sm1ou2,$BASEDN" \
1742                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1743         if test "x$RESULT" = "xNOK" ; then
1744                 echo "Change was replicated to central search!"
1745                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1746                 exit 1
1747         fi
1748         sleep 1
1749 done
1750
1751 echo "Checking contextCSN after modify of first backend on site1 master..."
1752 . $TESTDIR/checkcsn.sh
1753
1754
1755 # TEST:
1756 # Test updates to the second backend on site1 master, which should only be
1757 # replicated to site1 search.  The contextCSN should be updated everywhere.
1758 MNUM=`expr $MNUM + 1`
1759 echo "Using ldapmodify to modify second backend on site1 master..."
1760 $LDAPMODIFY -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1761 dn: ou=sm1ou2,dc=example,dc=com
1762 changetype: modify
1763 add: description
1764 description: Modify$MNUM
1765
1766 EOF
1767 RC=$?
1768 if test $RC != 0 ; then
1769         echo "ldapmodify failed ($RC)!"
1770         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1771         exit $RC
1772 fi
1773 sleep 1
1774
1775
1776 echo "Using ldapsearch to check replication to site1 search..."
1777 RC=32
1778 for i in 1 2 3 4 5; do
1779         RESULT=`$LDAPSEARCH -H $URI5 \
1780                 -s base -b "ou=sm1ou2,$BASEDN" \
1781                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1782         if test "x$RESULT" = "xOK" ; then
1783                 RC=0
1784                 break
1785         fi
1786         echo "Waiting $i seconds for syncrepl to receive changes..."
1787         sleep $i
1788 done
1789 if test $RC != 0 ; then
1790         echo "ldapsearch failed ($RC)!"
1791         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1792         exit $RC
1793 fi
1794
1795 echo "Using ldapsearch to check no replication to central master..."
1796 for i in 1 2 3 4 5; do
1797         RESULT=`$LDAPSEARCH -H $URI1 \
1798                 -s base -b "ou=sm1ou2,$BASEDN" \
1799                 "(description=Modify$NMUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1800         if test "x$RESULT" = "xNOK" ; then
1801                 echo "Change was replicated to site2 search!"
1802                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1803                 exit 1
1804         fi
1805         sleep 1
1806 done
1807
1808 echo "Checking contextCSN after modify of second backend on site1 master..."
1809 . $TESTDIR/checkcsn.sh
1810
1811
1812 # TEST:
1813 # Test updates to first backend on site2 master, which should be
1814 # replicated to the central servers, but not site1.  The contextCSN
1815 # should be updated everywhere:
1816 MNUM=`expr $MNUM + 1`
1817 echo "Using ldapmodify to modify first backend on site2 master..."
1818 $LDAPMODIFY -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1819 dn: ou=sm2ou1,dc=example,dc=com
1820 changetype: modify
1821 add: description
1822 description: Modify$MNUM
1823
1824 EOF
1825 RC=$?
1826 if test $RC != 0 ; then
1827         echo "ldapmodify failed ($RC)!"
1828         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1829         exit $RC
1830 fi
1831 sleep 1
1832
1833 echo "Using ldapsearch to check replication to central master..."
1834 RC=32
1835 for i in 1 2 3 4 5; do
1836         RESULT=`$LDAPSEARCH -H $URI1 \
1837                 -s base -b "ou=sm2ou1,$BASEDN" \
1838                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1839         if test "x$RESULT" = "xOK" ; then
1840                 RC=0
1841                 break
1842         fi
1843         echo "Waiting $i seconds for syncrepl to receive changes..."
1844         sleep $i
1845 done
1846 if test $RC != 0 ; then
1847         echo "ldapsearch failed ($RC)!"
1848         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1849         exit $RC
1850 fi
1851
1852 echo "Using ldapsearch to check replication to site2 search..."
1853 RC=32
1854 for i in 1 2 3 4 5; do
1855         RESULT=`$LDAPSEARCH -H $URI6 \
1856                 -s base -b "ou=sm2ou1,$BASEDN" \
1857                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1858         if test "x$RESULT" = "xOK" ; then
1859                 RC=0
1860                 break
1861         fi
1862         echo "Waiting $i seconds for syncrepl to receive changes..."
1863         sleep $i
1864 done
1865 if test $RC != 0 ; then
1866         echo "ldapsearch failed ($RC)!"
1867         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1868         exit $RC
1869 fi
1870
1871 echo "Using ldapsearch to check no replication to site1 master..."
1872 for i in 1 2 3 4 5; do
1873         RESULT=`$LDAPSEARCH -H $URI2 \
1874                 -s base -b "ou=sm2ou1,$BASEDN" \
1875                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1876         if test "x$RESULT" = "xNOK" ; then
1877                 echo "Change was replicated to site2 search!"
1878                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1879                 exit 1
1880         fi
1881         sleep 1
1882 done
1883
1884 echo "Using ldapsearch to check no replication to central search..."
1885 for i in 1 2 3 4 5; do
1886         RESULT=`$LDAPSEARCH -H $URI4 \
1887                 -s base -b "ou=sm2ou1,$BASEDN" \
1888                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1889         if test "x$RESULT" = "xNOK" ; then
1890                 echo "Change was replicated to site2 search!"
1891                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1892                 exit 1
1893         fi
1894         sleep 1
1895 done
1896
1897 echo "Checking contextCSN after modify of first backend on site2 master..."
1898 . $TESTDIR/checkcsn.sh
1899
1900
1901 # TEST:
1902 # Test updates to the second backend on site2 master, which should only be
1903 # replicated to site2 search.  As always, contextCSN should be updated
1904 # everywhere:
1905 MNUM=`expr $MNUM + 1`
1906 echo "Using ldapmodify to modify second backend on site2 master..."
1907 $LDAPMODIFY -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1908 dn: ou=sm2ou2,dc=example,dc=com
1909 changetype: modify
1910 add: description
1911 description: Modify$MNUM
1912
1913 EOF
1914 RC=$?
1915 if test $RC != 0 ; then
1916         echo "ldapmodify failed ($RC)!"
1917         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1918         exit $RC
1919 fi
1920 sleep 1
1921
1922 echo "Using ldapsearch to check replication to site2 search..."
1923 RC=32
1924 for i in 1 2 3 4 5; do
1925         RESULT=`$LDAPSEARCH -H $URI6 \
1926                 -s base -b "ou=sm2ou2,$BASEDN" \
1927                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1928         if test "x$RESULT" = "xOK" ; then
1929                 RC=0
1930                 break
1931         fi
1932         echo "Waiting $i seconds for syncrepl to receive changes..."
1933         sleep $i
1934 done
1935 if test $RC != 0 ; then
1936         echo "ldapsearch failed ($RC)!"
1937         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1938         exit $RC
1939 fi
1940
1941 echo "Using ldapsearch to check no replication to central master..."
1942 for i in 1 2 3 4 5; do
1943         RESULT=`$LDAPSEARCH -H $URI4 \
1944                 -s base -b "ou=sm2ou2,$BASEDN" \
1945                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1946         if test "x$RESULT" = "xNOK" ; then
1947                 echo "Change was replicated to central search!"
1948                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1949                 exit 1
1950         fi
1951         sleep 1
1952 done
1953
1954 echo "Checking contextCSN after modify of second backend on site2 master..."
1955 . $TESTDIR/checkcsn.sh
1956
1957 # TEST:
1958 # Test that all contextCSN values are updated on the slaves when they
1959 # starts with an empty database.  Start site2 master first, then site2
1960 # search and finally central master so that the site2 search's syncrepl
1961 # connection has been set up when site2 master receives the database:
1962 echo "Stopping central master and site2 servers to test start with emtpy db..."
1963 kill -HUP  $SMC_PID $SM2_PID $SS2_PID
1964 for pid in $SMC_PID $SM2_PID $SS2_PID; do wait $pid ; done
1965 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
1966 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SM2_PID / /"`;
1967 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SS2_PID / /"`;
1968 SMC_PID=
1969 SM2_PID=
1970 SS2_PID=
1971 rm -rf $SM2_DIR/db/*
1972 rm -rf $SS2_DIR/db/*
1973
1974 echo "Starting site2 master slapd on TCP/IP port $PORT3..."
1975 cd $SM2_DIR
1976 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1977 SM2_PID=$!
1978 if test $WAIT != 0 ; then
1979         echo PID $SM2_PID
1980         read foo
1981 fi
1982 KILLPIDS="$KILLPIDS $SM2_PID"
1983 cd $TESTWD
1984 sleep 1
1985 echo "Using ldapsearch to check that site2 master slapd is running..."
1986 for i in 1 2 3 4 5; do
1987         $LDAPSEARCH -s base -b "" -H $URI3 \
1988                 'objectclass=*' > /dev/null 2>&1
1989         RC=$?
1990         test $RC = 0 && break
1991         echo "Waiting $i seconds for slapd to start..."
1992         sleep $i
1993 done
1994 if test $RC != 0 ; then
1995         echo "ldapsearch failed ($RC)!"
1996         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1997         exit $RC
1998 fi
1999
2000 echo "Starting site2 search slapd on TCP/IP port $PORT6..."
2001 cd $SS2_DIR
2002 $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING >> $LOG6 2>&1 &
2003 SS2_PID=$!
2004 if test $WAIT != 0 ; then
2005         echo PID $SS2_PID
2006         read foo
2007 fi
2008 KILLPIDS="$KILLPIDS $SS2_PID"
2009 cd $TESTWD
2010 sleep 1
2011 echo "Using ldapsearch to check that site2 search slapd is running..."
2012 for i in 1 2 3 4 5; do
2013         $LDAPSEARCH -s base -b "" -H $URI6 \
2014                 'objectclass=*' > /dev/null 2>&1
2015         RC=$?
2016         test $RC = 0 && break
2017         echo "Waiting $i seconds for slapd to start..."
2018         sleep $i
2019 done
2020 if test $RC != 0 ; then
2021         echo "ldapsearch failed ($RC)!"
2022         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2023         exit $RC
2024 fi
2025
2026 echo "Starting central master slapd on TCP/IP port $PORT1..."
2027 cd $SMC_DIR
2028 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2029 SMC_PID=$!
2030 if test $WAIT != 0 ; then
2031         echo PID $SMC_PID
2032         read foo
2033 fi
2034 KILLPIDS="$KILLPIDS $SMC_PID"
2035 cd $TESTWD
2036 sleep 1
2037 echo "Using ldapsearch to check that central master slapd is running..."
2038 for i in 1 2 3 4 5; do
2039         $LDAPSEARCH -s base -b "" -H $URI1 \
2040                 'objectclass=*' > /dev/null 2>&1
2041         RC=$?
2042         test $RC = 0 && break
2043         echo "Waiting $i seconds for slapd to start..."
2044         sleep $i
2045 done
2046 if test $RC != 0 ; then
2047         echo "ldapsearch failed ($RC)!"
2048         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2049         exit $RC
2050 fi
2051
2052 echo "Using ldapsearch to check that site2 master received base..."
2053 RC=32
2054 for i in 1 2 3 4 5; do
2055         RESULT=`$LDAPSEARCH -H $URI3 \
2056                 -s base -b "$BASEDN" \
2057                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2058         if test "x$RESULT" = "xOK" ; then
2059                 RC=0
2060                 break
2061         fi
2062         echo "Waiting $i seconds for syncrepl to receive changes..."
2063         sleep $i
2064 done
2065 if test $RC != 0 ; then
2066         echo "ldapsearch failed ($RC)!"
2067         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2068         exit $RC
2069 fi
2070
2071 echo "Using ldapsearch to check that site2 search received base..."
2072 RC=32
2073 for i in 1 2 3 4 5; do
2074         RESULT=`$LDAPSEARCH -H $URI6 \
2075                 -s base -b "$BASEDN" \
2076                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2077         if test "x$RESULT" = "xOK" ; then
2078                 RC=0
2079                 break
2080         fi
2081         echo "Waiting $i seconds for syncrepl to receive changes..."
2082         sleep $i
2083 done
2084 if test $RC != 0 ; then
2085         echo "ldapsearch failed ($RC)!"
2086         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2087         exit $RC
2088 fi
2089
2090 sleep $SLEEP1
2091
2092 echo "Checking contextCSN after site2 servers repopulated..."
2093 . $TESTDIR/checkcsn.sh
2094
2095 if test $ERRORS -ne 0; then
2096         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2097         echo "Found $ERRORS errors"
2098         exit $ERRORS
2099 fi
2100
2101 # TEST:
2102 # Adding syncrepl of the second site1 master backend on central master
2103 # will not initialize the database unless the contextCSN attribute is
2104 # stored in the suffix of the database and not the suffix of the glue
2105 # database:
2106 echo "Adding syncrepl of second site1 master backend on central master..."
2107 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
2108 dn: olcDatabase={4}$BACKEND,cn=config
2109 changetype: modify
2110 add: olcSyncRepl
2111 olcSyncRepl: rid=4 provider=$URI2 searchbase="ou=sm1ou2,$BASEDN"
2112   binddn="ou=sm1ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
2113   type=refreshAndPersist retry="$RETRY" timeout=1
2114 EOF
2115 RC=$?
2116 if test $RC != 0 ; then
2117         echo "ldapmodify failed to add syncrepl on central master ($RC)!"
2118         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2119         exit $RC
2120 fi
2121 sleep 1
2122
2123 echo "Using ldapsearch to check that central master received second site1 backend..."
2124 RC=32
2125 for i in 1 2 3 4 5; do
2126         RESULT=`$LDAPSEARCH -H $URI1 \
2127                 -s base -b "ou=sm1ou2,$BASEDN" \
2128                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2129         if test "x$RESULT" = "xOK" ; then
2130                 RC=0
2131                 break
2132         fi
2133         echo "Waiting $i seconds for syncrepl to receive changes..."
2134         sleep $i
2135 done
2136 if test $RC != 0 ; then
2137         echo "ERROR: Second site1 backend not replicated to central master"
2138         ERRORS=`expr $ERRORS + 1`
2139
2140         echo "Restarting central master slapd on TCP/IP port $PORT1..."
2141         kill -HUP $SMC_PID
2142         wait $SMC_PID
2143         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2144
2145         cd $SMC_DIR
2146         $SLAPD -F slapd.d -h $URI1 -c rid=4,csn=0 -d $LVL $TIMING >> $LOG1 2>&1 &
2147         SMC_PID=$!
2148         if test $WAIT != 0 ; then
2149                 echo PID $SMC_PID
2150                 read foo
2151         fi
2152         KILLPIDS="$KILLPIDS $SMC_PID"
2153         cd $TESTWD
2154         echo "Using ldapsearch to check that central master slapd is running..."
2155         for i in 1 2 3 4 5; do
2156                 $LDAPSEARCH -s base -b "" -H $URI1 \
2157                         'objectclass=*' > /dev/null 2>&1
2158                 RC=$?
2159                 test $RC = 0 && break
2160                 echo "Waiting $i seconds for slapd to start..."
2161                 sleep $i
2162         done
2163         if test $RC != 0 ; then
2164                 echo "ldapsearch failed ($RC)!"
2165                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2166                 exit $RC
2167         fi
2168
2169         echo "Using ldapsearch to check that central master received second site1 backend..."
2170         RC=32
2171         for i in 1 2 3 4 5; do
2172                 RESULT=`$LDAPSEARCH -H $URI1 \
2173                         -s base -b "ou=sm1ou2,$BASEDN" \
2174                         '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2175                 if test "x$RESULT" = "xOK" ; then
2176                         RC=0
2177                         break
2178                 fi
2179                 echo "Waiting $i seconds for syncrepl to receive changes..."
2180                 sleep $i
2181         done
2182         if test $RC != 0 ; then
2183                 echo "ldapsearch failed ($RC)!"
2184                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2185                 exit $RC
2186         fi
2187 fi
2188
2189 echo "Using ldapsearch to check that central search received second site1 backend..."
2190 RC=32
2191 for i in 1 2 3 4 5; do
2192         RESULT=`$LDAPSEARCH -H $URI4 \
2193                 -s base -b "ou=sm1ou2,$BASEDN" \
2194                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2195         if test "x$RESULT" = "xOK" ; then
2196                 RC=0
2197                 break
2198         fi
2199         echo "Waiting $i seconds for syncrepl to receive changes..."
2200         sleep $i
2201 done
2202 if test $RC != 0 ; then
2203         echo "ERROR: Second site1 backend not replicated to central search"
2204         ERRORS=`expr $ERRORS + 1`
2205
2206         echo "Restarting central search slapd on TCP/IP port $PORT4..."
2207         kill -HUP $SSC_PID
2208         wait $SSC_PID
2209         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SSC_PID / /"`;
2210
2211         cd $SSC_DIR
2212         $SLAPD -F slapd.d -h $URI4 -c rid=1,csn=0 -d $LVL $TIMING >> $LOG4 2>&1 &
2213         SSC_PID=$!
2214         if test $WAIT != 0 ; then
2215                 echo PID $SSC_PID
2216                 read foo
2217         fi
2218         KILLPIDS="$KILLPIDS $SSC_PID"
2219         cd $TESTWD
2220         echo "Using ldapsearch to check that central search slapd is running..."
2221         for i in 1 2 3 4 5; do
2222                 $LDAPSEARCH -s base -b "" -H $URI4 \
2223                         'objectclass=*' > /dev/null 2>&1
2224                 RC=$?
2225                 test $RC = 0 && break
2226                 echo "Waiting $i seconds for slapd to start..."
2227                 sleep $i
2228         done
2229         if test $RC != 0 ; then
2230                 echo "ldapsearch failed ($RC)!"
2231                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2232                 exit $RC
2233         fi
2234
2235         echo "Using ldapsearch to check that central search received second site1 backend..."
2236         RC=32
2237         for i in 1 2 3 4 5; do
2238                 RESULT=`$LDAPSEARCH -H $URI4 \
2239                         -s base -b "ou=sm1ou2,$BASEDN" \
2240                         '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2241                 if test "x$RESULT" = "xOK" ; then
2242                         RC=0
2243                         break
2244                 fi
2245                 echo "Waiting $i seconds for syncrepl to receive changes..."
2246                 sleep $i
2247         done
2248         if test $RC != 0 ; then
2249                 echo "ldapsearch failed ($RC)!"
2250                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2251                 exit $RC
2252         fi
2253 fi
2254
2255
2256 # TEST:
2257 # Run race tests when more than one backend is replicated from the same
2258 # producer.  This will usually fail long before 100 iterations unless
2259 # syncrepl stores the contextCSN in the suffix of its own database, and
2260 # that syncprov follows these rules before updating its own CSN when it
2261 # detects updates from syncrepl:
2262 # 1) A contextCSN value must have been stored in the suffix of all the
2263 #        syncrepl configured databases within the glued syncprov database.
2264 # 2) Of all contextCSN values stored by syncrepl with the same SID,
2265 #        syncprov must always select the one with the lowest csn value.
2266 test -z "$RACE_TESTS" && RACE_TESTS=10
2267 RACE_NUM=0
2268 RACE_ERROR=0
2269
2270 SUB_DN=ou=sub,ou=sm1ou2,dc=example,dc=com
2271
2272 while test $RACE_ERROR -eq 0 -a $RACE_NUM -lt $RACE_TESTS ; do
2273         RACE_NUM=`expr $RACE_NUM + 1`
2274         echo "Running $RACE_NUM of $RACE_TESTS syncrepl race tests..."
2275
2276         echo "Stopping central master..."
2277         kill -HUP $SMC_PID
2278         wait $SMC_PID
2279         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2280
2281         MNUM=`expr $MNUM + 1`
2282         echo "Using ldapadd to add entry on site1 master..."
2283         $LDAPADD -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
2284 dn: $SUB_DN
2285 objectClass: top
2286 objectClass: organizationalUnit
2287 ou: sub
2288
2289 EOF
2290         RC=$?
2291         if test $RC != 0 ; then
2292                 echo "ldapadd failed ($RC)!"
2293                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2294                 exit $RC
2295         fi
2296
2297         echo "Starting central master again..."
2298         cd $SMC_DIR
2299         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2300         SMC_PID=$!
2301         KILLPIDS="$KILLPIDS $SMC_PID"
2302         cd $TESTWD
2303         echo "Using ldapsearch to check that central master received entry..."
2304         for i in 1 2 3 4 5; do
2305                 $LDAPSEARCH -s base -b "$SUB_DN"  -H $URI1 > /dev/null 2>&1
2306                 RC=$?
2307                 test $RC = 0 && break
2308                 sleep $i
2309         done
2310         if test $RC != 0 ; then
2311                 echo "ERROR: entry not replicated to central master!"
2312                 RACE_ERROR=1
2313                 break
2314         fi
2315
2316         echo "Using ldapsearch to check that central search received entry..."
2317         for i in 1 2 3 4 5; do
2318                 $LDAPSEARCH -s base -b "$SUB_DN"  -H $URI4 > /dev/null 2>&1
2319                 RC=$?
2320                 test $RC = 0 && break
2321                 sleep $i
2322         done
2323         if test $RC != 0 ; then
2324                 echo "ERROR: entry not replicated to central master!"
2325                 RACE_ERROR=1
2326                 break
2327         fi
2328
2329         echo "Stopping central master..."
2330         kill -HUP $SMC_PID
2331         wait $SMC_PID
2332         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2333
2334         echo "Using ldapdelete to delete entry on site1 master..."
2335         $LDAPDELETE -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD "$SUB_DN"
2336         RC=$?
2337         if test $RC != 0 ; then
2338                 echo "ldapdelete failed ($RC)!"
2339                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2340                 exit $RC
2341         fi
2342
2343         echo "Starting central master again..."
2344         cd $SMC_DIR
2345         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2346         SMC_PID=$!
2347         KILLPIDS="$KILLPIDS $SMC_PID"
2348         cd $TESTWD
2349
2350         echo "Using ldapsearch to check that entry was deleted on central master..."
2351         RC=0
2352         for i in 1 2 3 4 5; do
2353                 $LDAPSEARCH -s base -b "$SUB_DN" -H $URI1 > /dev/null 2>&1
2354                 RC=$?
2355                 if test $RC = 32; then break; fi
2356                 sleep $i
2357         done
2358
2359         if test $RC != 32; then
2360                 if test $RC != 0; then
2361                         echo "ldapsearch failed ($RC)!"
2362                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2363                         exit $RC
2364                 fi
2365                 echo "ERROR: Entry not removed on central master!"
2366                 RACE_ERROR=1
2367                 break
2368         fi
2369
2370         echo "Using ldapsearch to check that entry was deleted on central search..."
2371         RC=0
2372         for i in 1 2 3 4 5; do
2373                 $LDAPSEARCH -s base -b "$SUB_DN" -H $URI4 > /dev/null 2>&1
2374                 RC=$?
2375                 if test $RC != 0; then break; fi
2376                 sleep $i
2377         done
2378
2379         if test $RC != 32; then
2380                 echo "ERROR: Entry not removed on central search! (RC=$RC)"
2381                 RACE_ERROR=1
2382                 break
2383         fi
2384 done
2385
2386 if test $RACE_ERROR != 0; then
2387         echo "Race error found after $RACE_NUM of $RACE_TESTS iterations"
2388         ERRORS=`expr $ERRORS + $RACE_ERROR`
2389 else
2390         echo "No race errors found after $RACE_TESTS iterations"
2391 fi
2392
2393 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2394
2395 if test $ERRORS -ne 0; then
2396         echo "Found $ERRORS errors"
2397         echo ">>>>>> Exiting with a false success status for now"
2398         exit 0
2399 fi
2400
2401 echo ">>>>> Test succeeded"
2402
2403 exit 0