xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test048-syncrepl-multiproxy (revision fff57c5525bbe431aee7bdb3983954f0627a42cb)
1#! /bin/sh
2# $OpenLDAP: pkg/ldap/tests/scripts/test048-syncrepl-multiproxy,v 1.1.2.6 2008/02/11 23:26:51 kurt Exp $
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2008 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
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19if test $BACKLDAP = ldapno; then
20	echo "LDAP backend not available, test skipped"
21	exit 0
22fi
23
24if test $SYNCPROV = syncprovno; then
25	echo "Syncrepl provider overlay not available, test skipped"
26	exit 0
27fi
28
29if test $MONITORDB = no; then
30	echo "Monitor backend not available, test skipped"
31	exit 0
32fi
33
34mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3
35
36#
37# Test replication:
38# - start master
39# - start slave
40# - populate over ldap
41# - perform some modifies and deleted
42# - attempt to modify the slave (referral or chain)
43# - retrieve database over ldap and compare against expected results
44#
45
46echo "Starting master slapd on TCP/IP port $PORT1..."
47. $CONFFILTER $BACKEND $MONITORDB < $PLSRMASTERCONF > $CONF1
48$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
49MASTERPID=$!
50if test $WAIT != 0 ; then
51    echo MASTERPID $MASTERPID
52    read foo
53fi
54KILLPIDS="$MASTERPID"
55
56sleep 1
57
58echo "Using ldapsearch to check that master slapd is running..."
59for i in 0 1 2 3 4 5; do
60	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
61		'(objectClass=*)' > /dev/null 2>&1
62	RC=$?
63	if test $RC = 0 ; then
64		break
65	fi
66	echo "Waiting 5 seconds for slapd to start..."
67	sleep 5
68done
69
70if test $RC != 0 ; then
71	echo "ldapsearch failed ($RC)!"
72	test $KILLSERVERS != no && kill -HUP $KILLPIDS
73	exit $RC
74fi
75
76echo "Using ldapadd to create the context prefix entry in the master..."
77$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
78	$LDIFORDEREDCP > /dev/null 2>&1
79RC=$?
80if test $RC != 0 ; then
81	echo "ldapadd failed ($RC)!"
82	test $KILLSERVERS != no && kill -HUP $KILLPIDS
83	exit $RC
84fi
85
86echo "Starting P1 slave slapd on TCP/IP port $PORT2..."
87. $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF > $CONF2
88$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
89P1SLAVEPID=$!
90if test $WAIT != 0 ; then
91    echo P1SLAVEPID $P1SLAVEPID
92    read foo
93fi
94KILLPIDS="$MASTERPID $P1SLAVEPID"
95
96sleep 1
97
98echo "Using ldapsearch to check that P1 slave slapd is running..."
99for i in 0 1 2 3 4 5; do
100	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
101		'(objectClass=*)' > /dev/null 2>&1
102	RC=$?
103	if test $RC = 0 ; then
104		break
105	fi
106	echo "Waiting 5 seconds for slapd to start..."
107	sleep 5
108done
109
110if test $RC != 0 ; then
111	echo "ldapsearch failed ($RC)!"
112	test $KILLSERVERS != no && kill -HUP $KILLPIDS
113	exit $RC
114fi
115
116echo "Starting R1 slave slapd on TCP/IP port $PORT3..."
117. $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF | sed -e 's;\.2\.;.3.;' > $CONF3
118$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
119R1SLAVEPID=$!
120if test $WAIT != 0 ; then
121    echo R1SLAVEPID $R1SLAVEPID
122    read foo
123fi
124KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
125
126sleep 1
127
128echo "Using ldapsearch to check that R1 slave slapd is running..."
129for i in 0 1 2 3 4 5; do
130	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
131		'(objectClass=*)' > /dev/null 2>&1
132	RC=$?
133	if test $RC = 0; then
134		break
135	fi
136	echo "Waiting 5 seconds for slapd to start..."
137	sleep 5
138done
139
140if test $RC != 0 ; then
141	echo "ldapsearch failed ($RC)!"
142	test $KILLSERVERS != no && kill -HUP $KILLPIDS
143	exit $RC
144fi
145
146CHECK=1
147echo "$CHECK > Using ldapadd to populate the master directory..."
148$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
149	$LDIFORDEREDNOCP > /dev/null 2>&1
150RC=$?
151if test $RC != 0 ; then
152	echo "ldapadd failed ($RC)!"
153	test $KILLSERVERS != no && kill -HUP $KILLPIDS
154	exit $RC
155fi
156
157SLEEP=15
158echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
159sleep $SLEEP
160
161#echo "Using ldapsearch to read all the entries from the master..."
162$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
163	'(objectClass=*)' > "${MASTEROUT}.1" 2>&1
164RC=$?
165
166if test $RC != 0 ; then
167	echo "ldapsearch failed at master ($RC)!"
168	test $KILLSERVERS != no && kill -HUP $KILLPIDS
169	exit $RC
170fi
171
172#echo "Using ldapsearch to read all the entries from the P1 slave..."
173$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
174	'(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
175RC=$?
176
177if test $RC != 0 ; then
178	echo "ldapsearch failed at P1 slave ($RC)!"
179	test $KILLSERVERS != no && kill -HUP $KILLPIDS
180	exit $RC
181fi
182
183#echo "Filtering master results..."
184. $LDIFFILTER < "${MASTEROUT}.1" > $MASTERFLT
185#echo "Filtering slave results..."
186. $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
187
188echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
189$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
190
191if test $? != 0 ; then
192	echo "test failed - master and P1 slave databases differ"
193	test $KILLSERVERS != no && kill -HUP $KILLPIDS
194	exit 1
195fi
196
197#echo "Using ldapsearch to read all the entries from the R1 slave..."
198$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
199	'(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
200RC=$?
201
202if test $RC != 0 ; then
203	echo "ldapsearch failed at R1 slave ($RC)!"
204	test $KILLSERVERS != no && kill -HUP $KILLPIDS
205	exit $RC
206fi
207
208#echo "Filtering slave results..."
209. $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
210
211echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
212$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
213
214if test $? != 0 ; then
215	echo "test failed - master and R1 slave databases differ"
216	test $KILLSERVERS != no && kill -HUP $KILLPIDS
217	exit 1
218fi
219
220CHECK=`expr $CHECK + 1`
221SLEEP=10
222echo "$CHECK > Stopping the provider, sleeping $SLEEP seconds and restarting it..."
223kill -HUP "$MASTERPID"
224wait $MASTERPID
225sleep $SLEEP
226
227echo "======================= RESTART =======================" >> $LOG1
228$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
229MASTERPID=$!
230if test $WAIT != 0 ; then
231    echo MASTERPID $MASTERPID
232    read foo
233fi
234KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
235
236sleep 1
237
238echo "Using ldapsearch to check that master slapd is running..."
239for i in 0 1 2 3 4 5; do
240	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
241		'(objectClass=*)' > /dev/null 2>&1
242	RC=$?
243	if test $RC = 0 ; then
244		break
245	fi
246	echo "Waiting 5 seconds for slapd to start..."
247	sleep 5
248done
249
250if test $RC != 0 ; then
251	echo "ldapsearch failed ($RC)!"
252	test $KILLSERVERS != no && kill -HUP $KILLPIDS
253	exit $RC
254fi
255
256echo "Using ldapmodify to modify master directory..."
257
258#
259# Do some modifications
260#
261
262$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
263	$TESTOUT 2>&1 << EOMODS
264dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
265changetype: modify
266add: drink
267drink: Orange Juice
268-
269delete: sn
270sn: Jones
271-
272add: sn
273sn: Jones
274
275dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
276changetype: modify
277replace: drink
278drink: Iced Tea
279
280dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
281changetype: modify
282delete: uniquemember
283uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
284uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
285-
286add: uniquemember
287uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
288uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
289
290dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
291 =com
292changetype: modify
293delete: cn
294cn: Biiff Jensen
295
296dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
297changetype: add
298objectclass: OpenLDAPperson
299cn: Gern Jensen
300sn: Jensen
301uid: gjensen
302title: Chief Investigator, ITD
303postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
304seealso: cn=All Staff, ou=Groups, dc=example,dc=com
305drink: Coffee
306homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
307description: Very odd
308facsimiletelephonenumber: +1 313 555 7557
309telephonenumber: +1 313 555 8343
310mail: gjensen@mailgw.example.com
311homephone: +1 313 555 8844
312
313dn: ou=Retired, ou=People, dc=example,dc=com
314changetype: add
315objectclass: organizationalUnit
316ou: Retired
317
318dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
319changetype: add
320objectclass: OpenLDAPperson
321cn: Rosco P. Coltrane
322sn: Coltrane
323uid: rosco
324description: Fat tycoon
325
326dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
327changetype: modrdn
328newrdn: cn=Rosco P. Coltrane
329deleteoldrdn: 1
330newsuperior: ou=Retired, ou=People, dc=example,dc=com
331
332dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
333changetype: delete
334EOMODS
335
336RC=$?
337if test $RC != 0 ; then
338	echo "ldapmodify failed ($RC)!"
339	test $KILLSERVERS != no && kill -HUP $KILLPIDS
340	exit $RC
341fi
342
343SLEEP=15
344echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
345sleep $SLEEP
346
347#echo "Using ldapsearch to read all the entries from the master..."
348$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
349	'(objectClass=*)' > "${MASTEROUT}.2" 2>&1
350RC=$?
351
352if test $RC != 0 ; then
353	echo "ldapsearch failed at master ($RC)!"
354	test $KILLSERVERS != no && kill -HUP $KILLPIDS
355	exit $RC
356fi
357
358#echo "Using ldapsearch to read all the entries from the P1 slave..."
359$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
360	'(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
361RC=$?
362
363if test $RC != 0 ; then
364	echo "ldapsearch failed at P1 slave ($RC)!"
365	test $KILLSERVERS != no && kill -HUP $KILLPIDS
366	exit $RC
367fi
368
369#echo "Filtering master results..."
370. $LDIFFILTER < "${MASTEROUT}.2" > $MASTERFLT
371#echo "Filtering P1 slave results..."
372. $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
373
374echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
375$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
376
377if test $? != 0 ; then
378	echo "test failed - master and P1 slave databases differ"
379	test $KILLSERVERS != no && kill -HUP $KILLPIDS
380	exit 1
381fi
382
383#echo "Using ldapsearch to read all the entries from the R1 slave..."
384$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
385	'(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
386RC=$?
387
388if test $RC != 0 ; then
389	echo "ldapsearch failed at R1 slave ($RC)!"
390	test $KILLSERVERS != no && kill -HUP $KILLPIDS
391	exit $RC
392fi
393
394#echo "Filtering slave results..."
395. $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
396
397echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
398$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
399
400if test $? != 0 ; then
401	echo "test failed - master and R1 slave databases differ"
402	test $KILLSERVERS != no && kill -HUP $KILLPIDS
403	exit 1
404fi
405
406CHECK=`expr $CHECK + 1`
407echo "$CHECK > Stopping slaves to test recovery..."
408kill -HUP $P1SLAVEPID $R1SLAVEPID
409wait $P1SLAVEPID
410wait $R1SLAVEPID
411
412echo "Modifying more entries on the master..."
413$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
414	$TESTOUT 2>&1 << EOMODS
415dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
416changetype: modify
417add: description
418description: r1 slave is down...
419
420dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
421changetype: add
422objectclass: OpenLDAPperson
423sn: Kirk
424uid: jtk
425cn: James T. Kirk
426
427dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
428changetype: add
429objectclass: OpenLDAPperson
430sn: Hooker
431uid: tjh
432cn: Tiberius J. Hooker
433
434EOMODS
435
436echo "Restarting P1 slave..."
437echo "======================= RESTART =======================" >> $LOG3
438$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
439P1SLAVEPID=$!
440if test $WAIT != 0 ; then
441    echo P1SLAVEPID $P1SLAVEPID
442    read foo
443fi
444
445echo "Restarting R1 slave..."
446echo "======================= RESTART =======================" >> $LOG3
447$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
448R1SLAVEPID=$!
449if test $WAIT != 0 ; then
450    echo R1SLAVEPID $R1SLAVEPID
451    read foo
452fi
453KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
454
455SLEEP=25
456echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
457sleep $SLEEP
458
459#echo "Using ldapsearch to read all the entries from the master..."
460$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
461	'(objectClass=*)' > "${MASTEROUT}.3" 2>&1
462RC=$?
463
464if test $RC != 0 ; then
465	echo "ldapsearch failed at master ($RC)!"
466	test $KILLSERVERS != no && kill -HUP $KILLPIDS
467	exit $RC
468fi
469
470#echo "Using ldapsearch to read all the entries from the P1 slave..."
471$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
472	'(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
473RC=$?
474
475if test $RC != 0 ; then
476	echo "ldapsearch failed at slave ($RC)!"
477	test $KILLSERVERS != no && kill -HUP $KILLPIDS
478	exit $RC
479fi
480
481#echo "Filtering master results..."
482. $LDIFFILTER < "${MASTEROUT}.3" > $MASTERFLT
483#echo "Filtering slave results..."
484. $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
485
486echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
487$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
488
489if test $? != 0 ; then
490	echo "test failed - master and slave databases differ"
491	test $KILLSERVERS != no && kill -HUP $KILLPIDS
492	exit 1
493fi
494
495#echo "Using ldapsearch to read all the entries from the R1 slave..."
496$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
497	'(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
498RC=$?
499
500if test $RC != 0 ; then
501	echo "ldapsearch failed at slave ($RC)!"
502	test $KILLSERVERS != no && kill -HUP $KILLPIDS
503	exit $RC
504fi
505
506#echo "Filtering slave results..."
507. $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
508
509echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
510$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
511
512if test $? != 0 ; then
513	echo "test failed - master and slave databases differ"
514	test $KILLSERVERS != no && kill -HUP $KILLPIDS
515	exit 1
516fi
517
518CHECK=`expr $CHECK + 1`
519echo "$CHECK > Try updating the P1 slave slapd..."
520$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
521	$TESTOUT 2>&1 << EOMODS
522dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
523changetype: modify
524add: description
525description: This write must fail because directed to a shadow context,
526description: unless the chain overlay is configured appropriately ;)
527
528EOMODS
529
530RC=$?
531if test $RC != 0 ; then
532	echo "ldapmodify failed ($RC)!"
533	test $KILLSERVERS != no && kill -HUP $KILLPIDS
534	exit $RC
535fi
536
537SLEEP=15
538echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
539sleep $SLEEP
540
541#echo "Using ldapsearch to read all the entries from the master..."
542$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
543	'(objectClass=*)' > "${MASTEROUT}.4" 2>&1
544RC=$?
545
546if test $RC != 0 ; then
547	echo "ldapsearch failed at master ($RC)!"
548	test $KILLSERVERS != no && kill -HUP $KILLPIDS
549	exit $RC
550fi
551
552#echo "Using ldapsearch to read all the entries from the P1 slave..."
553$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
554'(objectClass=*)' > "${SLAVEOUT}.4" 2>&1
555RC=$?
556
557if test $RC != 0 ; then
558	echo "ldapsearch failed at slave ($RC)!"
559	test $KILLSERVERS != no && kill -HUP $KILLPIDS
560	exit $RC
561fi
562
563#echo "Filtering master results..."
564. $LDIFFILTER < "${MASTEROUT}.4" > $MASTERFLT
565#echo "Filtering slave results..."
566. $LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT
567
568echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
569$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
570
571if test $? != 0 ; then
572	echo "test failed - master and P1 slave databases differ"
573	test $KILLSERVERS != no && kill -HUP $KILLPIDS
574	exit 1
575fi
576
577#echo "Using ldapsearch to read all the entries from the R1 slave..."
578$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
579'(objectClass=*)' > "${SLAVEOUT}.4" 2>&1
580RC=$?
581
582if test $RC != 0 ; then
583	echo "ldapsearch failed at slave ($RC)!"
584	test $KILLSERVERS != no && kill -HUP $KILLPIDS
585	exit $RC
586fi
587
588#echo "Filtering slave results..."
589. $LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT
590
591echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
592$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
593
594if test $? != 0 ; then
595	echo "test failed - master and R1 slave databases differ"
596	test $KILLSERVERS != no && kill -HUP $KILLPIDS
597	exit 1
598fi
599
600test $KILLSERVERS != no && kill -HUP $KILLPIDS
601
602echo ">>>>> Test succeeded"
603
604test $KILLSERVERS != no && wait
605
606exit 0
607