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