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