]> git.sur5r.net Git - openldap/blob - tests/scripts/test045-syncreplication-proxied
ITS#5086
[openldap] / tests / scripts / test045-syncreplication-proxied
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2007 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 if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
17         echo "Test does not support $BACKEND"
18         exit 0
19 fi
20
21 # test now handles known issues
22 #if test x"$PROXYSYNC" = x ; then
23 #       echo "Test disabled; set PROXYSYNC=yes to enable"
24 #       exit 0
25 #fi
26
27 echo "running defines.sh"
28 . $SRCDIR/scripts/defines.sh
29
30 if test $BACKLDAP = ldapno; then 
31         echo "LDAP backend not available, test skipped"
32         exit 0
33 fi 
34
35 if test $SYNCPROV = syncprovno; then 
36         echo "Syncrepl provider overlay not available, test skipped"
37         exit 0
38 fi 
39
40 if test $MONITORDB = no; then 
41         echo "Monitor backend not available, test skipped"
42         exit 0
43 fi 
44
45 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
46
47 #
48 # Test replication:
49 # - start master
50 # - start slave
51 # - populate over ldap
52 # - perform some modifies and deleted
53 # - attempt to modify the slave (referral or chain)
54 # - retrieve database over ldap and compare against expected results
55 #
56
57 echo "Starting master slapd on TCP/IP port $PORT1..."
58 . $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1
59 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
60 MASTERPID=$!
61 if test $WAIT != 0 ; then
62     echo MASTERPID $MASTERPID
63     read foo
64 fi
65 KILLPIDS="$MASTERPID"
66
67 sleep 1
68
69 echo "Using ldapsearch to check that master slapd is running..."
70 for i in 0 1 2 3 4 5; do
71         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
72                 '(objectClass=*)' > /dev/null 2>&1
73         RC=$?
74         if test $RC = 0 ; then
75                 break
76         fi
77         echo "Waiting 5 seconds for slapd to start..."
78         sleep 5
79 done
80
81 if test $RC != 0 ; then
82         echo "ldapsearch failed ($RC)!"
83         test $KILLSERVERS != no && kill -HUP $KILLPIDS
84         exit $RC
85 fi
86
87 echo "Using ldapadd to create the context prefix entry in the master..."
88 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
89         $LDIFORDEREDCP > /dev/null 2>&1
90 RC=$?
91 if test $RC != 0 ; then
92         echo "ldapadd failed ($RC)!"
93         test $KILLSERVERS != no && kill -HUP $KILLPIDS
94         exit $RC
95 fi
96
97 echo "Starting slave slapd on TCP/IP port $PORT2..."
98 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF > $CONF2
99 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
100 SLAVEPID=$!
101 if test $WAIT != 0 ; then
102     echo SLAVEPID $SLAVEPID
103     read foo
104 fi
105 KILLPIDS="$MASTERPID $SLAVEPID"
106
107 sleep 1
108
109 echo "Using ldapsearch to check that slave slapd is running..."
110 for i in 0 1 2 3 4 5; do
111         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
112                 '(objectClass=*)' > /dev/null 2>&1
113         RC=$?
114         if test $RC = 0 ; then
115                 break
116         fi
117         echo "Waiting 5 seconds for slapd to start..."
118         sleep 5
119 done
120
121 if test $RC != 0 ; then
122         echo "ldapsearch failed ($RC)!"
123         test $KILLSERVERS != no && kill -HUP $KILLPIDS
124         exit $RC
125 fi
126
127 echo "Starting proxy slapd on TCP/IP port $PORT3..."
128 . $CONFFILTER $BACKEND $MONITORDB < $PLSRSLAVECONF > $CONF3
129 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
130 PROXYPID=$!
131 if test $WAIT != 0 ; then
132     echo PROXYPID $PROXYPID
133     read foo
134 fi
135 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
136
137 sleep 1
138
139 echo "Using ldapsearch to check that proxy slapd is running..."
140 for i in 0 1 2 3 4 5; do
141         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
142                 '(objectClass=*)' > /dev/null 2>&1
143         RC=$?
144         if test $RC = 0 || test $RC = 53 ; then
145                 break
146         fi
147         echo "Waiting 5 seconds for slapd to start..."
148         sleep 5
149 done
150
151 case $RC in
152 0 )
153         echo "ldapsearch should have failed ($RC)!"
154         test $KILLSERVERS != no && kill -HUP $KILLPIDS
155         exit -1
156         ;;
157 53)
158         ;;
159 *)
160         echo "ldapsearch failed ($RC)!"
161         test $KILLSERVERS != no && kill -HUP $KILLPIDS
162         exit $RC
163         ;;
164 esac
165
166 CHECK=1
167 echo "$CHECK > Using ldapadd to populate the master directory..."
168 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
169         $LDIFORDEREDNOCP > /dev/null 2>&1
170 RC=$?
171 if test $RC != 0 ; then
172         echo "ldapadd failed ($RC)!"
173         test $KILLSERVERS != no && kill -HUP $KILLPIDS
174         exit $RC
175 fi
176
177 # get master contextCSN
178 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
179         '(objectClass=*)' -s base contextCSN > "${MASTEROUT}.$CHECK" 2>&1
180 RC=$?
181 if test $RC != 0 ; then
182         echo "ldapsearch failed at master ($RC)!"
183         test $KILLSERVERS != no && kill -HUP $KILLPIDS
184         exit $RC
185 fi
186
187 # check slave contextCSN
188 sleep 1
189 for i in 1 2 3; do
190         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
191                 '(objectClass=*)' -s base contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
192         RC=$?
193
194         if test $RC != 0 ; then
195                 echo "ldapsearch failed at slave ($RC)!"
196                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
197                 exit $RC
198         fi
199
200         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
201
202         if test $? = 0 ; then
203                 break
204         fi
205
206         SLEEP=5
207         echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
208         sleep $SLEEP
209 done
210
211 #echo "Using ldapsearch to read all the entries from the master..."
212 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
213         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
214 RC=$?
215
216 if test $RC != 0 ; then
217         echo "ldapsearch failed at master ($RC)!"
218         test $KILLSERVERS != no && kill -HUP $KILLPIDS
219         exit $RC
220 fi
221
222 #echo "Using ldapsearch to read all the entries from the slave..."
223 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
224         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
225 RC=$?
226
227 if test $RC != 0 ; then
228         echo "ldapsearch failed at slave ($RC)!"
229         test $KILLSERVERS != no && kill -HUP $KILLPIDS
230         exit $RC
231 fi
232
233 #echo "Filtering master results..."
234 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
235 #echo "Filtering slave results..."
236 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
237
238 echo "$CHECK < Comparing retrieved entries from master and slave..."
239 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
240
241 if test $? != 0 ; then
242         echo "test failed - master and slave databases differ"
243         test $KILLSERVERS != no && kill -HUP $KILLPIDS
244         exit 1
245 fi
246
247 CHECK=`expr $CHECK + 1`
248 SLEEP=10
249 echo "$CHECK > Stopping the provider, sleeping $SLEEP seconds and restarting it..."
250 kill -HUP "$MASTERPID"
251 wait $MASTERPID
252 sleep $SLEEP
253
254 echo "======================= RESTART =======================" >> $LOG1
255 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
256 MASTERPID=$!
257 if test $WAIT != 0 ; then
258     echo MASTERPID $MASTERPID
259     read foo
260 fi
261 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
262
263 sleep 1
264
265 echo "Using ldapsearch to check that master slapd is running..."
266 for i in 0 1 2 3 4 5; do
267         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
268                 '(objectClass=*)' > /dev/null 2>&1
269         RC=$?
270         if test $RC = 0 ; then
271                 break
272         fi
273         echo "Waiting 5 seconds for slapd to start..."
274         sleep 5
275 done
276
277 if test $RC != 0 ; then
278         echo "ldapsearch failed ($RC)!"
279         test $KILLSERVERS != no && kill -HUP $KILLPIDS
280         exit $RC
281 fi
282
283 echo "Using ldapmodify to modify master directory..."
284
285 #
286 # Do some modifications
287 #
288
289 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
290         $TESTOUT 2>&1 << EOMODS
291 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
292 changetype: modify
293 add: drink
294 drink: Orange Juice
295 -
296 delete: sn
297 sn: Jones
298 -
299 add: sn
300 sn: Jones
301
302 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
303 changetype: modify
304 replace: drink
305 drink: Iced Tea
306
307 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
308 changetype: modify
309 delete: uniquemember
310 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
311 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
312 -
313 add: uniquemember
314 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
315 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
316
317 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
318  =com
319 changetype: modify
320 delete: cn
321 cn: Biiff Jensen
322
323 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
324 changetype: add
325 objectclass: OpenLDAPperson
326 cn: Gern Jensen
327 sn: Jensen
328 uid: gjensen
329 title: Chief Investigator, ITD
330 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
331 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
332 drink: Coffee
333 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
334 description: Very odd
335 facsimiletelephonenumber: +1 313 555 7557
336 telephonenumber: +1 313 555 8343
337 mail: gjensen@mailgw.example.com
338 homephone: +1 313 555 8844
339
340 dn: ou=Retired, ou=People, dc=example,dc=com
341 changetype: add
342 objectclass: organizationalUnit
343 ou: Retired
344
345 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
346 changetype: add
347 objectclass: OpenLDAPperson
348 cn: Rosco P. Coltrane
349 sn: Coltrane
350 uid: rosco
351 description: Fat tycoon
352
353 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
354 changetype: modrdn
355 newrdn: cn=Rosco P. Coltrane
356 deleteoldrdn: 1
357 newsuperior: ou=Retired, ou=People, dc=example,dc=com
358
359 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
360 changetype: delete
361 EOMODS
362
363 RC=$?
364 if test $RC != 0 ; then
365         echo "ldapmodify failed ($RC)!"
366         test $KILLSERVERS != no && kill -HUP $KILLPIDS
367         exit $RC
368 fi
369
370 # get master contextCSN
371 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
372         '(objectClass=*)' -s base contextCSN > "${MASTEROUT}.$CHECK" 2>&1
373 RC=$?
374 if test $RC != 0 ; then
375         echo "ldapsearch failed at master ($RC)!"
376         test $KILLSERVERS != no && kill -HUP $KILLPIDS
377         exit $RC
378 fi
379
380 # check slave contextCSN
381 for i in 1 2 3; do
382         SLEEP=5
383         echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
384         sleep $SLEEP
385
386         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
387                 '(objectClass=*)' -s base contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
388         RC=$?
389
390         if test $RC != 0 ; then
391                 echo "ldapsearch failed at slave ($RC)!"
392                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
393                 exit $RC
394         fi
395
396         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
397
398         if test $? = 0 ; then
399                 break
400         fi
401 done
402
403 #echo "Using ldapsearch to read all the entries from the master..."
404 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
405         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
406 RC=$?
407
408 if test $RC != 0 ; then
409         echo "ldapsearch failed at master ($RC)!"
410         test $KILLSERVERS != no && kill -HUP $KILLPIDS
411         exit $RC
412 fi
413
414 #echo "Using ldapsearch to read all the entries from the slave..."
415 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
416         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
417 RC=$?
418
419 if test $RC != 0 ; then
420         echo "ldapsearch failed at slave ($RC)!"
421         test $KILLSERVERS != no && kill -HUP $KILLPIDS
422         exit $RC
423 fi
424
425 #echo "Filtering master results..."
426 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
427 #echo "Filtering slave results..."
428 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
429
430 echo "$CHECK < Comparing retrieved entries from master and slave..."
431 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
432
433 if test $? != 0 ; then
434         echo "test failed - master and slave databases differ"
435         test $KILLSERVERS != no && kill -HUP $KILLPIDS
436         exit 1
437 fi
438
439 CHECK=`expr $CHECK + 1`
440 echo "$CHECK > Stopping proxy to test recovery..."
441 kill -HUP $PROXYPID
442 wait $PROXYPID
443
444 echo "Modifying more entries on the master..."
445 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
446         $TESTOUT 2>&1 << EOMODS
447 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
448 changetype: modify
449 add: description
450 description: proxy is down...
451
452 dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
453 changetype: add
454 objectclass: OpenLDAPperson
455 sn: Kirk
456 uid: jtk
457 cn: James T. Kirk
458
459 dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
460 changetype: add
461 objectclass: OpenLDAPperson
462 sn: Hooker
463 uid: tjh
464 cn: Tiberius J. Hooker
465
466 EOMODS
467
468 echo "Restarting proxy..."
469 echo "======================= RESTART =======================" >> $LOG3
470 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
471 PROXYPID=$!
472 if test $WAIT != 0 ; then
473     echo PROXYPID $PROXYPID
474     read foo
475 fi
476 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
477
478 # get master contextCSN
479 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
480         '(objectClass=*)' -s base contextCSN > "${MASTEROUT}.$CHECK" 2>&1
481 RC=$?
482 if test $RC != 0 ; then
483         echo "ldapsearch failed at master ($RC)!"
484         test $KILLSERVERS != no && kill -HUP $KILLPIDS
485         exit $RC
486 fi
487
488 # check slave contextCSN
489 for i in 1 2 3 4 5; do
490         SLEEP=5
491         echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
492         sleep $SLEEP
493
494         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
495                 '(objectClass=*)' -s base contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
496         RC=$?
497
498         if test $RC != 0 ; then
499                 echo "ldapsearch failed at slave ($RC)!"
500                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
501                 exit $RC
502         fi
503
504         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
505
506         if test $? = 0 ; then
507                 break
508         fi
509 done
510
511 #echo "Using ldapsearch to read all the entries from the master..."
512 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
513         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
514 RC=$?
515
516 if test $RC != 0 ; then
517         echo "ldapsearch failed at master ($RC)!"
518         test $KILLSERVERS != no && kill -HUP $KILLPIDS
519         exit $RC
520 fi
521
522 #echo "Using ldapsearch to read all the entries from the slave..."
523 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
524         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
525 RC=$?
526
527 if test $RC != 0 ; then
528         echo "ldapsearch failed at slave ($RC)!"
529         test $KILLSERVERS != no && kill -HUP $KILLPIDS
530         exit $RC
531 fi
532
533 #echo "Filtering master results..."
534 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
535 #echo "Filtering slave results..."
536 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
537
538 echo "$CHECK < Comparing retrieved entries from master and slave..."
539 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
540
541 if test $? != 0 ; then
542         echo "test failed - master and slave databases differ"
543         test $KILLSERVERS != no && kill -HUP $KILLPIDS
544         exit 1
545 fi
546
547 CHECK=`expr $CHECK + 1`
548 echo "$CHECK > Try updating the slave slapd..."
549 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
550         $TESTOUT 2>&1 << EOMODS
551 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
552 changetype: modify
553 add: description
554 description: This write must fail because directed to a shadow context,
555 description: unless the chain overlay is configured appropriately ;)
556
557 EOMODS
558
559 RC=$?
560 if test $RC != 0 ; then
561         echo "ldapmodify failed ($RC)!"
562         test $KILLSERVERS != no && kill -HUP $KILLPIDS
563         exit $RC
564 fi
565
566 # get master contextCSN
567 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
568         '(objectClass=*)' -s base contextCSN > "${MASTEROUT}.$CHECK" 2>&1
569 RC=$?
570 if test $RC != 0 ; then
571         echo "ldapsearch failed at master ($RC)!"
572         test $KILLSERVERS != no && kill -HUP $KILLPIDS
573         exit $RC
574 fi
575
576 # check slave contextCSN
577 sleep 1
578
579 for i in 1 2 3; do
580         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
581                 '(objectClass=*)' -s base contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
582         RC=$?
583
584         if test $RC != 0 ; then
585                 echo "ldapsearch failed at slave ($RC)!"
586                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
587                 exit $RC
588         fi
589
590         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
591
592         if test $? = 0 ; then
593                 break
594         fi
595
596         SLEEP=5
597         echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
598         sleep $SLEEP
599 done
600
601 #echo "Using ldapsearch to read all the entries from the master..."
602 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
603         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
604 RC=$?
605
606 if test $RC != 0 ; then
607         echo "ldapsearch failed at master ($RC)!"
608         test $KILLSERVERS != no && kill -HUP $KILLPIDS
609         exit $RC
610 fi
611
612 #echo "Using ldapsearch to read all the entries from the slave..."
613 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
614 '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
615 RC=$?
616
617 if test $RC != 0 ; then
618         echo "ldapsearch failed at slave ($RC)!"
619         test $KILLSERVERS != no && kill -HUP $KILLPIDS
620         exit $RC
621 fi
622
623 #echo "Filtering master results..."
624 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
625 #echo "Filtering slave results..."
626 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
627
628 echo "$CHECK < Comparing retrieved entries from master and slave..."
629 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
630
631 if test $? != 0 ; then
632         echo "test failed - master and slave databases differ"
633         test $KILLSERVERS != no && kill -HUP $KILLPIDS
634         exit 1
635 fi
636
637 CHECK=`expr $CHECK + 1`
638 echo "$CHECK > Stopping consumer to test recovery..."
639 kill -HUP $SLAVEPID
640 wait $SLAVEPID
641
642 echo "Modifying more entries on the master..."
643 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
644         $TESTOUT 2>&1 << EOMODS
645 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
646 changetype: modify
647 add: drink
648 drink: Mad Dog 20/20
649
650 EOMODS
651
652 SLEEP=10
653 echo "Waiting $SLEEP seconds for syncrepl to retry..."
654 sleep $SLEEP
655
656 echo "Restarting consumer..."
657 echo "======================= RESTART =======================" >> $LOG2
658 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
659 SLAVEPID=$!
660 if test $WAIT != 0 ; then
661     echo SLAVEPID $SLAVEPID
662     read foo
663 fi
664 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
665
666 # get master contextCSN
667 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
668         '(objectClass=*)' -s base contextCSN > "${MASTEROUT}.$CHECK" 2>&1
669 RC=$?
670 if test $RC != 0 ; then
671         echo "ldapsearch failed at master ($RC)!"
672         test $KILLSERVERS != no && kill -HUP $KILLPIDS
673         exit $RC
674 fi
675
676 # check slave contextCSN
677
678 for i in 1 2 3 4 5; do
679         SLEEP=5
680         echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
681         sleep $SLEEP
682
683         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
684                 '(objectClass=*)' -s base contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
685         RC=$?
686
687         if test $RC != 0 ; then
688                 echo "ldapsearch failed at slave ($RC)!"
689                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
690                 exit $RC
691         fi
692
693         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
694
695         if test $? = 0 ; then
696                 break
697         fi
698 done
699
700 #echo "Using ldapsearch to read all the entries from the master..."
701 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
702         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
703 RC=$?
704
705 if test $RC != 0 ; then
706         echo "ldapsearch failed at master ($RC)!"
707         test $KILLSERVERS != no && kill -HUP $KILLPIDS
708         exit $RC
709 fi
710
711 #echo "Using ldapsearch to read all the entries from the slave..."
712 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
713         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
714 RC=$?
715
716 if test $RC != 0 ; then
717         echo "ldapsearch failed at slave ($RC)!"
718         test $KILLSERVERS != no && kill -HUP $KILLPIDS
719         exit $RC
720 fi
721
722 #echo "Filtering master results..."
723 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
724 #echo "Filtering slave results..."
725 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
726
727 echo "$CHECK < Comparing retrieved entries from master and slave..."
728 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
729
730 if test $? != 0 ; then
731         # FIXME: keep the original workaround in place, in case we needed again
732         if test 1 = 1 ; then
733                 echo "test failed - master and slave databases differ"
734                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
735                 exit 1
736         fi
737
738         echo "  test failed - master and slave databases differ (ignored by now)"
739         echo "  Stopping proxy to see if it auto-recovers..."
740         kill -HUP $PROXYPID
741         wait $PROXYPID
742
743         echo "  ${CHECK}.1 > Restarting proxy..."
744         echo "======================= RESTART =======================" >> $LOG3
745         $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
746         PROXYPID=$!
747         if test $WAIT != 0 ; then
748                 echo PROXYPID $PROXYPID
749                 read foo
750         fi
751         KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
752
753         SLEEP=15
754         echo "  Waiting $SLEEP seconds for syncrepl to receive changes..."
755         sleep $SLEEP
756
757         #echo "Using ldapsearch to read all the entries from the slave..."
758         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
759                 '(objectClass=*)' > "${SLAVEOUT}.5.1" 2>&1
760         RC=$?
761
762         if test $RC != 0 ; then
763                 echo "  ldapsearch failed at slave ($RC)!"
764                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
765                 exit $RC
766         fi
767
768         #echo "Filtering slave results..."
769         . $LDIFFILTER < "${SLAVEOUT}.5.1" > $SLAVEFLT
770
771         echo "  ${CHECK}.1 < Comparing retrieved entries from master and slave..."
772         $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
773
774         if test $? != 0 ; then
775                 echo "  test failed - master and slave databases differ"
776                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
777                 exit 1
778         fi
779 fi
780
781 #
782 # Modifications formerly known to fail
783 #
784 CHECK=`expr $CHECK + 1`
785 echo "$CHECK > Performing modifications that were formerly known to fail..."
786 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
787         $TESTOUT 2>&1 << EOMODS
788 # First, back out previous change
789 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
790 changetype: modify
791 delete: drink
792 drink: Mad Dog 20/20
793
794 # From now on, perform modifications that were formerly known to fail
795 dn: cn=All Staff,ou=Groups,dc=example,dc=com
796 changetype: modify
797 delete: description
798
799 EOMODS
800
801 RC=$?
802 if test $RC != 0 ; then
803         echo "ldapmodify failed ($RC)!"
804         test $KILLSERVERS != no && kill -HUP $KILLPIDS
805         exit $RC
806 fi
807
808 # get master contextCSN
809 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
810         '(objectClass=*)' -s base contextCSN > "${MASTEROUT}.$CHECK" 2>&1
811 RC=$?
812 if test $RC != 0 ; then
813         echo "ldapsearch failed at master ($RC)!"
814         test $KILLSERVERS != no && kill -HUP $KILLPIDS
815         exit $RC
816 fi
817
818 # check slave contextCSN
819 sleep 1
820 for i in 1 2 3; do
821         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
822                 '(objectClass=*)' -s base contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
823         RC=$?
824
825         if test $RC != 0 ; then
826                 echo "ldapsearch failed at slave ($RC)!"
827                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
828                 exit $RC
829         fi
830
831         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
832
833         if test $? = 0 ; then
834                 break
835         fi
836
837         SLEEP=5
838         echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
839         sleep $SLEEP
840 done
841
842 #echo "Using ldapsearch to read all the entries from the master..."
843 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
844         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
845 RC=$?
846
847 if test $RC != 0 ; then
848         echo "ldapsearch failed at master ($RC)!"
849         test $KILLSERVERS != no && kill -HUP $KILLPIDS
850         exit $RC
851 fi
852
853 #echo "Using ldapsearch to read all the entries from the slave..."
854 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
855         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
856 RC=$?
857
858 if test $RC != 0 ; then
859         echo "ldapsearch failed at slave ($RC)!"
860         test $KILLSERVERS != no && kill -HUP $KILLPIDS
861         exit $RC
862 fi
863
864 #echo "Filtering master results..."
865 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
866 #echo "Filtering slave results..."
867 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
868
869 echo "$CHECK < Comparing retrieved entries from master and slave..."
870 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
871
872 if test $? != 0 ; then
873         echo "test failed - master and slave databases differ (ignored by now)"
874         #echo "test failed - master and slave databases differ"
875         #test $KILLSERVERS != no && kill -HUP $KILLPIDS
876         #exit 1
877 fi
878
879 test $KILLSERVERS != no && kill -HUP $KILLPIDS
880
881 echo ">>>>> Test succeeded"
882
883 test $KILLSERVERS != no && wait
884
885 exit 0