xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test045-syncreplication-proxied (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test045-syncreplication-proxied,v 1.14.2.9 2009/03/10 16:28:14 quanah Exp
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
16if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
17	echo "Test does not support $BACKEND"
18	exit 0
19fi
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
27echo "running defines.sh"
28. $SRCDIR/scripts/defines.sh
29
30if test $BACKLDAP = ldapno; then
31	echo "LDAP backend not available, test skipped"
32	exit 0
33fi
34
35if test $SYNCPROV = syncprovno; then
36	echo "Syncrepl provider overlay not available, test skipped"
37	exit 0
38fi
39
40if test $MONITORDB = no; then
41	echo "Monitor backend not available, test skipped"
42	exit 0
43fi
44
45mkdir -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
57echo "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 &
60MASTERPID=$!
61if test $WAIT != 0 ; then
62    echo MASTERPID $MASTERPID
63    read foo
64fi
65KILLPIDS="$MASTERPID"
66
67sleep 1
68
69echo "Using ldapsearch to check that master slapd is running..."
70for 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
79done
80
81if test $RC != 0 ; then
82	echo "ldapsearch failed ($RC)!"
83	test $KILLSERVERS != no && kill -HUP $KILLPIDS
84	exit $RC
85fi
86
87echo "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
90RC=$?
91if test $RC != 0 ; then
92	echo "ldapadd failed ($RC)!"
93	test $KILLSERVERS != no && kill -HUP $KILLPIDS
94	exit $RC
95fi
96
97echo "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 &
100SLAVEPID=$!
101if test $WAIT != 0 ; then
102    echo SLAVEPID $SLAVEPID
103    read foo
104fi
105KILLPIDS="$MASTERPID $SLAVEPID"
106
107sleep 1
108
109echo "Using ldapsearch to check that slave slapd is running..."
110for 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
119done
120
121if test $RC != 0 ; then
122	echo "ldapsearch failed ($RC)!"
123	test $KILLSERVERS != no && kill -HUP $KILLPIDS
124	exit $RC
125fi
126
127echo "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 &
130PROXYPID=$!
131if test $WAIT != 0 ; then
132    echo PROXYPID $PROXYPID
133    read foo
134fi
135KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
136
137sleep 1
138
139echo "Using ldapsearch to check that proxy slapd is running..."
140for 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
149done
150
151case $RC in
1520 )
153	echo "ldapsearch should have failed ($RC)!"
154	test $KILLSERVERS != no && kill -HUP $KILLPIDS
155	exit -1
156	;;
15753)
158	;;
159*)
160	echo "ldapsearch failed ($RC)!"
161	test $KILLSERVERS != no && kill -HUP $KILLPIDS
162	exit $RC
163	;;
164esac
165
166CHECK=1
167echo "$CHECK > Using ldapadd to populate the master directory..."
168$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
169	$LDIFORDEREDNOCP > /dev/null 2>&1
170RC=$?
171if test $RC != 0 ; then
172	echo "ldapadd failed ($RC)!"
173	test $KILLSERVERS != no && kill -HUP $KILLPIDS
174	exit $RC
175fi
176
177# get master contextCSN
178$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
179	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
180RC=$?
181if test $RC != 0 ; then
182	echo "ldapsearch failed at master ($RC)!"
183	test $KILLSERVERS != no && kill -HUP $KILLPIDS
184	exit $RC
185fi
186
187# check slave contextCSN
188sleep 1
189for 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
208done
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
213RC=$?
214
215if test $RC != 0 ; then
216	echo "ldapsearch failed at master ($RC)!"
217	test $KILLSERVERS != no && kill -HUP $KILLPIDS
218	exit $RC
219fi
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
224RC=$?
225
226if test $RC != 0 ; then
227	echo "ldapsearch failed at slave ($RC)!"
228	test $KILLSERVERS != no && kill -HUP $KILLPIDS
229	exit $RC
230fi
231
232#echo "Filtering master results..."
233. $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
234#echo "Filtering slave results..."
235. $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
236
237echo "$CHECK < Comparing retrieved entries from master and slave..."
238$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
239
240if test $? != 0 ; then
241	echo "test failed - master and slave databases differ"
242	test $KILLSERVERS != no && kill -HUP $KILLPIDS
243	exit 1
244fi
245
246CHECK=`expr $CHECK + 1`
247echo "$CHECK > Stopping the provider, sleeping $SLEEP2 seconds and restarting it..."
248kill -HUP "$MASTERPID"
249wait $MASTERPID
250sleep $SLEEP2
251
252echo "======================= RESTART =======================" >> $LOG1
253$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
254MASTERPID=$!
255if test $WAIT != 0 ; then
256    echo MASTERPID $MASTERPID
257    read foo
258fi
259KILLPIDS="$MASTERPID $SLAVEPID $PROXYPID"
260
261sleep 1
262
263echo "Using ldapsearch to check that master slapd is running..."
264for 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
273done
274
275if test $RC != 0 ; then
276	echo "ldapsearch failed ($RC)!"
277	test $KILLSERVERS != no && kill -HUP $KILLPIDS
278	exit $RC
279fi
280
281echo "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
289dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
290changetype: modify
291add: drink
292drink: Orange Juice
293-
294delete: sn
295sn: Jones
296-
297add: sn
298sn: Jones
299
300dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
301changetype: modify
302replace: drink
303drink: Iced Tea
304
305dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
306changetype: modify
307delete: uniquemember
308uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
309uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
310-
311add: uniquemember
312uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
313uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
314
315dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
316 =com
317changetype: modify
318delete: cn
319cn: Biiff Jensen
320
321dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
322changetype: add
323objectclass: OpenLDAPperson
324cn: Gern Jensen
325sn: Jensen
326uid: gjensen
327title: Chief Investigator, ITD
328postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
329seealso: cn=All Staff, ou=Groups, dc=example,dc=com
330drink: Coffee
331homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
332description: Very odd
333facsimiletelephonenumber: +1 313 555 7557
334telephonenumber: +1 313 555 8343
335mail: gjensen@mailgw.example.com
336homephone: +1 313 555 8844
337
338dn: ou=Retired, ou=People, dc=example,dc=com
339changetype: add
340objectclass: organizationalUnit
341ou: Retired
342
343dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
344changetype: add
345objectclass: OpenLDAPperson
346cn: Rosco P. Coltrane
347sn: Coltrane
348uid: rosco
349description: Fat tycoon
350
351dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
352changetype: modrdn
353newrdn: cn=Rosco P. Coltrane
354deleteoldrdn: 1
355newsuperior: ou=Retired, ou=People, dc=example,dc=com
356
357dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
358changetype: delete
359EOMODS
360
361RC=$?
362if test $RC != 0 ; then
363	echo "ldapmodify failed ($RC)!"
364	test $KILLSERVERS != no && kill -HUP $KILLPIDS
365	exit $RC
366fi
367
368# get master contextCSN
369$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
370	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
371RC=$?
372if test $RC != 0 ; then
373	echo "ldapsearch failed at master ($RC)!"
374	test $KILLSERVERS != no && kill -HUP $KILLPIDS
375	exit $RC
376fi
377
378# check slave contextCSN
379for 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
398done
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
403RC=$?
404
405if test $RC != 0 ; then
406	echo "ldapsearch failed at master ($RC)!"
407	test $KILLSERVERS != no && kill -HUP $KILLPIDS
408	exit $RC
409fi
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
414RC=$?
415
416if test $RC != 0 ; then
417	echo "ldapsearch failed at slave ($RC)!"
418	test $KILLSERVERS != no && kill -HUP $KILLPIDS
419	exit $RC
420fi
421
422#echo "Filtering master results..."
423. $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
424#echo "Filtering slave results..."
425. $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
426
427echo "$CHECK < Comparing retrieved entries from master and slave..."
428$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
429
430if test $? != 0 ; then
431	echo "test failed - master and slave databases differ"
432	test $KILLSERVERS != no && kill -HUP $KILLPIDS
433	exit 1
434fi
435
436CHECK=`expr $CHECK + 1`
437echo "$CHECK > Stopping proxy to test recovery..."
438kill -HUP $PROXYPID
439wait $PROXYPID
440
441echo "Modifying more entries on the master..."
442$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
443	$TESTOUT 2>&1 << EOMODS
444dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
445changetype: modify
446add: description
447description: proxy is down...
448
449dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
450changetype: add
451objectclass: OpenLDAPperson
452sn: Kirk
453uid: jtk
454cn: James T. Kirk
455
456dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
457changetype: add
458objectclass: OpenLDAPperson
459sn: Hooker
460uid: tjh
461cn: Tiberius J. Hooker
462
463EOMODS
464
465echo "Restarting proxy..."
466echo "======================= RESTART =======================" >> $LOG3
467$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
468PROXYPID=$!
469if test $WAIT != 0 ; then
470    echo PROXYPID $PROXYPID
471    read foo
472fi
473KILLPIDS="$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
478RC=$?
479if test $RC != 0 ; then
480	echo "ldapsearch failed at master ($RC)!"
481	test $KILLSERVERS != no && kill -HUP $KILLPIDS
482	exit $RC
483fi
484
485# check slave contextCSN
486for 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
505done
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
510RC=$?
511
512if test $RC != 0 ; then
513	echo "ldapsearch failed at master ($RC)!"
514	test $KILLSERVERS != no && kill -HUP $KILLPIDS
515	exit $RC
516fi
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
521RC=$?
522
523if test $RC != 0 ; then
524	echo "ldapsearch failed at slave ($RC)!"
525	test $KILLSERVERS != no && kill -HUP $KILLPIDS
526	exit $RC
527fi
528
529#echo "Filtering master results..."
530. $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
531#echo "Filtering slave results..."
532. $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
533
534echo "$CHECK < Comparing retrieved entries from master and slave..."
535$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
536
537if test $? != 0 ; then
538	echo "test failed - master and slave databases differ"
539	test $KILLSERVERS != no && kill -HUP $KILLPIDS
540	exit 1
541fi
542
543CHECK=`expr $CHECK + 1`
544echo "$CHECK > Try updating the slave slapd..."
545$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
546	$TESTOUT 2>&1 << EOMODS
547dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
548changetype: modify
549add: description
550description: This write must fail because directed to a shadow context,
551description: unless the chain overlay is configured appropriately ;)
552
553EOMODS
554
555RC=$?
556if test $RC != 0 ; then
557	echo "ldapmodify failed ($RC)!"
558	test $KILLSERVERS != no && kill -HUP $KILLPIDS
559	exit $RC
560fi
561
562# get master contextCSN
563$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
564	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
565RC=$?
566if test $RC != 0 ; then
567	echo "ldapsearch failed at master ($RC)!"
568	test $KILLSERVERS != no && kill -HUP $KILLPIDS
569	exit $RC
570fi
571
572# check slave contextCSN
573sleep 1
574
575for 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
594done
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
599RC=$?
600
601if test $RC != 0 ; then
602	echo "ldapsearch failed at master ($RC)!"
603	test $KILLSERVERS != no && kill -HUP $KILLPIDS
604	exit $RC
605fi
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
610RC=$?
611
612if test $RC != 0 ; then
613	echo "ldapsearch failed at slave ($RC)!"
614	test $KILLSERVERS != no && kill -HUP $KILLPIDS
615	exit $RC
616fi
617
618#echo "Filtering master results..."
619. $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
620#echo "Filtering slave results..."
621. $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
622
623echo "$CHECK < Comparing retrieved entries from master and slave..."
624$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
625
626if test $? != 0 ; then
627	echo "test failed - master and slave databases differ"
628	test $KILLSERVERS != no && kill -HUP $KILLPIDS
629	exit 1
630fi
631
632CHECK=`expr $CHECK + 1`
633echo "$CHECK > Stopping consumer to test recovery..."
634kill -HUP $SLAVEPID
635wait $SLAVEPID
636
637echo "Modifying more entries on the master..."
638$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
639	$TESTOUT 2>&1 << EOMODS
640dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
641changetype: modify
642add: drink
643drink: Mad Dog 20/20
644
645EOMODS
646
647echo "Waiting $SLEEP2 seconds for syncrepl to retry..."
648sleep $SLEEP2
649
650echo "Restarting consumer..."
651echo "======================= RESTART =======================" >> $LOG2
652$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
653SLAVEPID=$!
654if test $WAIT != 0 ; then
655    echo SLAVEPID $SLAVEPID
656    read foo
657fi
658KILLPIDS="$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
663RC=$?
664if test $RC != 0 ; then
665	echo "ldapsearch failed at master ($RC)!"
666	test $KILLSERVERS != no && kill -HUP $KILLPIDS
667	exit $RC
668fi
669
670# check slave contextCSN
671
672for 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
691done
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
696RC=$?
697
698if test $RC != 0 ; then
699	echo "ldapsearch failed at master ($RC)!"
700	test $KILLSERVERS != no && kill -HUP $KILLPIDS
701	exit $RC
702fi
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
707RC=$?
708
709if test $RC != 0 ; then
710	echo "ldapsearch failed at slave ($RC)!"
711	test $KILLSERVERS != no && kill -HUP $KILLPIDS
712	exit $RC
713fi
714
715#echo "Filtering master results..."
716. $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
717#echo "Filtering slave results..."
718. $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
719
720echo "$CHECK < Comparing retrieved entries from master and slave..."
721$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
722
723if 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
771fi
772
773#
774# Modifications formerly known to fail
775#
776CHECK=`expr $CHECK + 1`
777echo "$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
781dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
782changetype: modify
783delete: drink
784drink: Mad Dog 20/20
785
786# From now on, perform modifications that were formerly known to fail
787dn: cn=All Staff,ou=Groups,dc=example,dc=com
788changetype: modify
789delete: description
790
791EOMODS
792
793RC=$?
794if test $RC != 0 ; then
795	echo "ldapmodify failed ($RC)!"
796	test $KILLSERVERS != no && kill -HUP $KILLPIDS
797	exit $RC
798fi
799
800# get master contextCSN
801$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
802	-s base '(objectClass=*)' contextCSN > "${MASTEROUT}.$CHECK" 2>&1
803RC=$?
804if test $RC != 0 ; then
805	echo "ldapsearch failed at master ($RC)!"
806	test $KILLSERVERS != no && kill -HUP $KILLPIDS
807	exit $RC
808fi
809
810# check slave contextCSN
811sleep 1
812for 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
831done
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
836RC=$?
837
838if test $RC != 0 ; then
839	echo "ldapsearch failed at master ($RC)!"
840	test $KILLSERVERS != no && kill -HUP $KILLPIDS
841	exit $RC
842fi
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
847RC=$?
848
849if test $RC != 0 ; then
850	echo "ldapsearch failed at slave ($RC)!"
851	test $KILLSERVERS != no && kill -HUP $KILLPIDS
852	exit $RC
853fi
854
855#echo "Filtering master results..."
856. $LDIFFILTER < "${MASTEROUT}.$CHECK" > $MASTERFLT
857#echo "Filtering slave results..."
858. $LDIFFILTER < "${SLAVEOUT}.$CHECK" > $SLAVEFLT
859
860echo "$CHECK < Comparing retrieved entries from master and slave..."
861$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
862
863if 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
868fi
869
870test $KILLSERVERS != no && kill -HUP $KILLPIDS
871
872echo ">>>>> Test succeeded"
873
874test $KILLSERVERS != no && wait
875
876exit 0
877