xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test054-syncreplication-parallel-load (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test054-syncreplication-parallel-load,v 1.1.2.3 2009/03/05 22:19:39 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
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 $DBDIR4
30
31#
32# Test replication:
33# - start producer
34# - start consumer
35# - populate over ldap
36# - perform some modifies and deleted
37# - attempt to modify the consumer (referral or chain)
38# - retrieve database over ldap and compare against expected results
39#
40
41echo "Starting producer slapd on TCP/IP port $PORT1..."
42. $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1
43$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
44PID=$!
45if test $WAIT != 0 ; then
46    echo PID $PID
47    read foo
48fi
49KILLPIDS="$PID"
50
51sleep 1
52
53echo "Using ldapsearch to check that producer slapd is running..."
54for i in 0 1 2 3 4 5; do
55	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
56		'objectclass=*' > /dev/null 2>&1
57	RC=$?
58	if test $RC = 0 ; then
59		break
60	fi
61	echo "Waiting 5 seconds for slapd to start..."
62	sleep 5
63done
64
65if test $RC != 0 ; then
66	echo "ldapsearch failed ($RC)!"
67	test $KILLSERVERS != no && kill -HUP $KILLPIDS
68	exit $RC
69fi
70
71echo "Using ldapadd to create the context prefix entry in the producer..."
72$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
73	$LDIFORDEREDCP > /dev/null 2>&1
74RC=$?
75if test $RC != 0 ; then
76	echo "ldapadd failed ($RC)!"
77	test $KILLSERVERS != no && kill -HUP $KILLPIDS
78	exit $RC
79fi
80
81echo "Starting consumer slapd on TCP/IP port $PORT4..."
82. $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $CONF4
83$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
84SLAVEPID=$!
85if test $WAIT != 0 ; then
86    echo SLAVEPID $SLAVEPID
87    read foo
88fi
89KILLPIDS="$KILLPIDS $SLAVEPID"
90
91sleep 1
92
93echo "Using ldapsearch to check that consumer slapd is running..."
94for i in 0 1 2 3 4 5; do
95	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT4 \
96		'objectclass=*' > /dev/null 2>&1
97	RC=$?
98	if test $RC = 0 ; then
99		break
100	fi
101	echo "Waiting 5 seconds for slapd to start..."
102	sleep 5
103done
104
105if test $RC != 0 ; then
106	echo "ldapsearch failed ($RC)!"
107	test $KILLSERVERS != no && kill -HUP $KILLPIDS
108	exit $RC
109fi
110
111MORELDIF=$TESTDIR/more.ldif
112TESTOUT1=$TESTDIR/testout1.out
113TESTOUT2=$TESTDIR/testout2.out
114sed -e 's/[Oo][Uu]=/ou=More /g' -e 's/^[Oo][Uu]: /ou: More /' \
115	-e 's/cn=Manager/cn=More Manager/g' \
116	-e 's/^cn: Manager/cn: More Manager/' \
117	$LDIFORDEREDNOCP > $MORELDIF
118
119echo "Using ldapadd to populate the producer directory..."
120$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
121	$LDIFORDEREDNOCP > $TESTOUT1 2>&1  &
122C1PID=$!
123$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
124	$MORELDIF > $TESTOUT2 2>&1 &
125C2PID=$!
126wait $C1PID $C2PID
127
128echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
129sleep $SLEEP1
130
131echo "Stopping the provider, sleeping 10 seconds and restarting it..."
132kill -HUP "$PID"
133wait $PID
134sleep 10
135echo "RESTART" >> $LOG1
136$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
137PID=$!
138if test $WAIT != 0 ; then
139    echo PID $PID
140    read foo
141fi
142KILLPIDS="$PID $SLAVEPID"
143
144sleep 1
145
146echo "Using ldapsearch to check that producer slapd is running..."
147for i in 0 1 2 3 4 5; do
148	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
149		'objectclass=*' > /dev/null 2>&1
150	RC=$?
151	if test $RC = 0 ; then
152		break
153	fi
154	echo "Waiting 5 seconds for slapd to start..."
155	sleep 5
156done
157
158if test $RC != 0 ; then
159	echo "ldapsearch failed ($RC)!"
160	test $KILLSERVERS != no && kill -HUP $KILLPIDS
161	exit $RC
162fi
163
164echo "Waiting 10 seconds to let the system catch up"
165sleep 10
166
167echo "Using ldapmodify to modify producer directory..."
168
169#
170# Do some modifications
171#
172
173$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
174	$TESTOUT 2>&1 << EOMODS
175dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
176changetype: modify
177add: drink
178drink: Orange Juice
179-
180delete: sn
181sn: Jones
182-
183add: sn
184sn: Jones
185
186dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
187changetype: modify
188replace: drink
189drink: Iced Tea
190
191dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
192changetype: modify
193delete: uniquemember
194uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
195uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
196-
197add: uniquemember
198uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
199uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
200
201dn: cn=All Staff,ou=Groups,dc=example,dc=com
202changetype: modify
203delete: description
204
205dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
206changetype: add
207objectclass: OpenLDAPperson
208cn: Gern Jensen
209sn: Jensen
210uid: gjensen
211title: Chief Investigator, ITD
212postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
213seealso: cn=All Staff, ou=Groups, dc=example,dc=com
214drink: Coffee
215homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
216description: Very odd
217facsimiletelephonenumber: +1 313 555 7557
218telephonenumber: +1 313 555 8343
219mail: gjensen@mailgw.example.com
220homephone: +1 313 555 8844
221
222dn: ou=Retired, ou=People, dc=example,dc=com
223changetype: add
224objectclass: organizationalUnit
225ou: Retired
226
227dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
228changetype: add
229objectclass: OpenLDAPperson
230cn: Rosco P. Coltrane
231sn: Coltrane
232uid: rosco
233description: Fat tycoon
234
235dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
236changetype: modrdn
237newrdn: cn=Rosco P. Coltrane
238deleteoldrdn: 1
239newsuperior: ou=Retired, ou=People, dc=example,dc=com
240
241dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
242changetype: delete
243
244EOMODS
245
246RC=$?
247if test $RC != 0 ; then
248	echo "ldapmodify failed ($RC)!"
249	test $KILLSERVERS != no && kill -HUP $KILLPIDS
250	exit $RC
251fi
252
253echo "Using ldappasswd to change some passwords..."
254$LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
255	'cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
256	> $TESTOUT 2>&1
257RC=$?
258if test $RC != 0 ; then
259	echo "ldapmodify failed ($RC)!"
260	test $KILLSERVERS != no && kill -HUP $KILLPIDS
261	exit $RC
262fi
263
264echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
265sleep $SLEEP1
266
267echo "Stopping consumer to test recovery..."
268kill -HUP $SLAVEPID
269wait $SLAVEPID
270
271echo "Modifying more entries on the producer..."
272$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
273	$TESTOUT 2>&1 << EOMODS
274dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
275changetype: delete
276
277dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
278changetype: modify
279add: drink
280drink: Mad Dog 20/20
281
282dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
283changetype: add
284objectclass: OpenLDAPperson
285sn: Coltrane
286uid: rosco
287cn: Rosco P. Coltrane
288
289EOMODS
290
291echo "Restarting consumer..."
292echo "RESTART" >> $LOG4
293$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
294SLAVEPID=$!
295if test $WAIT != 0 ; then
296    echo SLAVEPID $SLAVEPID
297    read foo
298fi
299KILLPIDS="$PID $SLAVEPID"
300
301echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
302sleep $SLEEP1
303
304if test ! $BACKLDAP = "ldapno" ; then
305	echo "Try updating the consumer slapd..."
306	$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \
307		$TESTOUT 2>&1 << EOMODS
308dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
309changetype: modify
310add: description
311description: This write must fail because directed to a shadow context,
312description: unless the chain overlay is configured appropriately ;)
313
314EOMODS
315
316	RC=$?
317	if test $RC != 0 ; then
318		echo "ldapmodify failed ($RC)!"
319		test $KILLSERVERS != no && kill -HUP $KILLPIDS
320		exit $RC
321	fi
322
323	# ITS#4964
324	echo "Trying to change some passwords on the consumer..."
325	$LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD \
326		'cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
327		> $TESTOUT 2>&1
328	RC=$?
329	if test $RC != 0 ; then
330		echo "ldapmodify failed ($RC)!"
331		test $KILLSERVERS != no && kill -HUP $KILLPIDS
332		exit $RC
333	fi
334
335	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
336	sleep $SLEEP1
337fi
338
339OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp"
340
341echo "Using ldapsearch to read all the entries from the producer..."
342$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
343	'(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
344RC=$?
345
346if test $RC != 0 ; then
347	echo "ldapsearch failed at producer ($RC)!"
348	test $KILLSERVERS != no && kill -HUP $KILLPIDS
349	exit $RC
350fi
351
352echo "Using ldapsearch to read all the entries from the consumer..."
353$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
354	'(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
355RC=$?
356
357if test $RC != 0 ; then
358	echo "ldapsearch failed at consumer ($RC)!"
359	test $KILLSERVERS != no && kill -HUP $KILLPIDS
360	exit $RC
361fi
362
363test $KILLSERVERS != no && kill -HUP $KILLPIDS
364
365echo "Filtering producer results..."
366. $LDIFFILTER < $MASTEROUT > $MASTERFLT
367echo "Filtering consumer results..."
368. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
369
370echo "Comparing retrieved entries from producer and consumer..."
371$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
372
373if test $? != 0 ; then
374	echo "test failed - producer and consumer databases differ"
375	exit 1
376fi
377
378echo ">>>>> Test succeeded"
379
380test $KILLSERVERS != no && wait
381
382exit 0
383