1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test045-syncreplication-proxied,v 1.14.2.11 2010/04/19 19:14:36 quanah Exp
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
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
23echo "running defines.sh"
24. $SRCDIR/scripts/defines.sh
25
26if test $BACKLDAP = ldapno; then 
27	echo "LDAP backend not available, test skipped"
28	exit 0
29fi 
30
31if test $SYNCPROV = syncprovno; then 
32	echo "Syncrepl provider overlay not available, test skipped"
33	exit 0
34fi 
35
36if test $MONITORDB = no; then 
37	echo "Monitor backend not available, test skipped"
38	exit 0
39fi 
40
41mkdir -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
53echo "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 &
56MASTERPID=$!
57if test $WAIT != 0 ; then
58    echo MASTERPID $MASTERPID
59    read foo
60fi
61KILLPIDS="$MASTERPID"
62
63sleep 1
64
65echo "Using ldapsearch to check that master slapd is running..."
66for 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
75done
76
77if test $RC != 0 ; then
78	echo "ldapsearch failed ($RC)!"
79	test $KILLSERVERS != no && kill -HUP $KILLPIDS
80	exit $RC
81fi
82
83echo "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
86RC=$?
87if test $RC != 0 ; then
88	echo "ldapadd failed ($RC)!"
89	test $KILLSERVERS != no && kill -HUP $KILLPIDS
90	exit $RC
91fi
92
93echo "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 &
96SLAVEPID=$!
97if test $WAIT != 0 ; then
98    echo SLAVEPID $SLAVEPID
99    read foo
100fi
101KILLPIDS="$MASTERPID $SLAVEPID"
102
103sleep 1
104
105echo "Using ldapsearch to check that slave slapd is running..."
106for 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
115done
116
117if test $RC != 0 ; then
118	echo "ldapsearch failed ($RC)!"
119	test $KILLSERVERS != no && kill -HUP $KILLPIDS
120	exit $RC
121fi
122
123echo "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 &
126PROXYPID=$!
127if test $WAIT != 0 ; then
128    echo PROXYPID $PROXYPID
129    read foo
130fi
131KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
132
133sleep 1
134
135echo "Using ldapsearch to check that proxy slapd is running..."
136for 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
145done
146
147case $RC in
1480 )
149	echo "ldapsearch should have failed ($RC)!"
150	test $KILLSERVERS != no && kill -HUP $KILLPIDS
151	exit -1
152	;;
15353)
154	;;
155*)
156	echo "ldapsearch failed ($RC)!"
157	test $KILLSERVERS != no && kill -HUP $KILLPIDS
158	exit $RC
159	;;
160esac
161
162CHECK=1
163echo "$CHECK > Using ldapadd to populate the master directory..."
164$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
165	$LDIFORDEREDNOCP > /dev/null 2>&1
166RC=$?
167if test $RC != 0 ; then
168	echo "ldapadd failed ($RC)!"
169	test $KILLSERVERS != no && kill -HUP $KILLPIDS
170	exit $RC
171fi
172
173# get master contextCSN
174$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
175	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
176RC=$?
177if test $RC != 0 ; then
178	echo "ldapsearch failed at master ($RC)!"
179	test $KILLSERVERS != no && kill -HUP $KILLPIDS
180	exit $RC
181fi
182
183# check slave contextCSN
184sleep 1
185for 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
204done
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
209RC=$?
210
211if test $RC != 0 ; then
212	echo "ldapsearch failed at master ($RC)!"
213	test $KILLSERVERS != no && kill -HUP $KILLPIDS
214	exit $RC
215fi
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
220RC=$?
221
222if test $RC != 0 ; then
223	echo "ldapsearch failed at slave ($RC)!"
224	test $KILLSERVERS != no && kill -HUP $KILLPIDS
225	exit $RC
226fi
227
228#echo "Filtering master results..."
229$LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
230#echo "Filtering slave results..."
231$LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
232
233echo "$CHECK < Comparing retrieved entries from master and slave..."
234$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
235
236if test $? != 0 ; then
237	echo "test failed - master and slave databases differ"
238	test $KILLSERVERS != no && kill -HUP $KILLPIDS
239	exit 1
240fi
241
242CHECK=`expr $CHECK + 1`
243echo "$CHECK > Stopping the provider, sleeping $SLEEP2 seconds and restarting it..."
244kill -HUP "$MASTERPID"
245wait $MASTERPID
246sleep $SLEEP2
247
248echo "======================= RESTART =======================" >> $LOG1
249$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
250MASTERPID=$!
251if test $WAIT != 0 ; then
252    echo MASTERPID $MASTERPID
253    read foo
254fi
255KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
256
257sleep 1
258
259echo "Using ldapsearch to check that master slapd is running..."
260for 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
269done
270
271if test $RC != 0 ; then
272	echo "ldapsearch failed ($RC)!"
273	test $KILLSERVERS != no && kill -HUP $KILLPIDS
274	exit $RC
275fi
276
277echo "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
285dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
286changetype: modify
287add: drink
288drink: Orange Juice
289-
290delete: sn
291sn: Jones
292-
293add: sn
294sn: Jones
295
296dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
297changetype: modify
298replace: drink
299drink: Iced Tea
300
301dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
302changetype: modify
303delete: uniquemember
304uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
305uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
306-
307add: uniquemember
308uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
309uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
310
311dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
312 =com
313changetype: modify
314delete: cn
315cn: Biiff Jensen
316
317dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
318changetype: add
319objectclass: OpenLDAPperson
320cn: Gern Jensen
321sn: Jensen
322uid: gjensen
323title: Chief Investigator, ITD
324postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
325seealso: cn=All Staff, ou=Groups, dc=example,dc=com
326drink: Coffee
327homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
328description: Very odd
329facsimiletelephonenumber: +1 313 555 7557
330telephonenumber: +1 313 555 8343
331mail: gjensen@mailgw.example.com
332homephone: +1 313 555 8844
333
334dn: ou=Retired, ou=People, dc=example,dc=com
335changetype: add
336objectclass: organizationalUnit
337ou: Retired
338
339dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
340changetype: add
341objectclass: OpenLDAPperson
342cn: Rosco P. Coltrane
343sn: Coltrane
344uid: rosco
345description: Fat tycoon
346
347dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
348changetype: modrdn
349newrdn: cn=Rosco P. Coltrane
350deleteoldrdn: 1
351newsuperior: ou=Retired, ou=People, dc=example,dc=com
352
353dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
354changetype: delete
355EOMODS
356
357RC=$?
358if test $RC != 0 ; then
359	echo "ldapmodify failed ($RC)!"
360	test $KILLSERVERS != no && kill -HUP $KILLPIDS
361	exit $RC
362fi
363
364# get master contextCSN
365$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
366	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
367RC=$?
368if test $RC != 0 ; then
369	echo "ldapsearch failed at master ($RC)!"
370	test $KILLSERVERS != no && kill -HUP $KILLPIDS
371	exit $RC
372fi
373
374# check slave contextCSN
375for 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
394done
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
399RC=$?
400
401if test $RC != 0 ; then
402	echo "ldapsearch failed at master ($RC)!"
403	test $KILLSERVERS != no && kill -HUP $KILLPIDS
404	exit $RC
405fi
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
410RC=$?
411
412if test $RC != 0 ; then
413	echo "ldapsearch failed at slave ($RC)!"
414	test $KILLSERVERS != no && kill -HUP $KILLPIDS
415	exit $RC
416fi
417
418#echo "Filtering master results..."
419$LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
420#echo "Filtering slave results..."
421$LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
422
423echo "$CHECK < Comparing retrieved entries from master and slave..."
424$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
425
426if test $? != 0 ; then
427	echo "test failed - master and slave databases differ"
428	test $KILLSERVERS != no && kill -HUP $KILLPIDS
429	exit 1
430fi
431
432CHECK=`expr $CHECK + 1`
433echo "$CHECK > Stopping proxy to test recovery..."
434kill -HUP $PROXYPID
435wait $PROXYPID
436
437echo "Modifying more entries on the master..."
438$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
439	$TESTOUT 2>&1 << EOMODS
440dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
441changetype: modify
442add: description
443description: proxy is down...
444
445dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
446changetype: add
447objectclass: OpenLDAPperson
448sn: Kirk
449uid: jtk
450cn: James T. Kirk
451
452dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
453changetype: add
454objectclass: OpenLDAPperson
455sn: Hooker
456uid: tjh
457cn: Tiberius J. Hooker
458
459EOMODS
460
461echo "Restarting proxy..."
462echo "======================= RESTART =======================" >> $LOG3
463$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
464PROXYPID=$!
465if test $WAIT != 0 ; then
466    echo PROXYPID $PROXYPID
467    read foo
468fi
469KILLPIDS="$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
474RC=$?
475if test $RC != 0 ; then
476	echo "ldapsearch failed at master ($RC)!"
477	test $KILLSERVERS != no && kill -HUP $KILLPIDS
478	exit $RC
479fi
480
481# check slave contextCSN
482for 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
501done
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
506RC=$?
507
508if test $RC != 0 ; then
509	echo "ldapsearch failed at master ($RC)!"
510	test $KILLSERVERS != no && kill -HUP $KILLPIDS
511	exit $RC
512fi
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
517RC=$?
518
519if test $RC != 0 ; then
520	echo "ldapsearch failed at slave ($RC)!"
521	test $KILLSERVERS != no && kill -HUP $KILLPIDS
522	exit $RC
523fi
524
525#echo "Filtering master results..."
526$LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
527#echo "Filtering slave results..."
528$LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
529
530echo "$CHECK < Comparing retrieved entries from master and slave..."
531$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
532
533if test $? != 0 ; then
534	echo "test failed - master and slave databases differ"
535	test $KILLSERVERS != no && kill -HUP $KILLPIDS
536	exit 1
537fi
538
539CHECK=`expr $CHECK + 1`
540echo "$CHECK > Try updating the slave slapd..."
541$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
542	$TESTOUT 2>&1 << EOMODS
543dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
544changetype: modify
545add: description
546description: This write must fail because directed to a shadow context,
547description: unless the chain overlay is configured appropriately ;)
548
549EOMODS
550
551RC=$?
552if test $RC != 0 ; then
553	echo "ldapmodify failed ($RC)!"
554	test $KILLSERVERS != no && kill -HUP $KILLPIDS
555	exit $RC
556fi
557
558# get master contextCSN
559$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
560	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
561RC=$?
562if test $RC != 0 ; then
563	echo "ldapsearch failed at master ($RC)!"
564	test $KILLSERVERS != no && kill -HUP $KILLPIDS
565	exit $RC
566fi
567
568# check slave contextCSN
569sleep 1
570
571for 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
590done
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
595RC=$?
596
597if test $RC != 0 ; then
598	echo "ldapsearch failed at master ($RC)!"
599	test $KILLSERVERS != no && kill -HUP $KILLPIDS
600	exit $RC
601fi
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
606RC=$?
607
608if test $RC != 0 ; then
609	echo "ldapsearch failed at slave ($RC)!"
610	test $KILLSERVERS != no && kill -HUP $KILLPIDS
611	exit $RC
612fi
613
614#echo "Filtering master results..."
615$LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
616#echo "Filtering slave results..."
617$LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
618
619echo "$CHECK < Comparing retrieved entries from master and slave..."
620$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
621
622if test $? != 0 ; then
623	echo "test failed - master and slave databases differ"
624	test $KILLSERVERS != no && kill -HUP $KILLPIDS
625	exit 1
626fi
627
628CHECK=`expr $CHECK + 1`
629echo "$CHECK > Stopping consumer to test recovery..."
630kill -HUP $SLAVEPID
631wait $SLAVEPID
632
633echo "Modifying more entries on the master..."
634$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
635	$TESTOUT 2>&1 << EOMODS
636dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
637changetype: modify
638add: drink
639drink: Mad Dog 20/20
640
641EOMODS
642
643echo "Waiting $SLEEP2 seconds for syncrepl to retry..."
644sleep $SLEEP2
645
646echo "Restarting consumer..."
647echo "======================= RESTART =======================" >> $LOG2
648$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
649SLAVEPID=$!
650if test $WAIT != 0 ; then
651    echo SLAVEPID $SLAVEPID
652    read foo
653fi
654KILLPIDS="$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
659RC=$?
660if test $RC != 0 ; then
661	echo "ldapsearch failed at master ($RC)!"
662	test $KILLSERVERS != no && kill -HUP $KILLPIDS
663	exit $RC
664fi
665
666# check slave contextCSN
667
668for 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
687done
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
692RC=$?
693
694if test $RC != 0 ; then
695	echo "ldapsearch failed at master ($RC)!"
696	test $KILLSERVERS != no && kill -HUP $KILLPIDS
697	exit $RC
698fi
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
703RC=$?
704
705if test $RC != 0 ; then
706	echo "ldapsearch failed at slave ($RC)!"
707	test $KILLSERVERS != no && kill -HUP $KILLPIDS
708	exit $RC
709fi
710
711#echo "Filtering master results..."
712$LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
713#echo "Filtering slave results..."
714$LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
715
716echo "$CHECK < Comparing retrieved entries from master and slave..."
717$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
718
719if 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
767fi
768
769#
770# Modifications formerly known to fail
771#
772CHECK=`expr $CHECK + 1`
773echo "$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
777dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
778changetype: modify
779delete: drink
780drink: Mad Dog 20/20
781
782# From now on, perform modifications that were formerly known to fail
783dn: cn=All Staff,ou=Groups,dc=example,dc=com
784changetype: modify
785delete: description
786
787EOMODS
788
789RC=$?
790if test $RC != 0 ; then
791	echo "ldapmodify failed ($RC)!"
792	test $KILLSERVERS != no && kill -HUP $KILLPIDS
793	exit $RC
794fi
795
796# get master contextCSN
797$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
798	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
799RC=$?
800if test $RC != 0 ; then
801	echo "ldapsearch failed at master ($RC)!"
802	test $KILLSERVERS != no && kill -HUP $KILLPIDS
803	exit $RC
804fi
805
806# check slave contextCSN
807sleep 1
808for 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
827done
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
832RC=$?
833
834if test $RC != 0 ; then
835	echo "ldapsearch failed at master ($RC)!"
836	test $KILLSERVERS != no && kill -HUP $KILLPIDS
837	exit $RC
838fi
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
843RC=$?
844
845if test $RC != 0 ; then
846	echo "ldapsearch failed at slave ($RC)!"
847	test $KILLSERVERS != no && kill -HUP $KILLPIDS
848	exit $RC
849fi
850
851#echo "Filtering master results..."
852$LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
853#echo "Filtering slave results..."
854$LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
855
856echo "$CHECK < Comparing retrieved entries from master and slave..."
857$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
858
859if 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
864fi
865
866test $KILLSERVERS != no && kill -HUP $KILLPIDS
867
868echo ">>>>> Test succeeded"
869
870test $KILLSERVERS != no && wait
871
872exit 0
873