xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test018-syncreplication-persist (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test018-syncreplication-persist,v 1.38.2.10 2009/03/05 23:32:21 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" && test "$BACKEND" != "ldif"; 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
111echo "Using ldapadd to populate the producer directory..."
112$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
113	$LDIFORDEREDNOCP > /dev/null 2>&1
114RC=$?
115if test $RC != 0 ; then
116	echo "ldapadd failed ($RC)!"
117	test $KILLSERVERS != no && kill -HUP $KILLPIDS
118	exit $RC
119fi
120
121echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
122sleep $SLEEP1
123
124echo "Stopping the provider, sleeping 10 seconds and restarting it..."
125kill -HUP "$PID"
126wait $PID
127sleep 10
128echo "RESTART" >> $LOG1
129$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
130PID=$!
131if test $WAIT != 0 ; then
132    echo PID $PID
133    read foo
134fi
135KILLPIDS="$PID $SLAVEPID"
136
137sleep 1
138
139echo "Using ldapsearch to check that producer slapd is running..."
140for i in 0 1 2 3 4 5; do
141	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
142		'objectclass=*' > /dev/null 2>&1
143	RC=$?
144	if test $RC = 0 ; then
145		break
146	fi
147	echo "Waiting 5 seconds for slapd to start..."
148	sleep 5
149done
150
151echo "Waiting $SLEEP1 seconds for consumer to reconnect..."
152sleep $SLEEP1
153
154if test $RC != 0 ; then
155	echo "ldapsearch failed ($RC)!"
156	test $KILLSERVERS != no && kill -HUP $KILLPIDS
157	exit $RC
158fi
159
160echo "Using ldapmodify to modify producer directory..."
161
162#
163# Do some modifications
164#
165
166$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
167	$TESTOUT 2>&1 << EOMODS
168dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
169changetype: modify
170add: drink
171drink: Orange Juice
172-
173delete: sn
174sn: Jones
175-
176add: sn
177sn: Jones
178
179dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
180changetype: modify
181replace: drink
182drink: Iced Tea
183
184dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
185changetype: modify
186delete: uniquemember
187uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
188uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
189-
190add: uniquemember
191uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
192uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
193
194dn: cn=All Staff,ou=Groups,dc=example,dc=com
195changetype: modify
196delete: description
197
198dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
199changetype: add
200objectclass: OpenLDAPperson
201cn: Gern Jensen
202sn: Jensen
203uid: gjensen
204title: Chief Investigator, ITD
205postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
206seealso: cn=All Staff, ou=Groups, dc=example,dc=com
207drink: Coffee
208homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
209description: Very odd
210facsimiletelephonenumber: +1 313 555 7557
211telephonenumber: +1 313 555 8343
212mail: gjensen@mailgw.example.com
213homephone: +1 313 555 8844
214
215dn: ou=Retired, ou=People, dc=example,dc=com
216changetype: add
217objectclass: organizationalUnit
218ou: Retired
219
220dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
221changetype: add
222objectclass: OpenLDAPperson
223cn: Rosco P. Coltrane
224sn: Coltrane
225uid: rosco
226description: Fat tycoon
227
228dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
229changetype: modrdn
230newrdn: cn=Rosco P. Coltrane
231deleteoldrdn: 1
232newsuperior: ou=Retired, ou=People, dc=example,dc=com
233
234dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
235changetype: delete
236
237dn: dc=testdomain1,dc=example,dc=com
238changetype: modrdn
239newrdn: dc=itsdomain1
240deleteoldrdn: 1
241
242dn: dc=itsdomain1,dc=example,dc=com
243changetype: modify
244replace: description
245description: Example, Inc. ITS test domain
246
247dn: dc=testdomain2,dc=example,dc=com
248changetype: modrdn
249newrdn: dc=itsdomain2
250deleteoldrdn: 1
251
252EOMODS
253
254RC=$?
255if test $RC != 0 ; then
256	echo "ldapmodify failed ($RC)!"
257	test $KILLSERVERS != no && kill -HUP $KILLPIDS
258	exit $RC
259fi
260
261echo "Using ldappasswd to change some passwords..."
262$LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
263	'cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
264	> $TESTOUT 2>&1
265RC=$?
266if test $RC != 0 ; then
267	echo "ldapmodify failed ($RC)!"
268	test $KILLSERVERS != no && kill -HUP $KILLPIDS
269	exit $RC
270fi
271
272echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
273sleep $SLEEP1
274
275echo "Stopping consumer to test recovery..."
276kill -HUP $SLAVEPID
277wait $SLAVEPID
278
279echo "Modifying more entries on the producer..."
280$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
281	$TESTOUT 2>&1 << EOMODS
282dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
283changetype: delete
284
285dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
286changetype: modify
287add: drink
288drink: Mad Dog 20/20
289
290dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
291changetype: add
292objectclass: OpenLDAPperson
293sn: Coltrane
294uid: rosco
295cn: Rosco P. Coltrane
296
297dn: dc=itsdomain2,dc=example,dc=com
298changetype: modify
299replace: description
300description: Example, Inc. itsdomain2 test domain
301
302EOMODS
303
304RC=$?
305if test $RC != 0 ; then
306	echo "ldapmodify failed ($RC)!"
307	test $KILLSERVERS != no && kill -HUP $KILLPIDS
308	exit $RC
309fi
310
311echo "Restarting consumer..."
312echo "RESTART" >> $LOG4
313$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
314SLAVEPID=$!
315if test $WAIT != 0 ; then
316    echo SLAVEPID $SLAVEPID
317    read foo
318fi
319KILLPIDS="$PID $SLAVEPID"
320
321echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
322sleep $SLEEP1
323
324if test ! $BACKLDAP = "ldapno" ; then
325	echo "Try updating the consumer slapd..."
326	$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \
327		$TESTOUT 2>&1 << EOMODS
328dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
329changetype: modify
330add: description
331description: This write must fail because directed to a shadow context,
332description: unless the chain overlay is configured appropriately ;)
333
334EOMODS
335
336	RC=$?
337	if test $RC != 0 ; then
338		echo "ldapmodify failed ($RC)!"
339		test $KILLSERVERS != no && kill -HUP $KILLPIDS
340		exit $RC
341	fi
342
343	# ITS#4964
344	echo "Trying to change some passwords on the consumer..."
345	$LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD \
346		'cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
347		> $TESTOUT 2>&1
348	RC=$?
349	if test $RC != 0 ; then
350		echo "ldapmodify failed ($RC)!"
351		test $KILLSERVERS != no && kill -HUP $KILLPIDS
352		exit $RC
353	fi
354
355	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
356	sleep $SLEEP1
357fi
358
359OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp"
360
361echo "Using ldapsearch to read all the entries from the producer..."
362$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
363	'(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
364RC=$?
365
366if test $RC != 0 ; then
367	echo "ldapsearch failed at producer ($RC)!"
368	test $KILLSERVERS != no && kill -HUP $KILLPIDS
369	exit $RC
370fi
371
372echo "Using ldapsearch to read all the entries from the consumer..."
373$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
374	'(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
375RC=$?
376
377if test $RC != 0 ; then
378	echo "ldapsearch failed at consumer ($RC)!"
379	test $KILLSERVERS != no && kill -HUP $KILLPIDS
380	exit $RC
381fi
382
383test $KILLSERVERS != no && kill -HUP $KILLPIDS
384
385echo "Filtering producer results..."
386. $LDIFFILTER < $MASTEROUT > $MASTERFLT
387echo "Filtering consumer results..."
388. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
389
390echo "Comparing retrieved entries from producer and consumer..."
391$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
392
393if test $? != 0 ; then
394	echo "test failed - producer and consumer databases differ"
395	exit 1
396fi
397
398echo ">>>>> Test succeeded"
399
400test $KILLSERVERS != no && wait
401
402exit 0
403