xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test043-delta-syncrepl (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test043-delta-syncrepl,v 1.4.2.8 2010/06/10 17:28:50 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
23if test $ACCESSLOG = accesslogno; then
24	echo "Accesslog overlay not available, test skipped"
25	exit 0
26fi
27if test $BACKEND = ldif ; then
28	# Onelevel search does not return entries in order of creation or CSN.
29	echo "$BACKEND backend unsuitable for syncprov logdb, test skipped"
30	exit 0
31fi
32
33mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2
34
35#
36# Test replication:
37# - start producer
38# - start consumer
39# - populate over ldap
40# - perform some modifies and deleted
41# - attempt to modify the consumer (referral or chain)
42# - retrieve database over ldap and compare against expected results
43#
44
45echo "Starting producer slapd on TCP/IP port $PORT1..."
46. $CONFFILTER $BACKEND $MONITORDB < $DSRMASTERCONF > $CONF1
47$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
48PID=$!
49if test $WAIT != 0 ; then
50    echo PID $PID
51    read foo
52fi
53KILLPIDS="$PID"
54
55sleep 1
56
57echo "Using ldapsearch to check that producer slapd is running..."
58for i in 0 1 2 3 4 5; do
59	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
60		'objectclass=*' > /dev/null 2>&1
61	RC=$?
62	if test $RC = 0 ; then
63		break
64	fi
65	echo "Waiting 5 seconds for slapd to start..."
66	sleep 5
67done
68
69if test $RC != 0 ; then
70	echo "ldapsearch failed ($RC)!"
71	test $KILLSERVERS != no && kill -HUP $KILLPIDS
72	exit $RC
73fi
74
75echo "Using ldapadd to create the context prefix entries in the producer..."
76$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
77	$LDIFORDEREDCP > /dev/null 2>&1
78RC=$?
79if test $RC != 0 ; then
80	echo "ldapadd failed ($RC)!"
81	test $KILLSERVERS != no && kill -HUP $KILLPIDS
82	exit $RC
83fi
84
85echo "Starting consumer slapd on TCP/IP port $PORT2..."
86. $CONFFILTER $BACKEND $MONITORDB < $DSRSLAVECONF > $CONF2
87$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
88SLAVEPID=$!
89if test $WAIT != 0 ; then
90    echo SLAVEPID $SLAVEPID
91    read foo
92fi
93KILLPIDS="$KILLPIDS $SLAVEPID"
94
95sleep 1
96
97echo "Using ldapsearch to check that consumer slapd is running..."
98for i in 0 1 2 3 4 5; do
99	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
100		'objectclass=*' > /dev/null 2>&1
101	RC=$?
102	if test $RC = 0 ; then
103		break
104	fi
105	echo "Waiting 5 seconds for slapd to start..."
106	sleep 5
107done
108
109if test $RC != 0 ; then
110	echo "ldapsearch failed ($RC)!"
111	test $KILLSERVERS != no && kill -HUP $KILLPIDS
112	exit $RC
113fi
114
115echo "Using ldapadd to populate the producer directory..."
116$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
117	$LDIFORDEREDNOCP > /dev/null 2>&1
118RC=$?
119if test $RC != 0 ; then
120	echo "ldapadd failed ($RC)!"
121	test $KILLSERVERS != no && kill -HUP $KILLPIDS
122	exit $RC
123fi
124
125echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
126sleep $SLEEP1
127
128echo "Stopping the provider, sleeping 10 seconds and restarting it..."
129kill -HUP "$PID"
130sleep 10
131echo "RESTART" >> $LOG1
132$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
133PID=$!
134if test $WAIT != 0 ; then
135    echo PID $PID
136    read foo
137fi
138KILLPIDS="$PID $SLAVEPID"
139
140sleep 1
141
142echo "Using ldapsearch to check that producer slapd is running..."
143for i in 0 1 2 3 4 5; do
144	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
145		'objectclass=*' > /dev/null 2>&1
146	RC=$?
147	if test $RC = 0 ; then
148		break
149	fi
150	echo "Waiting 5 seconds for slapd to start..."
151	sleep 5
152done
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
237EOMODS
238RC=$?
239if test $RC != 0 ; then
240	echo "ldapmodify failed ($RC)!"
241	test $KILLSERVERS != no && kill -HUP $KILLPIDS
242	exit $RC
243fi
244
245echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
246sleep $SLEEP1
247
248echo "Stopping consumer to test recovery..."
249kill -HUP $SLAVEPID
250sleep 10
251
252echo "Modifying more entries on the producer..."
253$LDAPMODIFY -v -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
254	$TESTOUT 2>&1 << EOMODS
255dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
256changetype: delete
257
258dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
259changetype: modify
260add: drink
261drink: Mad Dog 20/20
262
263dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
264changetype: add
265objectclass: OpenLDAPperson
266sn: Coltrane
267uid: rosco
268cn: Rosco P. Coltrane
269
270dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
271changetype: modify
272replace: drink
273
274dn: cn=All Staff,ou=Groups,dc=example,dc=com
275changetype: modrdn
276newrdn: cn=Some Staff
277deleteoldrdn: 1
278
279EOMODS
280
281echo "Restarting consumer..."
282echo "RESTART" >> $LOG2
283$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
284SLAVEPID=$!
285if test $WAIT != 0 ; then
286    echo SLAVEPID $SLAVEPID
287    read foo
288fi
289KILLPIDS="$PID $SLAVEPID"
290
291echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
292sleep $SLEEP1
293
294if test ! $BACKLDAP = "ldapno" ; then
295	echo "Try updating the consumer slapd..."
296	$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
297		$TESTOUT 2>&1 << EOMODS
298dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
299changetype: modify
300add: description
301description: This write must fail because directed to a shadow context,
302description: unless the chain overlay is configured appropriately ;)
303
304EOMODS
305
306	RC=$?
307	if test $RC != 0 ; then
308		echo "ldapmodify failed ($RC)!"
309		test $KILLSERVERS != no && kill -HUP $KILLPIDS
310		exit $RC
311	fi
312
313	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
314	sleep $SLEEP1
315fi
316
317echo "Using ldapsearch to read all the entries from the producer..."
318$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
319	'objectclass=*' \* + > $MASTEROUT 2>&1
320RC=$?
321
322if test $RC != 0 ; then
323	echo "ldapsearch failed at producer ($RC)!"
324	test $KILLSERVERS != no && kill -HUP $KILLPIDS
325	exit $RC
326fi
327
328echo "Using ldapsearch to read all the entries from the consumer..."
329$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
330	'objectclass=*' \* + > $SLAVEOUT 2>&1
331RC=$?
332
333if test $RC != 0 ; then
334	echo "ldapsearch failed at consumer ($RC)!"
335	test $KILLSERVERS != no && kill -HUP $KILLPIDS
336	exit $RC
337fi
338
339test $KILLSERVERS != no && kill -HUP $KILLPIDS
340
341echo "Filtering producer results..."
342$LDIFFILTER -s bdb=a,hdb=a < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
343echo "Filtering consumer results..."
344$LDIFFILTER -s bdb=a,hdb=a < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
345
346echo "Comparing retrieved entries from producer and consumer..."
347$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
348
349if test $? != 0 ; then
350	echo "test failed - producer and consumer databases differ"
351	exit 1
352fi
353
354echo ">>>>> Test succeeded"
355
356test $KILLSERVERS != no && wait
357
358exit 0
359