]> git.sur5r.net Git - openldap/blob - tests/scripts/test058-syncrepl-asymmetric
Use provider instead of producer, as provider is a very specific term in replication
[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-2010 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 if test "$BACKEND" = ldif ; then
115         echo "$BACKEND backend does not support access controls, test skipped"
116         exit 0
117 fi
118
119 echo "running defines.sh"
120 . $SRCDIR/scripts/defines.sh
121
122 if test $SYNCPROV = syncprovno; then
123         echo "Syncrepl provider overlay not available, test skipped"
124         exit 0
125 fi
126
127 SMC_DIR=$TESTDIR/smc
128 SM1_DIR=$TESTDIR/sm1
129 SM2_DIR=$TESTDIR/sm2
130 SS1_DIR=$TESTDIR/ss1
131 SS2_DIR=$TESTDIR/ss2
132 SSC_DIR=$TESTDIR/ssc
133
134 mkdir -p $TESTDIR
135
136 for dir in $SMC_DIR $SM1_DIR $SM2_DIR $SS1_DIR $SS2_DIR $SSC_DIR; do
137         mkdir -p $dir $dir/slapd.d $dir/db
138 done
139
140 mkdir -p $SMC_DIR/ou1 $SMC_DIR/sm1ou1 $SMC_DIR/sm1ou2
141 mkdir -p $SMC_DIR/ou2 $SMC_DIR/sm2ou1
142 mkdir -p $SM1_DIR/ou1 $SM1_DIR/sm1ou1 $SM1_DIR/sm1ou2
143 mkdir -p $SM2_DIR/ou2 $SM2_DIR/sm1ou1 $SM2_DIR/sm2ou1 $SM2_DIR/sm2ou2
144
145 cd $TESTDIR
146
147 KILLPIDS=
148
149 $SLAPPASSWD -g -n >$CONFIGPWF
150
151 ID=1
152
153 if test $WAIT != 0 ; then
154         RETRY="1 60"
155 else
156         RETRY="1 10"
157 fi
158
159 echo "Initializing master configurations..."
160 for dir in $SMC_DIR $SM1_DIR $SM2_DIR; do
161         $SLAPADD -F $dir/slapd.d -n 0 <<EOF
162 dn: cn=config
163 objectClass: olcGlobal
164 cn: config
165 olcServerID: $ID
166
167 dn: olcDatabase={0}config,cn=config
168 objectClass: olcDatabaseConfig
169 olcDatabase: {0}config
170 olcRootPW:< file://$CONFIGPWF
171
172 EOF
173         ID=`expr $ID + 1`
174 done
175
176 echo "Initializing search configurations..."
177 for dir in $SS1_DIR $SS2_DIR $SSC_DIR; do
178         $SLAPADD -F $dir/slapd.d -n 0 <<EOF
179 dn: cn=config
180 objectClass: olcGlobal
181 cn: config
182
183 dn: olcDatabase={0}config,cn=config
184 objectClass: olcDatabaseConfig
185 olcDatabase: {0}config
186 olcRootPW:< file://$CONFIGPWF
187
188 EOF
189 done
190
191 echo "Starting central master slapd on TCP/IP port $PORT1..."
192 cd $SMC_DIR
193 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
194 SMC_PID=$!
195 if test $WAIT != 0 ; then
196         echo PID $SMC_PID
197         read foo
198 fi
199 KILLPIDS="$KILLPIDS $SMC_PID"
200 cd $TESTWD
201 sleep 1
202 echo "Using ldapsearch to check that central master slapd is running..."
203 for i in 1 2 3 4 5; do
204         $LDAPSEARCH -s base -b "" -H $URI1 \
205                 'objectclass=*' > /dev/null 2>&1
206         RC=$?
207         test $RC = 0 && break
208         echo "Waiting $i seconds for slapd to start..."
209         sleep $i
210 done
211 if test $RC != 0 ; then
212         echo "ldapsearch failed ($RC)!"
213         test $KILLSERVERS != no && kill -HUP $KILLPIDS
214         exit $RC
215 fi
216
217 echo "Starting site1 master slapd on TCP/IP port $PORT2..."
218 cd $SM1_DIR
219 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
220 SM1_PID=$!
221 if test $WAIT != 0 ; then
222         echo PID $SM1_PID
223         read foo
224 fi
225 KILLPIDS="$KILLPIDS $SM1_PID"
226 cd $TESTWD
227 sleep 1
228 echo "Using ldapsearch to check that site1 master is running..."
229 for i in 1 2 3 4 5; do
230         $LDAPSEARCH -s base -b "" -H $URI2 \
231                 'objectclass=*' > /dev/null 2>&1
232         RC=$?
233         test $RC = 0 && break
234         echo "Waiting $i seconds for slapd to start..."
235         sleep $i
236 done
237 if test $RC != 0 ; then
238         echo "ldapsearch failed ($RC)!"
239         test $KILLSERVERS != no && kill -HUP $KILLPIDS
240         exit $RC
241 fi
242
243 echo "Starting site2 master slapd on TCP/IP port $PORT3..."
244 cd $SM2_DIR
245 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
246 SM2_PID=$!
247 if test $WAIT != 0 ; then
248         echo PID $SM2_PID
249         read foo
250 fi
251 KILLPIDS="$KILLPIDS $SM2_PID"
252 cd $TESTWD
253 sleep 1
254 echo "Using ldapsearch to check that site2 master is running..."
255 for i in 1 2 3 4 5; do
256         $LDAPSEARCH -s base -b "" -H $URI3 \
257                 'objectclass=*' > /dev/null 2>&1
258         RC=$?
259         test $RC = 0 && break
260         echo "Waiting $i seconds for slapd to start..."
261         sleep $i
262 done
263 if test $RC != 0 ; then
264         echo "ldapsearch failed ($RC)!"
265         test $KILLSERVERS != no && kill -HUP $KILLPIDS
266         exit $RC
267 fi
268
269 echo "Starting central search slapd on TCP/IP port $PORT4..."
270 cd $SSC_DIR
271 $SLAPD -F slapd.d -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
272 SSC_PID=$!
273 if test $WAIT != 0 ; then
274         echo PID $SSC_PID
275         read foo
276 fi
277 KILLPIDS="$KILLPIDS $SSC_PID"
278 cd $TESTWD
279 sleep 1
280 echo "Using ldapsearch to check that central search slapd is running..."
281 for i in 1 2 3 4 5; do
282         $LDAPSEARCH -s base -b "" -H $URI4 \
283                 'objectclass=*' > /dev/null 2>&1
284         RC=$?
285         test $RC = 0 && break
286         echo "Waiting $i seconds for slapd to start..."
287         sleep $i
288 done
289 if test $RC != 0 ; then
290         echo "ldapsearch failed ($RC)!"
291         test $KILLSERVERS != no && kill -HUP $KILLPIDS
292         exit $RC
293 fi
294
295
296 echo "Starting site1 search slapd on TCP/IP port $PORT5..."
297 cd $SS1_DIR
298 $SLAPD -F slapd.d -h $URI5 -d $LVL $TIMING > $LOG5 2>&1 &
299 SS1_PID=$!
300 if test $WAIT != 0 ; then
301         echo PID $SS1_PID
302         read foo
303 fi
304 KILLPIDS="$KILLPIDS $SS1_PID"
305 cd $TESTWD
306 sleep 1
307 echo "Using ldapsearch to check that site1 search slapd is running..."
308 for i in 1 2 3 4 5; do
309         $LDAPSEARCH -s base -b "" -H $URI5 \
310                 'objectclass=*' > /dev/null 2>&1
311         RC=$?
312         test $RC = 0 && break
313         echo "Waiting $i seconds for slapd to start..."
314         sleep $i
315 done
316 if test $RC != 0 ; then
317         echo "ldapsearch failed ($RC)!"
318         test $KILLSERVERS != no && kill -HUP $KILLPIDS
319         exit $RC
320 fi
321
322
323 echo "Starting site2 search slapd on TCP/IP port $PORT6..."
324 cd $SS2_DIR
325 $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING > $LOG6 2>&1 &
326 SS2_PID=$!
327 if test $WAIT != 0 ; then
328         echo PID $SS2_PID
329         read foo
330 fi
331 KILLPIDS="$KILLPIDS $SS2_PID"
332 cd $TESTWD
333 sleep 1
334 echo "Using ldapsearch to check that site2 search slapd is running..."
335 for i in 1 2 3 4 5; do
336         $LDAPSEARCH -s base -b "" -H $URI6 \
337                 'objectclass=*' > /dev/null 2>&1
338         RC=$?
339         test $RC = 0 && break
340         echo "Waiting $i seconds for slapd to start..."
341         sleep $i
342 done
343 if test $RC != 0 ; then
344         echo "ldapsearch failed ($RC)!"
345         test $KILLSERVERS != no && kill -HUP $KILLPIDS
346         exit $RC
347 fi
348
349 for uri in $URI1 $URI2 $URI3 $URI4 $URI5 $URI6; do
350         echo "Adding schema on $uri..."
351         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
352 include: file://$ABS_SCHEMADIR/core.ldif
353
354 include: file://$ABS_SCHEMADIR/cosine.ldif
355
356 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
357
358 include: file://$ABS_SCHEMADIR/openldap.ldif
359
360 include: file://$ABS_SCHEMADIR/nis.ldif
361 EOF
362         RC=$?
363         if test $RC != 0 ; then
364                 echo "ldapadd failed for schema config ($RC)!"
365                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
366                 exit $RC
367         fi
368
369         [ "$BACKENDTYPE" = mod ] || continue
370
371         echo "Adding backend module on $uri..."
372         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
373 dn: cn=module,cn=config
374 objectClass: olcModuleList
375 cn: module
376 olcModulePath: ../../../servers/slapd/back-$BACKEND
377 olcModuleLoad: back_$BACKEND.la
378 EOF
379         RC=$?
380         if test $RC != 0 ; then
381                 echo "ldapadd failed for backend module ($RC)!"
382                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
383                 exit $RC
384         fi
385 done
386
387 echo "Adding database config on central master..."
388 if [ "$SYNCPROV" = syncprovmod ]; then
389         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
390 dn: cn=module,cn=config
391 objectClass: olcModuleList
392 cn: module
393 olcModulePath: ../../../servers/slapd/overlays
394 olcModuleLoad: syncprov.la
395
396 EOF
397         RC=$?
398         if test $RC != 0 ; then
399                 echo "ldapadd failed for moduleLoad ($RC)!"
400                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
401                 exit $RC
402         fi
403 fi
404
405 nullExclude="" nullOK="" wantNoObj=32
406 test $BACKEND = null && nullExclude="# " nullOK="OK" wantNoObj=0
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 ${nullExclude}objectClass: olc${BACKEND}Config
412 olcDatabase: {1}$BACKEND
413 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
431 olcDatabase: {1}$BACKEND
432 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
440 olcDatabase: {2}$BACKEND
441 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
449 olcDatabase: {3}$BACKEND
450 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
458 olcDatabase: {4}$BACKEND
459 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
467 olcDatabase: {5}$BACKEND
468 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
503 olcDatabase: {1}$BACKEND
504 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
520 olcDatabase: {1}$BACKEND
521 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
529 olcDatabase: {2}$BACKEND
530 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
539 olcDatabase: {3}$BACKEND
540 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
576 olcDatabase: {1}$BACKEND
577 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
594 olcDatabase: {1}$BACKEND
595 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
603 olcDatabase: {2}$BACKEND
604 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
612 olcDatabase: {3}$BACKEND
613 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
622 olcDatabase: {4}$BACKEND
623 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
726 olcDatabase: {1}$BACKEND
727 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
744 olcDatabase: {1}$BACKEND
745 ${nullExclude}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 ${nullExclude}objectClass: olc${BACKEND}Config
762 olcDatabase: {1}$BACKEND
763 ${nullExclude}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$nullOK" = "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$nullOK" = "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$nullOK" = "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$nullOK" = "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$nullOK" = "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$nullOK" = "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$nullOK" = "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 test $BACKEND = null && echo : > $TESTDIR/checkcsn.sh
1512
1513 chmod +x $TESTDIR/checkcsn.sh
1514
1515
1516 echo "Checking contextCSN after initial replication..."
1517 . $TESTDIR/checkcsn.sh
1518
1519 MNUM=1
1520
1521 # TEST:
1522 # Test that updates to the first backend on central master, which should
1523 # be replicated to all servers actually is so, and that the contextCSN is
1524 # updated everywhere:
1525 echo "Using ldapmodify to modify first backend on central master..."
1526 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1527 dn: ou=ou1,dc=example,dc=com
1528 changetype: modify
1529 add: description
1530 description: Modify$MNUM
1531
1532 EOF
1533 RC=$?
1534 if test $RC != 0 ; then
1535         echo "ldapmodify failed ($RC)!"
1536         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1537         exit $RC
1538 fi
1539 sleep 1
1540
1541 echo "Using ldapsearch to check replication to central search..."
1542 RC=32
1543 for i in 1 2 3 4 5; do
1544         RESULT=`$LDAPSEARCH -H $URI4 \
1545                 -s base -b "ou=ou1,$BASEDN" \
1546                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1547         if test "x$RESULT$nullOK" = "xOK" ; then
1548                 RC=0
1549                 break
1550         fi
1551         echo "Waiting $i seconds for syncrepl to receive changes..."
1552         sleep $i
1553 done
1554 if test $RC != 0 ; then
1555         echo "ldapsearch failed ($RC)!"
1556         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1557         exit $RC
1558 fi
1559
1560 echo "Using ldapsearch to check replication to site1 search..."
1561 RC=32
1562 for i in 1 2 3 4 5; do
1563         RESULT=`$LDAPSEARCH -H $URI5 \
1564                 -s base -b "ou=ou1,$BASEDN" \
1565                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1566         if test "x$RESULT$nullOK" = "xOK" ; then
1567                 RC=0
1568                 break
1569         fi
1570         echo "Waiting $i seconds for syncrepl to receive changes..."
1571         sleep $i
1572 done
1573 if test $RC != 0 ; then
1574         echo "ldapsearch failed ($RC)!"
1575         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1576         exit $RC
1577 fi
1578
1579 echo "Using ldapsearch to check replication to site2 search..."
1580 RC=32
1581 for i in 1 2 3 4 5; do
1582         RESULT=`$LDAPSEARCH -H $URI6 \
1583                 -s base -b "ou=ou1,$BASEDN" \
1584                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1585         if test "x$RESULT$nullOK" = "xOK" ; then
1586                 RC=0
1587                 break
1588         fi
1589         echo "Waiting $i seconds for syncrepl to receive changes..."
1590         sleep $i
1591 done
1592 if test $RC != 0 ; then
1593         echo "ldapsearch failed ($RC)!"
1594         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1595         exit $RC
1596 fi
1597
1598 echo "Checking contextCSN after modify of first backend on central master..."
1599 . $TESTDIR/checkcsn.sh
1600
1601 # TEST:
1602 # Test that updates to the second backend on central master is only
1603 # replicated to those search servers that should receive that backend.
1604 # The contextCSN should still be updated everywhere:
1605 MNUM=`expr $MNUM + 1`
1606 echo "Using ldapmodify to modify second backend on central master..."
1607 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1608 dn: ou=ou2,dc=example,dc=com
1609 changetype: modify
1610 add: description
1611 description: Modify$MNUM
1612
1613 EOF
1614 RC=$?
1615 if test $RC != 0 ; then
1616         echo "ldapmodify failed ($RC)!"
1617         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1618         exit $RC
1619 fi
1620 sleep 1
1621
1622 echo "Using ldapsearch to check replication to site2 search..."
1623 RC=32
1624 for i in 1 2 3 4 5; do
1625         RESULT=`$LDAPSEARCH -H $URI6 \
1626                 -s base -b "ou=ou2,$BASEDN" \
1627                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1628         if test "x$RESULT$nullOK" = "xOK" ; then
1629                 RC=0
1630                 break
1631         fi
1632         echo "Waiting $i seconds for syncrepl to receive changes..."
1633         sleep $i
1634 done
1635 if test $RC != 0 ; then
1636         echo "ldapsearch failed ($RC)!"
1637         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1638         exit $RC
1639 fi
1640
1641 echo "Using ldapsearch to check no replication to site1 master..."
1642 for i in 1 2 3 4 5; do
1643         RESULT=`$LDAPSEARCH -H $URI2 \
1644                 -s base -b "ou=ou2,$BASEDN" \
1645                 "(description=Modify$NMUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1646         if test "x$RESULT" = "xNOK" ; then
1647                 echo "Change was replicated to site1 search!"
1648                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1649                 exit 1
1650         fi
1651         sleep 1
1652 done
1653
1654 echo "Using ldapsearch to check no replication to central search..."
1655 for i in 1 2 3 4 5; do
1656         RESULT=`$LDAPSEARCH -H $URI4 \
1657                 -s base -b "ou=ou2,$BASEDN" \
1658                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1659         if test "x$RESULT" = "xNOK" ; then
1660                 echo "Change was replicated to central search!"
1661                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1662                 exit 1
1663         fi
1664         sleep 1
1665 done
1666
1667 echo "Checking contextCSN after modify of second backend on central master..."
1668 . $TESTDIR/checkcsn.sh
1669
1670 # TEST:
1671 # Test that updates to the first backend on site1 master, which should be
1672 # replicated everywhere except to central and site2 search.  The contextCSN
1673 # should be updated on all servers:
1674 MNUM=`expr $MNUM + 1`
1675 echo "Using ldapmodify to modify first backend on site1 master..."
1676 $LDAPMODIFY -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1677 dn: ou=sm1ou1,dc=example,dc=com
1678 changetype: modify
1679 add: description
1680 description: Modify$MNUM
1681
1682 EOF
1683 RC=$?
1684 if test $RC != 0 ; then
1685         echo "ldapmodify failed ($RC)!"
1686         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1687         exit $RC
1688 fi
1689 sleep 1
1690
1691 echo "Using ldapsearch to check replication to site1 search..."
1692 RC=32
1693 for i in 1 2 3 4 5; do
1694         RESULT=`$LDAPSEARCH -H $URI5 \
1695                 -s base -b "ou=sm1ou1,$BASEDN" \
1696                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1697         if test "x$RESULT$nullOK" = "xOK" ; then
1698                 RC=0
1699                 break
1700         fi
1701         echo "Waiting $i seconds for syncrepl to receive changes..."
1702         sleep $i
1703 done
1704 if test $RC != 0 ; then
1705         echo "ldapsearch failed ($RC)!"
1706         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1707         exit $RC
1708 fi
1709
1710 echo "Using ldapsearch to check replication to site2 master..."
1711 RC=32
1712 for i in 1 2 3 4 5; do
1713         RESULT=`$LDAPSEARCH -H $URI3 \
1714                 -s base -b "ou=sm1ou1,$BASEDN" \
1715                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1716         if test "x$RESULT$nullOK" = "xOK" ; then
1717                 RC=0
1718                 break
1719         fi
1720         echo "Waiting $i seconds for syncrepl to receive changes..."
1721         sleep $i
1722 done
1723 if test $RC != 0 ; then
1724         echo "ldapsearch failed ($RC)!"
1725         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1726         exit $RC
1727 fi
1728
1729 echo "Using ldapsearch to check no replication to site2 search..."
1730 for i in 1 2 3 4 5; do
1731         RESULT=`$LDAPSEARCH -H $URI6 \
1732                 -s base -b "ou=sm1ou2,$BASEDN" \
1733                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1734         if test "x$RESULT" = "xNOK" ; then
1735                 echo "Change was replicated to central search!"
1736                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1737                 exit 1
1738         fi
1739         sleep 1
1740 done
1741
1742 echo "Using ldapsearch to check no replication to central search..."
1743 for i in 1 2 3 4 5; do
1744         RESULT=`$LDAPSEARCH -H $URI4 \
1745                 -s base -b "ou=sm1ou2,$BASEDN" \
1746                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1747         if test "x$RESULT" = "xNOK" ; then
1748                 echo "Change was replicated to central search!"
1749                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1750                 exit 1
1751         fi
1752         sleep 1
1753 done
1754
1755 echo "Checking contextCSN after modify of first backend on site1 master..."
1756 . $TESTDIR/checkcsn.sh
1757
1758
1759 # TEST:
1760 # Test updates to the second backend on site1 master, which should only be
1761 # replicated to site1 search.  The contextCSN should be updated everywhere.
1762 MNUM=`expr $MNUM + 1`
1763 echo "Using ldapmodify to modify second backend on site1 master..."
1764 $LDAPMODIFY -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1765 dn: ou=sm1ou2,dc=example,dc=com
1766 changetype: modify
1767 add: description
1768 description: Modify$MNUM
1769
1770 EOF
1771 RC=$?
1772 if test $RC != 0 ; then
1773         echo "ldapmodify failed ($RC)!"
1774         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1775         exit $RC
1776 fi
1777 sleep 1
1778
1779
1780 echo "Using ldapsearch to check replication to site1 search..."
1781 RC=32
1782 for i in 1 2 3 4 5; do
1783         RESULT=`$LDAPSEARCH -H $URI5 \
1784                 -s base -b "ou=sm1ou2,$BASEDN" \
1785                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1786         if test "x$RESULT$nullOK" = "xOK" ; then
1787                 RC=0
1788                 break
1789         fi
1790         echo "Waiting $i seconds for syncrepl to receive changes..."
1791         sleep $i
1792 done
1793 if test $RC != 0 ; then
1794         echo "ldapsearch failed ($RC)!"
1795         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1796         exit $RC
1797 fi
1798
1799 echo "Using ldapsearch to check no replication to central master..."
1800 for i in 1 2 3 4 5; do
1801         RESULT=`$LDAPSEARCH -H $URI1 \
1802                 -s base -b "ou=sm1ou2,$BASEDN" \
1803                 "(description=Modify$NMUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1804         if test "x$RESULT" = "xNOK" ; then
1805                 echo "Change was replicated to site2 search!"
1806                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1807                 exit 1
1808         fi
1809         sleep 1
1810 done
1811
1812 echo "Checking contextCSN after modify of second backend on site1 master..."
1813 . $TESTDIR/checkcsn.sh
1814
1815
1816 # TEST:
1817 # Test updates to first backend on site2 master, which should be
1818 # replicated to the central servers, but not site1.  The contextCSN
1819 # should be updated everywhere:
1820 MNUM=`expr $MNUM + 1`
1821 echo "Using ldapmodify to modify first backend on site2 master..."
1822 $LDAPMODIFY -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1823 dn: ou=sm2ou1,dc=example,dc=com
1824 changetype: modify
1825 add: description
1826 description: Modify$MNUM
1827
1828 EOF
1829 RC=$?
1830 if test $RC != 0 ; then
1831         echo "ldapmodify failed ($RC)!"
1832         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1833         exit $RC
1834 fi
1835 sleep 1
1836
1837 echo "Using ldapsearch to check replication to central master..."
1838 RC=32
1839 for i in 1 2 3 4 5; do
1840         RESULT=`$LDAPSEARCH -H $URI1 \
1841                 -s base -b "ou=sm2ou1,$BASEDN" \
1842                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1843         if test "x$RESULT$nullOK" = "xOK" ; then
1844                 RC=0
1845                 break
1846         fi
1847         echo "Waiting $i seconds for syncrepl to receive changes..."
1848         sleep $i
1849 done
1850 if test $RC != 0 ; then
1851         echo "ldapsearch failed ($RC)!"
1852         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1853         exit $RC
1854 fi
1855
1856 echo "Using ldapsearch to check replication to site2 search..."
1857 RC=32
1858 for i in 1 2 3 4 5; do
1859         RESULT=`$LDAPSEARCH -H $URI6 \
1860                 -s base -b "ou=sm2ou1,$BASEDN" \
1861                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1862         if test "x$RESULT$nullOK" = "xOK" ; then
1863                 RC=0
1864                 break
1865         fi
1866         echo "Waiting $i seconds for syncrepl to receive changes..."
1867         sleep $i
1868 done
1869 if test $RC != 0 ; then
1870         echo "ldapsearch failed ($RC)!"
1871         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1872         exit $RC
1873 fi
1874
1875 echo "Using ldapsearch to check no replication to site1 master..."
1876 for i in 1 2 3 4 5; do
1877         RESULT=`$LDAPSEARCH -H $URI2 \
1878                 -s base -b "ou=sm2ou1,$BASEDN" \
1879                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1880         if test "x$RESULT" = "xNOK" ; then
1881                 echo "Change was replicated to site2 search!"
1882                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1883                 exit 1
1884         fi
1885         sleep 1
1886 done
1887
1888 echo "Using ldapsearch to check no replication to central search..."
1889 for i in 1 2 3 4 5; do
1890         RESULT=`$LDAPSEARCH -H $URI4 \
1891                 -s base -b "ou=sm2ou1,$BASEDN" \
1892                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1893         if test "x$RESULT" = "xNOK" ; then
1894                 echo "Change was replicated to site2 search!"
1895                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1896                 exit 1
1897         fi
1898         sleep 1
1899 done
1900
1901 echo "Checking contextCSN after modify of first backend on site2 master..."
1902 . $TESTDIR/checkcsn.sh
1903
1904
1905 # TEST:
1906 # Test updates to the second backend on site2 master, which should only be
1907 # replicated to site2 search.  As always, contextCSN should be updated
1908 # everywhere:
1909 MNUM=`expr $MNUM + 1`
1910 echo "Using ldapmodify to modify second backend on site2 master..."
1911 $LDAPMODIFY -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1912 dn: ou=sm2ou2,dc=example,dc=com
1913 changetype: modify
1914 add: description
1915 description: Modify$MNUM
1916
1917 EOF
1918 RC=$?
1919 if test $RC != 0 ; then
1920         echo "ldapmodify failed ($RC)!"
1921         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1922         exit $RC
1923 fi
1924 sleep 1
1925
1926 echo "Using ldapsearch to check replication to site2 search..."
1927 RC=32
1928 for i in 1 2 3 4 5; do
1929         RESULT=`$LDAPSEARCH -H $URI6 \
1930                 -s base -b "ou=sm2ou2,$BASEDN" \
1931                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1932         if test "x$RESULT$nullOK" = "xOK" ; then
1933                 RC=0
1934                 break
1935         fi
1936         echo "Waiting $i seconds for syncrepl to receive changes..."
1937         sleep $i
1938 done
1939 if test $RC != 0 ; then
1940         echo "ldapsearch failed ($RC)!"
1941         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1942         exit $RC
1943 fi
1944
1945 echo "Using ldapsearch to check no replication to central master..."
1946 for i in 1 2 3 4 5; do
1947         RESULT=`$LDAPSEARCH -H $URI4 \
1948                 -s base -b "ou=sm2ou2,$BASEDN" \
1949                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1950         if test "x$RESULT" = "xNOK" ; then
1951                 echo "Change was replicated to central search!"
1952                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1953                 exit 1
1954         fi
1955         sleep 1
1956 done
1957
1958 echo "Checking contextCSN after modify of second backend on site2 master..."
1959 . $TESTDIR/checkcsn.sh
1960
1961 # TEST:
1962 # Test that all contextCSN values are updated on the slaves when they
1963 # starts with an empty database.  Start site2 master first, then site2
1964 # search and finally central master so that the site2 search's syncrepl
1965 # connection has been set up when site2 master receives the database:
1966 echo "Stopping central master and site2 servers to test start with emtpy db..."
1967 kill -HUP  $SMC_PID $SM2_PID $SS2_PID
1968 for pid in $SMC_PID $SM2_PID $SS2_PID; do wait $pid ; done
1969 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
1970 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SM2_PID / /"`;
1971 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SS2_PID / /"`;
1972 SMC_PID=
1973 SM2_PID=
1974 SS2_PID=
1975 rm -rf $SM2_DIR/db/*
1976 rm -rf $SS2_DIR/db/*
1977
1978 echo "Starting site2 master slapd on TCP/IP port $PORT3..."
1979 cd $SM2_DIR
1980 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1981 SM2_PID=$!
1982 if test $WAIT != 0 ; then
1983         echo PID $SM2_PID
1984         read foo
1985 fi
1986 KILLPIDS="$KILLPIDS $SM2_PID"
1987 cd $TESTWD
1988 sleep 1
1989 echo "Using ldapsearch to check that site2 master slapd is running..."
1990 for i in 1 2 3 4 5; do
1991         $LDAPSEARCH -s base -b "" -H $URI3 \
1992                 'objectclass=*' > /dev/null 2>&1
1993         RC=$?
1994         test $RC = 0 && break
1995         echo "Waiting $i seconds for slapd to start..."
1996         sleep $i
1997 done
1998 if test $RC != 0 ; then
1999         echo "ldapsearch failed ($RC)!"
2000         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2001         exit $RC
2002 fi
2003
2004 echo "Starting site2 search slapd on TCP/IP port $PORT6..."
2005 cd $SS2_DIR
2006 $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING >> $LOG6 2>&1 &
2007 SS2_PID=$!
2008 if test $WAIT != 0 ; then
2009         echo PID $SS2_PID
2010         read foo
2011 fi
2012 KILLPIDS="$KILLPIDS $SS2_PID"
2013 cd $TESTWD
2014 sleep 1
2015 echo "Using ldapsearch to check that site2 search slapd is running..."
2016 for i in 1 2 3 4 5; do
2017         $LDAPSEARCH -s base -b "" -H $URI6 \
2018                 'objectclass=*' > /dev/null 2>&1
2019         RC=$?
2020         test $RC = 0 && break
2021         echo "Waiting $i seconds for slapd to start..."
2022         sleep $i
2023 done
2024 if test $RC != 0 ; then
2025         echo "ldapsearch failed ($RC)!"
2026         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2027         exit $RC
2028 fi
2029
2030 echo "Starting central master slapd on TCP/IP port $PORT1..."
2031 cd $SMC_DIR
2032 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2033 SMC_PID=$!
2034 if test $WAIT != 0 ; then
2035         echo PID $SMC_PID
2036         read foo
2037 fi
2038 KILLPIDS="$KILLPIDS $SMC_PID"
2039 cd $TESTWD
2040 sleep 1
2041 echo "Using ldapsearch to check that central master slapd is running..."
2042 for i in 1 2 3 4 5; do
2043         $LDAPSEARCH -s base -b "" -H $URI1 \
2044                 'objectclass=*' > /dev/null 2>&1
2045         RC=$?
2046         test $RC = 0 && break
2047         echo "Waiting $i seconds for slapd to start..."
2048         sleep $i
2049 done
2050 if test $RC != 0 ; then
2051         echo "ldapsearch failed ($RC)!"
2052         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2053         exit $RC
2054 fi
2055
2056 echo "Using ldapsearch to check that site2 master received base..."
2057 RC=32
2058 for i in 1 2 3 4 5; do
2059         RESULT=`$LDAPSEARCH -H $URI3 \
2060                 -s base -b "$BASEDN" \
2061                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2062         if test "x$RESULT$nullOK" = "xOK" ; then
2063                 RC=0
2064                 break
2065         fi
2066         echo "Waiting $i seconds for syncrepl to receive changes..."
2067         sleep $i
2068 done
2069 if test $RC != 0 ; then
2070         echo "ldapsearch failed ($RC)!"
2071         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2072         exit $RC
2073 fi
2074
2075 echo "Using ldapsearch to check that site2 search received base..."
2076 RC=32
2077 for i in 1 2 3 4 5; do
2078         RESULT=`$LDAPSEARCH -H $URI6 \
2079                 -s base -b "$BASEDN" \
2080                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2081         if test "x$RESULT$nullOK" = "xOK" ; then
2082                 RC=0
2083                 break
2084         fi
2085         echo "Waiting $i seconds for syncrepl to receive changes..."
2086         sleep $i
2087 done
2088 if test $RC != 0 ; then
2089         echo "ldapsearch failed ($RC)!"
2090         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2091         exit $RC
2092 fi
2093
2094 sleep $SLEEP1
2095
2096 echo "Checking contextCSN after site2 servers repopulated..."
2097 . $TESTDIR/checkcsn.sh
2098
2099 if test $ERRORS -ne 0; then
2100         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2101         echo "Found $ERRORS errors"
2102         exit $ERRORS
2103 fi
2104
2105 # TEST:
2106 # Adding syncrepl of the second site1 master backend on central master
2107 # will not initialize the database unless the contextCSN attribute is
2108 # stored in the suffix of the database and not the suffix of the glue
2109 # database:
2110 echo "Adding syncrepl of second site1 master backend on central master..."
2111 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
2112 dn: olcDatabase={4}$BACKEND,cn=config
2113 changetype: modify
2114 add: olcSyncRepl
2115 olcSyncRepl: rid=4 provider=$URI2 searchbase="ou=sm1ou2,$BASEDN"
2116   binddn="ou=sm1ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
2117   type=refreshAndPersist retry="$RETRY" timeout=1
2118 EOF
2119 RC=$?
2120 if test $RC != 0 ; then
2121         echo "ldapmodify failed to add syncrepl on central master ($RC)!"
2122         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2123         exit $RC
2124 fi
2125 sleep 1
2126
2127 echo "Using ldapsearch to check that central master received second site1 backend..."
2128 RC=32
2129 for i in 1 2 3 4 5; do
2130         RESULT=`$LDAPSEARCH -H $URI1 \
2131                 -s base -b "ou=sm1ou2,$BASEDN" \
2132                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2133         if test "x$RESULT$nullOK" = "xOK" ; then
2134                 RC=0
2135                 break
2136         fi
2137         echo "Waiting $i seconds for syncrepl to receive changes..."
2138         sleep $i
2139 done
2140 if test $RC != 0 ; then
2141         echo "ERROR: Second site1 backend not replicated to central master"
2142         ERRORS=`expr $ERRORS + 1`
2143
2144         echo "Restarting central master slapd on TCP/IP port $PORT1..."
2145         kill -HUP $SMC_PID
2146         wait $SMC_PID
2147         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2148
2149         cd $SMC_DIR
2150         $SLAPD -F slapd.d -h $URI1 -c rid=4,csn=0 -d $LVL $TIMING >> $LOG1 2>&1 &
2151         SMC_PID=$!
2152         if test $WAIT != 0 ; then
2153                 echo PID $SMC_PID
2154                 read foo
2155         fi
2156         KILLPIDS="$KILLPIDS $SMC_PID"
2157         cd $TESTWD
2158         echo "Using ldapsearch to check that central master slapd is running..."
2159         for i in 1 2 3 4 5; do
2160                 $LDAPSEARCH -s base -b "" -H $URI1 \
2161                         'objectclass=*' > /dev/null 2>&1
2162                 RC=$?
2163                 test $RC = 0 && break
2164                 echo "Waiting $i seconds for slapd to start..."
2165                 sleep $i
2166         done
2167         if test $RC != 0 ; then
2168                 echo "ldapsearch failed ($RC)!"
2169                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2170                 exit $RC
2171         fi
2172
2173         echo "Using ldapsearch to check that central master received second site1 backend..."
2174         RC=32
2175         for i in 1 2 3 4 5; do
2176                 RESULT=`$LDAPSEARCH -H $URI1 \
2177                         -s base -b "ou=sm1ou2,$BASEDN" \
2178                         '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2179                 if test "x$RESULT$nullOK" = "xOK" ; then
2180                         RC=0
2181                         break
2182                 fi
2183                 echo "Waiting $i seconds for syncrepl to receive changes..."
2184                 sleep $i
2185         done
2186         if test $RC != 0 ; then
2187                 echo "ldapsearch failed ($RC)!"
2188                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2189                 exit $RC
2190         fi
2191 fi
2192
2193 echo "Using ldapsearch to check that central search received second site1 backend..."
2194 RC=32
2195 for i in 1 2 3 4 5; do
2196         RESULT=`$LDAPSEARCH -H $URI4 \
2197                 -s base -b "ou=sm1ou2,$BASEDN" \
2198                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2199         if test "x$RESULT$nullOK" = "xOK" ; then
2200                 RC=0
2201                 break
2202         fi
2203         echo "Waiting $i seconds for syncrepl to receive changes..."
2204         sleep $i
2205 done
2206 if test $RC != 0 ; then
2207         echo "ERROR: Second site1 backend not replicated to central search"
2208         ERRORS=`expr $ERRORS + 1`
2209
2210         echo "Restarting central search slapd on TCP/IP port $PORT4..."
2211         kill -HUP $SSC_PID
2212         wait $SSC_PID
2213         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SSC_PID / /"`;
2214
2215         cd $SSC_DIR
2216         $SLAPD -F slapd.d -h $URI4 -c rid=1,csn=0 -d $LVL $TIMING >> $LOG4 2>&1 &
2217         SSC_PID=$!
2218         if test $WAIT != 0 ; then
2219                 echo PID $SSC_PID
2220                 read foo
2221         fi
2222         KILLPIDS="$KILLPIDS $SSC_PID"
2223         cd $TESTWD
2224         echo "Using ldapsearch to check that central search slapd is running..."
2225         for i in 1 2 3 4 5; do
2226                 $LDAPSEARCH -s base -b "" -H $URI4 \
2227                         'objectclass=*' > /dev/null 2>&1
2228                 RC=$?
2229                 test $RC = 0 && break
2230                 echo "Waiting $i seconds for slapd to start..."
2231                 sleep $i
2232         done
2233         if test $RC != 0 ; then
2234                 echo "ldapsearch failed ($RC)!"
2235                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2236                 exit $RC
2237         fi
2238
2239         echo "Using ldapsearch to check that central search received second site1 backend..."
2240         RC=32
2241         for i in 1 2 3 4 5; do
2242                 RESULT=`$LDAPSEARCH -H $URI4 \
2243                         -s base -b "ou=sm1ou2,$BASEDN" \
2244                         '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2245                 if test "x$RESULT$nullOK" = "xOK" ; then
2246                         RC=0
2247                         break
2248                 fi
2249                 echo "Waiting $i seconds for syncrepl to receive changes..."
2250                 sleep $i
2251         done
2252         if test $RC != 0 ; then
2253                 echo "ldapsearch failed ($RC)!"
2254                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2255                 exit $RC
2256         fi
2257 fi
2258
2259
2260 # TEST:
2261 # Run race tests when more than one backend is replicated from the same
2262 # provider.  This will usually fail long before 100 iterations unless
2263 # syncrepl stores the contextCSN in the suffix of its own database, and
2264 # that syncprov follows these rules before updating its own CSN when it
2265 # detects updates from syncrepl:
2266 # 1) A contextCSN value must have been stored in the suffix of all the
2267 #        syncrepl configured databases within the glued syncprov database.
2268 # 2) Of all contextCSN values stored by syncrepl with the same SID,
2269 #        syncprov must always select the one with the lowest csn value.
2270 test -z "$RACE_TESTS" && RACE_TESTS=10
2271 RACE_NUM=0
2272 RACE_ERROR=0
2273
2274 SUB_DN=ou=sub,ou=sm1ou2,dc=example,dc=com
2275
2276 while test $RACE_ERROR -eq 0 -a $RACE_NUM -lt $RACE_TESTS ; do
2277         RACE_NUM=`expr $RACE_NUM + 1`
2278         echo "Running $RACE_NUM of $RACE_TESTS syncrepl race tests..."
2279
2280         echo "Stopping central master..."
2281         kill -HUP $SMC_PID
2282         wait $SMC_PID
2283         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2284
2285         MNUM=`expr $MNUM + 1`
2286         echo "Using ldapadd to add entry on site1 master..."
2287         $LDAPADD -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
2288 dn: $SUB_DN
2289 objectClass: top
2290 objectClass: organizationalUnit
2291 ou: sub
2292
2293 EOF
2294         RC=$?
2295         if test $RC != 0 ; then
2296                 echo "ldapadd failed ($RC)!"
2297                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2298                 exit $RC
2299         fi
2300
2301         echo "Starting central master again..."
2302         cd $SMC_DIR
2303         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2304         SMC_PID=$!
2305         KILLPIDS="$KILLPIDS $SMC_PID"
2306         cd $TESTWD
2307         echo "Using ldapsearch to check that central master received entry..."
2308         for i in 1 2 3 4 5; do
2309                 $LDAPSEARCH -s base -b "$SUB_DN"  -H $URI1 > /dev/null 2>&1
2310                 RC=$?
2311                 test $RC = 0 && break
2312                 sleep $i
2313         done
2314         if test $RC != 0 ; then
2315                 echo "ERROR: entry not replicated to central master!"
2316                 RACE_ERROR=1
2317                 break
2318         fi
2319
2320         echo "Using ldapsearch to check that central search received entry..."
2321         for i in 1 2 3 4 5; do
2322                 $LDAPSEARCH -s base -b "$SUB_DN"  -H $URI4 > /dev/null 2>&1
2323                 RC=$?
2324                 test $RC = 0 && break
2325                 sleep $i
2326         done
2327         if test $RC != 0 ; then
2328                 echo "ERROR: entry not replicated to central master!"
2329                 RACE_ERROR=1
2330                 break
2331         fi
2332
2333         echo "Stopping central master..."
2334         kill -HUP $SMC_PID
2335         wait $SMC_PID
2336         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2337
2338         echo "Using ldapdelete to delete entry on site1 master..."
2339         $LDAPDELETE -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD "$SUB_DN"
2340         RC=$?
2341         if test $RC != 0 ; then
2342                 echo "ldapdelete failed ($RC)!"
2343                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2344                 exit $RC
2345         fi
2346
2347         echo "Starting central master again..."
2348         cd $SMC_DIR
2349         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2350         SMC_PID=$!
2351         KILLPIDS="$KILLPIDS $SMC_PID"
2352         cd $TESTWD
2353
2354         echo "Using ldapsearch to check that entry was deleted on central master..."
2355         RC=0
2356         for i in 1 2 3 4 5; do
2357                 $LDAPSEARCH -s base -b "$SUB_DN" -H $URI1 > /dev/null 2>&1
2358                 RC=$?
2359                 if test $RC = $wantNoObj; then break; fi
2360                 sleep $i
2361         done
2362
2363         if test $RC != $wantNoObj; then
2364                 if test $RC != 0; then
2365                         echo "ldapsearch failed ($RC)!"
2366                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2367                         exit $RC
2368                 fi
2369                 echo "ERROR: Entry not removed on central master!"
2370                 RACE_ERROR=1
2371                 break
2372         fi
2373
2374         echo "Using ldapsearch to check that entry was deleted on central search..."
2375         RC=0
2376         for i in 1 2 3 4 5; do
2377                 $LDAPSEARCH -s base -b "$SUB_DN" -H $URI4 > /dev/null 2>&1
2378                 RC=$?
2379                 if test $RC != 0; then break; fi
2380                 sleep $i
2381         done
2382
2383         if test $RC != $wantNoObj; then
2384                 echo "ERROR: Entry not removed on central search! (RC=$RC)"
2385                 RACE_ERROR=1
2386                 break
2387         fi
2388 done
2389
2390 if test $RACE_ERROR != 0; then
2391         echo "Race error found after $RACE_NUM of $RACE_TESTS iterations"
2392         ERRORS=`expr $ERRORS + $RACE_ERROR`
2393 else
2394         echo "No race errors found after $RACE_TESTS iterations"
2395 fi
2396
2397 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2398
2399 if test $ERRORS -ne 0; then
2400         echo "Found $ERRORS errors"
2401         echo ">>>>>> Exiting with a false success status for now"
2402         exit 0
2403 fi
2404
2405 echo ">>>>> Test succeeded"
2406
2407 exit 0