xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test019-syncreplication-cascade (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1#! /bin/sh
2# $OpenLDAP: pkg/ldap/tests/scripts/test019-syncreplication-cascade,v 1.19.2.3 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
16if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
17	echo "Test does not support $BACKEND"
18	exit 0
19fi
20
21echo "running defines.sh"
22. $SRCDIR/scripts/defines.sh
23
24if test $SYNCPROV = syncprovno; then
25	echo "Syncrepl provider overlay not available, test skipped"
26	exit 0
27fi
28
29mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3 $DBDIR4 $DBDIR5 $DBDIR6
30
31#
32# Test replication:
33# - start master
34# - start slave
35# - populate over ldap
36# - perform some modifies and deleted
37# - retrieve database over ldap and compare against expected results
38#
39
40echo "Starting master slapd on TCP/IP port $PORT1..."
41. $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1
42$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
43PID=$!
44if test $WAIT != 0 ; then
45    echo PID $PID
46    read foo
47fi
48KILLPIDS="$PID"
49
50sleep 1
51
52echo "Using ldapsearch to check that master slapd (pid=$PID) is running..."
53for i in 0 1 2 3 4 5; do
54	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
55		'objectclass=*' > /dev/null 2>&1
56	RC=$?
57	if test $RC = 0 ; then
58		break
59	fi
60	echo "Waiting 5 seconds for slapd to start..."
61	sleep 5
62done
63
64if test $RC != 0 ; then
65	echo "ldapsearch failed ($RC)!"
66	test $KILLSERVERS != no && kill -HUP $KILLPIDS
67	exit $RC
68fi
69
70echo "Using ldapadd to create the context prefix entry in the master..."
71$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
72	$LDIFORDEREDCP > /dev/null 2>&1
73RC=$?
74if test $RC != 0 ; then
75	echo "ldapadd failed ($RC)!"
76	test $KILLSERVERS != no && kill -HUP $KILLPIDS
77	exit $RC
78fi
79
80echo "Starting R1 slave slapd on TCP/IP port $PORT2..."
81. $CONFFILTER $BACKEND $MONITORDB < $R1SRSLAVECONF > $CONF2
82$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
83SLAVEPID=$!
84if test $WAIT != 0 ; then
85    echo SLAVE R1 PID $SLAVEPID
86    read foo
87fi
88KILLPIDS="$KILLPIDS $SLAVEPID"
89
90sleep 1
91
92echo "Using ldapsearch to check that R1 slave slapd (pid=$SLAVEPID) is running..."
93for i in 0 1 2 3 4 5; do
94	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
95		'objectclass=*' > /dev/null 2>&1
96	RC=$?
97	if test $RC = 0 ; then
98		break
99	fi
100	echo "Waiting 5 seconds for R1 slapd to start..."
101	sleep 5
102done
103
104if test $RC != 0 ; then
105	echo "ldapsearch failed ($RC)!"
106	test $KILLSERVERS != no && kill -HUP $KILLPIDS
107	exit $RC
108fi
109
110echo "Starting R2 slave slapd on TCP/IP port $PORT3..."
111. $CONFFILTER $BACKEND $MONITORDB < $R2SRSLAVECONF > $CONF3
112$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
113SLAVEPID=$!
114if test $WAIT != 0 ; then
115    echo SLAVE R2 PID $SLAVEPID
116    read foo
117fi
118KILLPIDS="$KILLPIDS $SLAVEPID"
119
120sleep 1
121
122echo "Using ldapsearch to check that R2 slave slapd (pid=$SLAVEPID) is running..."
123for i in 0 1 2 3 4 5; do
124	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
125		'objectclass=*' > /dev/null 2>&1
126	RC=$?
127	if test $RC = 0 ; then
128		break
129	fi
130	echo "Waiting 5 seconds for R2 slave slapd to start..."
131	sleep 5
132done
133
134if test $RC != 0 ; then
135	echo "ldapsearch failed ($RC)!"
136	test $KILLSERVERS != no && kill -HUP $KILLPIDS
137	exit $RC
138fi
139
140echo "Starting P1 slave slapd on TCP/IP port $PORT4..."
141. $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $CONF4
142$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
143SLAVEPID=$!
144if test $WAIT != 0 ; then
145    echo SLAVE P1 PID $SLAVEPID
146    read foo
147fi
148KILLPIDS="$KILLPIDS $SLAVEPID"
149
150sleep 1
151
152echo "Using ldapsearch to check that P1 slave slapd (pid=$SLAVEPID) is running..."
153for i in 0 1 2 3 4 5; do
154	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT4 \
155		'objectclass=*' > /dev/null 2>&1
156	RC=$?
157	if test $RC = 0 ; then
158		break
159	fi
160	echo "Waiting 5 seconds for P1 slave slapd to start..."
161	sleep 5
162done
163
164if test $RC != 0 ; then
165	echo "ldapsearch failed ($RC)!"
166	test $KILLSERVERS != no && kill -HUP $KILLPIDS
167	exit $RC
168fi
169
170echo "Starting P2 slave slapd on TCP/IP port $PORT5..."
171. $CONFFILTER $BACKEND $MONITORDB < $P2SRSLAVECONF > $CONF5
172$SLAPD -f $CONF5 -h $URI5 -d $LVL $TIMING > $LOG5 2>&1 &
173SLAVEPID=$!
174if test $WAIT != 0 ; then
175    echo SLAVE P2 PID $SLAVEPID
176    read foo
177fi
178KILLPIDS="$KILLPIDS $SLAVEPID"
179
180sleep 1
181
182echo "Using ldapsearch to check that P2 slave slapd (pid=$SLAVEPID) is running..."
183for i in 0 1 2 3 4 5; do
184	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT5 \
185		'objectclass=*' > /dev/null 2>&1
186	RC=$?
187	if test $RC = 0 ; then
188		break
189	fi
190	echo "Waiting 5 seconds for P2 slave slapd to start..."
191	sleep 5
192done
193
194if test $RC != 0 ; then
195	echo "ldapsearch failed ($RC)!"
196	test $KILLSERVERS != no && kill -HUP $KILLPIDS
197	exit $RC
198fi
199
200echo "Starting P3 slave slapd on TCP/IP port $PORT6..."
201. $CONFFILTER $BACKEND $MONITORDB < $P3SRSLAVECONF > $CONF6
202$SLAPD -f $CONF6 -h $URI6 -d $LVL $TIMING > $LOG6 2>&1 &
203SLAVEPID=$!
204if test $WAIT != 0 ; then
205    echo SLAVE P3 PID $SLAVEPID
206    read foo
207fi
208KILLPIDS="$KILLPIDS $SLAVEPID"
209
210sleep 1
211
212echo "Using ldapsearch to check that P3 slave slapd (pid=$SLAVEPID) is running..."
213for i in 0 1 2 3 4 5; do
214	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT6 \
215		'objectclass=*' > /dev/null 2>&1
216	RC=$?
217	if test $RC = 0 ; then
218		break
219	fi
220	echo "Waiting 5 seconds for P3 slave slapd to start..."
221	sleep 5
222done
223
224if test $RC != 0 ; then
225	echo "ldapsearch failed ($RC)!"
226	test $KILLSERVERS != no && kill -HUP $KILLPIDS
227	exit $RC
228fi
229
230echo "Using ldapadd to populate the master directory..."
231$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
232	$LDIFORDEREDNOCP > /dev/null 2>&1
233RC=$?
234if test $RC != 0 ; then
235	echo "ldapadd failed ($RC)!"
236	test $KILLSERVERS != no && kill -HUP $KILLPIDS
237	exit $RC
238fi
239
240echo "Waiting 25 seconds for syncrepl to receive changes..."
241sleep 25
242
243echo "Using ldapmodify to modify master directory..."
244
245#
246# Do some modifications
247#
248
249$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
250	$TESTOUT 2>&1 << EOMODS
251dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
252changetype: modify
253add: drink
254drink: Orange Juice
255-
256delete: sn
257sn: Jones
258-
259add: sn
260sn: Jones
261
262dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
263changetype: modify
264replace: drink
265drink: Iced Tea
266drink: Mad Dog 20/20
267
268dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
269changetype: modify
270delete: uniquemember
271uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
272uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
273-
274add: uniquemember
275uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
276uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
277
278dn: cn=All Staff,ou=Groups,dc=example,dc=com
279changetype: modify
280delete: description
281
282dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
283changetype: add
284objectclass: OpenLDAPperson
285cn: Gern Jensen
286sn: Jensen
287uid: gjensen
288title: Chief Investigator, ITD
289postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
290seealso: cn=All Staff, ou=Groups, dc=example,dc=com
291drink: Coffee
292homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
293description: Very odd
294facsimiletelephonenumber: +1 313 555 7557
295telephonenumber: +1 313 555 8343
296mail: gjensen@mailgw.example.com
297homephone: +1 313 555 8844
298
299dn: ou=Retired, ou=People, dc=example,dc=com
300changetype: add
301objectclass: organizationalUnit
302ou: Retired
303
304dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
305changetype: add
306objectclass: OpenLDAPperson
307cn: Rosco P. Coltrane
308sn: Coltrane
309uid: rosco
310
311dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
312changetype: modrdn
313newrdn: cn=Rosco P. Coltrane
314deleteoldrdn: 1
315newsuperior: ou=Retired, ou=People, dc=example,dc=com
316
317dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
318changetype: delete
319
320EOMODS
321
322RC=$?
323if test $RC != 0 ; then
324	echo "ldapmodify failed ($RC)!"
325	test $KILLSERVERS != no && kill -HUP $KILLPIDS
326	exit $RC
327fi
328
329echo "Waiting 25 seconds for syncrepl to receive changes..."
330sleep 25
331
332echo "Using ldapsearch to read all the entries from the master..."
333$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
334	'objectclass=*' > $MASTEROUT 2>&1
335RC=$?
336
337if test $RC != 0 ; then
338	echo "ldapsearch failed at master ($RC)!"
339	test $KILLSERVERS != no && kill -HUP $KILLPIDS
340	exit $RC
341fi
342
343echo "Using ldapsearch to read all the entries from the R1 slave..."
344$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
345	'objectclass=*' > $SERVER2OUT 2>&1
346RC=$?
347
348if test $RC != 0 ; then
349	echo "ldapsearch failed at R1 slave ($RC)!"
350	test $KILLSERVERS != no && kill -HUP $KILLPIDS
351	exit $RC
352fi
353
354echo "Using ldapsearch to read all the entries from the R2 slave..."
355$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
356	'objectclass=*' > $SERVER3OUT 2>&1
357RC=$?
358
359if test $RC != 0 ; then
360	echo "ldapsearch failed at R2 slave ($RC)!"
361	test $KILLSERVERS != no && kill -HUP $KILLPIDS
362	exit $RC
363fi
364
365echo "Using ldapsearch to read all the entries from the P1 slave..."
366$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
367	'objectclass=*' > $SERVER4OUT 2>&1
368RC=$?
369
370if test $RC != 0 ; then
371	echo "ldapsearch failed at P1 slave ($RC)!"
372	test $KILLSERVERS != no && kill -HUP $KILLPIDS
373	exit $RC
374fi
375
376echo "Using ldapsearch to read all the entries from the P2 slave..."
377$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT5 \
378	'objectclass=*' > $SERVER5OUT 2>&1
379RC=$?
380
381if test $RC != 0 ; then
382	echo "ldapsearch failed at P2 slave ($RC)!"
383	test $KILLSERVERS != no && kill -HUP $KILLPIDS
384	exit $RC
385fi
386
387echo "Using ldapsearch to read all the entries from the P3 slave..."
388$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT6 \
389	'objectclass=*' > $SERVER6OUT 2>&1
390RC=$?
391
392if test $RC != 0 ; then
393	echo "ldapsearch failed at P3 slave ($RC)!"
394	test $KILLSERVERS != no && kill -HUP $KILLPIDS
395	exit $RC
396fi
397
398test $KILLSERVERS != no && kill -HUP $KILLPIDS
399
400echo "Filtering master ldapsearch results..."
401. $LDIFFILTER < $MASTEROUT > $MASTERFLT
402echo "Filtering R1 slave ldapsearch results..."
403. $LDIFFILTER < $SERVER2OUT > $SERVER2FLT
404echo "Filtering R2 slave ldapsearch results..."
405. $LDIFFILTER < $SERVER3OUT > $SERVER3FLT
406echo "Filtering P1 slave ldapsearch results..."
407. $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
408echo "Filtering P2 slave ldapsearch results..."
409. $LDIFFILTER < $SERVER5OUT > $SERVER5FLT
410echo "Filtering P3 slave ldapsearch results..."
411. $LDIFFILTER < $SERVER6OUT > $SERVER6FLT
412
413echo "Comparing retrieved entries from master and R1 slave..."
414$CMP $MASTERFLT $SERVER2FLT > $CMPOUT
415
416if test $? != 0 ; then
417	echo "test failed - master and R1 slave databases differ"
418	exit 1
419fi
420
421echo "Comparing retrieved entries from master and R2 slave..."
422$CMP $MASTERFLT $SERVER3FLT > $CMPOUT
423
424if test $? != 0 ; then
425	echo "test failed - master and R2 slave databases differ"
426	exit 1
427fi
428
429echo "Comparing retrieved entries from master and P1 slave..."
430$CMP $MASTERFLT $SERVER4FLT > $CMPOUT
431
432if test $? != 0 ; then
433	echo "test failed - master and P1 slave databases differ"
434	exit 1
435fi
436
437echo "Comparing retrieved entries from master and P2 slave..."
438$CMP $MASTERFLT $SERVER5FLT > $CMPOUT
439
440if test $? != 0 ; then
441	echo "test failed - master and P2 slave databases differ"
442	exit 1
443fi
444
445echo "Comparing retrieved entries from master and P3 slave..."
446$CMP $MASTERFLT $SERVER6FLT > $CMPOUT
447
448if test $? != 0 ; then
449	echo "test failed - master and P3 slave databases differ"
450	exit 1
451fi
452
453echo ">>>>> Test succeeded"
454
455test $KILLSERVERS != no && wait
456
457exit 0
458