]> git.sur5r.net Git - openldap/blob - tests/scripts/test045-syncreplication-proxied
connid is unsigned; offset real conns by maxrid + 1
[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-2009 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 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         -s base '(objectClass=*)' 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                 -s base '(objectClass=*)' 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         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
207         sleep $SLEEP1
208 done
209
210 #echo "Using ldapsearch to read all the entries from the master..."
211 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
212         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
213 RC=$?
214
215 if test $RC != 0 ; then
216         echo "ldapsearch failed at master ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 #echo "Using ldapsearch to read all the entries from the slave..."
222 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
223         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
224 RC=$?
225
226 if test $RC != 0 ; then
227         echo "ldapsearch failed at slave ($RC)!"
228         test $KILLSERVERS != no && kill -HUP $KILLPIDS
229         exit $RC
230 fi
231
232 #echo "Filtering master results..."
233 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
234 #echo "Filtering slave results..."
235 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
236
237 echo "$CHECK < Comparing retrieved entries from master and slave..."
238 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
239
240 if test $? != 0 ; then
241         echo "test failed - master and slave databases differ"
242         test $KILLSERVERS != no && kill -HUP $KILLPIDS
243         exit 1
244 fi
245
246 CHECK=`expr $CHECK + 1`
247 echo "$CHECK > Stopping the provider, sleeping $SLEEP2 seconds and restarting it..."
248 kill -HUP "$MASTERPID"
249 wait $MASTERPID
250 sleep $SLEEP2
251
252 echo "======================= RESTART =======================" >> $LOG1
253 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
254 MASTERPID=$!
255 if test $WAIT != 0 ; then
256     echo MASTERPID $MASTERPID
257     read foo
258 fi
259 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
260
261 sleep 1
262
263 echo "Using ldapsearch to check that master slapd is running..."
264 for i in 0 1 2 3 4 5; do
265         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
266                 '(objectClass=*)' > /dev/null 2>&1
267         RC=$?
268         if test $RC = 0 ; then
269                 break
270         fi
271         echo "Waiting 5 seconds for slapd to start..."
272         sleep 5
273 done
274
275 if test $RC != 0 ; then
276         echo "ldapsearch failed ($RC)!"
277         test $KILLSERVERS != no && kill -HUP $KILLPIDS
278         exit $RC
279 fi
280
281 echo "Using ldapmodify to modify master directory..."
282
283 #
284 # Do some modifications
285 #
286
287 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
288         $TESTOUT 2>&1 << EOMODS
289 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
290 changetype: modify
291 add: drink
292 drink: Orange Juice
293 -
294 delete: sn
295 sn: Jones
296 -
297 add: sn
298 sn: Jones
299
300 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
301 changetype: modify
302 replace: drink
303 drink: Iced Tea
304
305 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
306 changetype: modify
307 delete: uniquemember
308 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
309 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
310 -
311 add: uniquemember
312 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
313 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
314
315 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
316  =com
317 changetype: modify
318 delete: cn
319 cn: Biiff Jensen
320
321 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
322 changetype: add
323 objectclass: OpenLDAPperson
324 cn: Gern Jensen
325 sn: Jensen
326 uid: gjensen
327 title: Chief Investigator, ITD
328 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
329 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
330 drink: Coffee
331 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
332 description: Very odd
333 facsimiletelephonenumber: +1 313 555 7557
334 telephonenumber: +1 313 555 8343
335 mail: gjensen@mailgw.example.com
336 homephone: +1 313 555 8844
337
338 dn: ou=Retired, ou=People, dc=example,dc=com
339 changetype: add
340 objectclass: organizationalUnit
341 ou: Retired
342
343 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
344 changetype: add
345 objectclass: OpenLDAPperson
346 cn: Rosco P. Coltrane
347 sn: Coltrane
348 uid: rosco
349 description: Fat tycoon
350
351 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
352 changetype: modrdn
353 newrdn: cn=Rosco P. Coltrane
354 deleteoldrdn: 1
355 newsuperior: ou=Retired, ou=People, dc=example,dc=com
356
357 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
358 changetype: delete
359 EOMODS
360
361 RC=$?
362 if test $RC != 0 ; then
363         echo "ldapmodify failed ($RC)!"
364         test $KILLSERVERS != no && kill -HUP $KILLPIDS
365         exit $RC
366 fi
367
368 # get master contextCSN
369 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
370         -s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
371 RC=$?
372 if test $RC != 0 ; then
373         echo "ldapsearch failed at master ($RC)!"
374         test $KILLSERVERS != no && kill -HUP $KILLPIDS
375         exit $RC
376 fi
377
378 # check slave contextCSN
379 for i in 1 2 3; do
380         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
381         sleep $SLEEP1
382
383         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
384                 -s base '(objectClass=*)' contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
385         RC=$?
386
387         if test $RC != 0 ; then
388                 echo "ldapsearch failed at slave ($RC)!"
389                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
390                 exit $RC
391         fi
392
393         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
394
395         if test $? = 0 ; then
396                 break
397         fi
398 done
399
400 #echo "Using ldapsearch to read all the entries from the master..."
401 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
402         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
403 RC=$?
404
405 if test $RC != 0 ; then
406         echo "ldapsearch failed at master ($RC)!"
407         test $KILLSERVERS != no && kill -HUP $KILLPIDS
408         exit $RC
409 fi
410
411 #echo "Using ldapsearch to read all the entries from the slave..."
412 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
413         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
414 RC=$?
415
416 if test $RC != 0 ; then
417         echo "ldapsearch failed at slave ($RC)!"
418         test $KILLSERVERS != no && kill -HUP $KILLPIDS
419         exit $RC
420 fi
421
422 #echo "Filtering master results..."
423 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
424 #echo "Filtering slave results..."
425 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
426
427 echo "$CHECK < Comparing retrieved entries from master and slave..."
428 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
429
430 if test $? != 0 ; then
431         echo "test failed - master and slave databases differ"
432         test $KILLSERVERS != no && kill -HUP $KILLPIDS
433         exit 1
434 fi
435
436 CHECK=`expr $CHECK + 1`
437 echo "$CHECK > Stopping proxy to test recovery..."
438 kill -HUP $PROXYPID
439 wait $PROXYPID
440
441 echo "Modifying more entries on the master..."
442 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
443         $TESTOUT 2>&1 << EOMODS
444 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
445 changetype: modify
446 add: description
447 description: proxy is down...
448
449 dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
450 changetype: add
451 objectclass: OpenLDAPperson
452 sn: Kirk
453 uid: jtk
454 cn: James T. Kirk
455
456 dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
457 changetype: add
458 objectclass: OpenLDAPperson
459 sn: Hooker
460 uid: tjh
461 cn: Tiberius J. Hooker
462
463 EOMODS
464
465 echo "Restarting proxy..."
466 echo "======================= RESTART =======================" >> $LOG3
467 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
468 PROXYPID=$!
469 if test $WAIT != 0 ; then
470     echo PROXYPID $PROXYPID
471     read foo
472 fi
473 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
474
475 # get master contextCSN
476 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
477         -s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
478 RC=$?
479 if test $RC != 0 ; then
480         echo "ldapsearch failed at master ($RC)!"
481         test $KILLSERVERS != no && kill -HUP $KILLPIDS
482         exit $RC
483 fi
484
485 # check slave contextCSN
486 for i in 1 2 3 4 5; do
487         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
488         sleep $SLEEP1
489
490         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
491                 -s base '(objectClass=*)' contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
492         RC=$?
493
494         if test $RC != 0 ; then
495                 echo "ldapsearch failed at slave ($RC)!"
496                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
497                 exit $RC
498         fi
499
500         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
501
502         if test $? = 0 ; then
503                 break
504         fi
505 done
506
507 #echo "Using ldapsearch to read all the entries from the master..."
508 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
509         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
510 RC=$?
511
512 if test $RC != 0 ; then
513         echo "ldapsearch failed at master ($RC)!"
514         test $KILLSERVERS != no && kill -HUP $KILLPIDS
515         exit $RC
516 fi
517
518 #echo "Using ldapsearch to read all the entries from the slave..."
519 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
520         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
521 RC=$?
522
523 if test $RC != 0 ; then
524         echo "ldapsearch failed at slave ($RC)!"
525         test $KILLSERVERS != no && kill -HUP $KILLPIDS
526         exit $RC
527 fi
528
529 #echo "Filtering master results..."
530 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
531 #echo "Filtering slave results..."
532 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
533
534 echo "$CHECK < Comparing retrieved entries from master and slave..."
535 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
536
537 if test $? != 0 ; then
538         echo "test failed - master and slave databases differ"
539         test $KILLSERVERS != no && kill -HUP $KILLPIDS
540         exit 1
541 fi
542
543 CHECK=`expr $CHECK + 1`
544 echo "$CHECK > Try updating the slave slapd..."
545 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
546         $TESTOUT 2>&1 << EOMODS
547 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
548 changetype: modify
549 add: description
550 description: This write must fail because directed to a shadow context,
551 description: unless the chain overlay is configured appropriately ;)
552
553 EOMODS
554
555 RC=$?
556 if test $RC != 0 ; then
557         echo "ldapmodify failed ($RC)!"
558         test $KILLSERVERS != no && kill -HUP $KILLPIDS
559         exit $RC
560 fi
561
562 # get master contextCSN
563 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
564         -s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
565 RC=$?
566 if test $RC != 0 ; then
567         echo "ldapsearch failed at master ($RC)!"
568         test $KILLSERVERS != no && kill -HUP $KILLPIDS
569         exit $RC
570 fi
571
572 # check slave contextCSN
573 sleep 1
574
575 for i in 1 2 3; do
576         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
577                 -s base '(objectClass=*)' contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
578         RC=$?
579
580         if test $RC != 0 ; then
581                 echo "ldapsearch failed at slave ($RC)!"
582                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
583                 exit $RC
584         fi
585
586         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
587
588         if test $? = 0 ; then
589                 break
590         fi
591
592         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
593         sleep $SLEEP1
594 done
595
596 #echo "Using ldapsearch to read all the entries from the master..."
597 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
598         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
599 RC=$?
600
601 if test $RC != 0 ; then
602         echo "ldapsearch failed at master ($RC)!"
603         test $KILLSERVERS != no && kill -HUP $KILLPIDS
604         exit $RC
605 fi
606
607 #echo "Using ldapsearch to read all the entries from the slave..."
608 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
609 '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
610 RC=$?
611
612 if test $RC != 0 ; then
613         echo "ldapsearch failed at slave ($RC)!"
614         test $KILLSERVERS != no && kill -HUP $KILLPIDS
615         exit $RC
616 fi
617
618 #echo "Filtering master results..."
619 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
620 #echo "Filtering slave results..."
621 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
622
623 echo "$CHECK < Comparing retrieved entries from master and slave..."
624 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
625
626 if test $? != 0 ; then
627         echo "test failed - master and slave databases differ"
628         test $KILLSERVERS != no && kill -HUP $KILLPIDS
629         exit 1
630 fi
631
632 CHECK=`expr $CHECK + 1`
633 echo "$CHECK > Stopping consumer to test recovery..."
634 kill -HUP $SLAVEPID
635 wait $SLAVEPID
636
637 echo "Modifying more entries on the master..."
638 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
639         $TESTOUT 2>&1 << EOMODS
640 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
641 changetype: modify
642 add: drink
643 drink: Mad Dog 20/20
644
645 EOMODS
646
647 echo "Waiting $SLEEP2 seconds for syncrepl to retry..."
648 sleep $SLEEP2
649
650 echo "Restarting consumer..."
651 echo "======================= RESTART =======================" >> $LOG2
652 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
653 SLAVEPID=$!
654 if test $WAIT != 0 ; then
655     echo SLAVEPID $SLAVEPID
656     read foo
657 fi
658 KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
659
660 # get master contextCSN
661 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
662         -s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
663 RC=$?
664 if test $RC != 0 ; then
665         echo "ldapsearch failed at master ($RC)!"
666         test $KILLSERVERS != no && kill -HUP $KILLPIDS
667         exit $RC
668 fi
669
670 # check slave contextCSN
671
672 for i in 1 2 3 4 5; do
673         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
674         sleep $SLEEP1
675
676         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
677                 -s base '(objectClass=*)' contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
678         RC=$?
679
680         if test $RC != 0 ; then
681                 echo "ldapsearch failed at slave ($RC)!"
682                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
683                 exit $RC
684         fi
685
686         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
687
688         if test $? = 0 ; then
689                 break
690         fi
691 done
692
693 #echo "Using ldapsearch to read all the entries from the master..."
694 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
695         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
696 RC=$?
697
698 if test $RC != 0 ; then
699         echo "ldapsearch failed at master ($RC)!"
700         test $KILLSERVERS != no && kill -HUP $KILLPIDS
701         exit $RC
702 fi
703
704 #echo "Using ldapsearch to read all the entries from the slave..."
705 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
706         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
707 RC=$?
708
709 if test $RC != 0 ; then
710         echo "ldapsearch failed at slave ($RC)!"
711         test $KILLSERVERS != no && kill -HUP $KILLPIDS
712         exit $RC
713 fi
714
715 #echo "Filtering master results..."
716 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
717 #echo "Filtering slave results..."
718 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
719
720 echo "$CHECK < Comparing retrieved entries from master and slave..."
721 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
722
723 if test $? != 0 ; then
724         # FIXME: keep the original workaround in place, in case we needed again
725         if test 1 = 1 ; then
726                 echo "test failed - master and slave databases differ"
727                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
728                 exit 1
729         fi
730
731         echo "  test failed - master and slave databases differ (ignored by now)"
732         echo "  Stopping proxy to see if it auto-recovers..."
733         kill -HUP $PROXYPID
734         wait $PROXYPID
735
736         echo "  ${CHECK}.1 > Restarting proxy..."
737         echo "======================= RESTART =======================" >> $LOG3
738         $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
739         PROXYPID=$!
740         if test $WAIT != 0 ; then
741                 echo PROXYPID $PROXYPID
742                 read foo
743         fi
744         KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
745
746         echo "  Waiting $SLEEP2 seconds for syncrepl to receive changes..."
747         sleep $SLEEP2
748
749         #echo "Using ldapsearch to read all the entries from the slave..."
750         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
751                 '(objectClass=*)' > "${SLAVEOUT}.5.1" 2>&1
752         RC=$?
753
754         if test $RC != 0 ; then
755                 echo "  ldapsearch failed at slave ($RC)!"
756                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
757                 exit $RC
758         fi
759
760         #echo "Filtering slave results..."
761         . $LDIFFILTER < "${SLAVEOUT}.5.1" > $SLAVEFLT
762
763         echo "  ${CHECK}.1 < Comparing retrieved entries from master and slave..."
764         $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
765
766         if test $? != 0 ; then
767                 echo "  test failed - master and slave databases differ"
768                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
769                 exit 1
770         fi
771 fi
772
773 #
774 # Modifications formerly known to fail
775 #
776 CHECK=`expr $CHECK + 1`
777 echo "$CHECK > Performing modifications that were formerly known to fail..."
778 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
779         $TESTOUT 2>&1 << EOMODS
780 # First, back out previous change
781 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
782 changetype: modify
783 delete: drink
784 drink: Mad Dog 20/20
785
786 # From now on, perform modifications that were formerly known to fail
787 dn: cn=All Staff,ou=Groups,dc=example,dc=com
788 changetype: modify
789 delete: description
790
791 EOMODS
792
793 RC=$?
794 if test $RC != 0 ; then
795         echo "ldapmodify failed ($RC)!"
796         test $KILLSERVERS != no && kill -HUP $KILLPIDS
797         exit $RC
798 fi
799
800 # get master contextCSN
801 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
802         -s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
803 RC=$?
804 if test $RC != 0 ; then
805         echo "ldapsearch failed at master ($RC)!"
806         test $KILLSERVERS != no && kill -HUP $KILLPIDS
807         exit $RC
808 fi
809
810 # check slave contextCSN
811 sleep 1
812 for i in 1 2 3; do
813         $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
814                 -s base '(objectClass=*)' contextCSN > "${SLAVEOUT}.$CHECK" 2>&1
815         RC=$?
816
817         if test $RC != 0 ; then
818                 echo "ldapsearch failed at slave ($RC)!"
819                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
820                 exit $RC
821         fi
822
823         $CMP ${MASTEROUT}.$CHECK ${SLAVEOUT}.$CHECK > $CMPOUT
824
825         if test $? = 0 ; then
826                 break
827         fi
828
829         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
830         sleep $SLEEP1
831 done
832
833 #echo "Using ldapsearch to read all the entries from the master..."
834 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
835         '(objectClass=*)' > "${MASTEROUT}.$CHECK" 2>&1
836 RC=$?
837
838 if test $RC != 0 ; then
839         echo "ldapsearch failed at master ($RC)!"
840         test $KILLSERVERS != no && kill -HUP $KILLPIDS
841         exit $RC
842 fi
843
844 #echo "Using ldapsearch to read all the entries from the slave..."
845 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
846         '(objectClass=*)' > "${SLAVEOUT}.$CHECK" 2>&1
847 RC=$?
848
849 if test $RC != 0 ; then
850         echo "ldapsearch failed at slave ($RC)!"
851         test $KILLSERVERS != no && kill -HUP $KILLPIDS
852         exit $RC
853 fi
854
855 #echo "Filtering master results..."
856 . $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
857 #echo "Filtering slave results..."
858 . $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
859
860 echo "$CHECK < Comparing retrieved entries from master and slave..."
861 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
862
863 if test $? != 0 ; then
864         echo "test failed - master and slave databases differ (ignored by now)"
865         #echo "test failed - master and slave databases differ"
866         #test $KILLSERVERS != no && kill -HUP $KILLPIDS
867         #exit 1
868 fi
869
870 test $KILLSERVERS != no && kill -HUP $KILLPIDS
871
872 echo ">>>>> Test succeeded"
873
874 test $KILLSERVERS != no && wait
875
876 exit 0