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