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