test049-sync-config revision 1.1.1.1
1#! /bin/sh
2# $OpenLDAP: pkg/ldap/tests/scripts/test049-sync-config,v 1.4.2.4 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
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
24PRODIR=$TESTDIR/pro
25CONDIR=$TESTDIR/con
26DBPRO=$PRODIR/db
27DBCON=$CONDIR/db
28CFPRO=$PRODIR/slapd.d
29CFCON=$CONDIR/slapd.d
30
31mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
32
33$SLAPPASSWD -g -n >$CONFIGPWF
34
35#
36# Test replication of dynamic config:
37# - start producer
38# - start consumer
39# - configure over ldap
40# - populate over ldap
41# - configure syncrepl over ldap
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 < $DYNAMICCONF > $CONFLDIF
47$SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
48cd $PRODIR
49$SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
50PID=$!
51if test $WAIT != 0 ; then
52    echo PID $PID
53    read foo
54fi
55KILLPIDS="$PID"
56cd $TESTWD
57
58sleep 1
59
60echo "Using ldapsearch to check that producer slapd is running..."
61for i in 0 1 2 3 4 5; do
62	$LDAPSEARCH -s base -b "" -H $URI1 \
63		'objectclass=*' > /dev/null 2>&1
64	RC=$?
65	if test $RC = 0 ; then
66		break
67	fi
68	echo "Waiting 5 seconds for slapd to start..."
69	sleep 5
70done
71
72if test $RC != 0 ; then
73	echo "ldapsearch failed ($RC)!"
74	test $KILLSERVERS != no && kill -HUP $KILLPIDS
75	exit $RC
76fi
77
78echo "Inserting syncprov overlay on producer..."
79if [ "$SYNCPROV" = syncprovmod ]; then
80	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
81dn: cn=module,cn=config
82objectClass: olcModuleList
83cn: module
84olcModulePath: ../../../servers/slapd/overlays
85olcModuleLoad: syncprov.la
86EOF
87	RC=$?
88	if test $RC != 0 ; then
89		echo "ldapadd failed for moduleLoad ($RC)!"
90		test $KILLSERVERS != no && kill -HUP $KILLPIDS
91		exit $RC
92	fi
93fi
94read CONFIGPW < $CONFIGPWF
95$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
96dn: olcDatabase={0}config,cn=config
97changetype: modify
98add: olcSyncRepl
99olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
100  credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
101  interval=00:00:00:10
102-
103add: olcUpdateRef
104olcUpdateRef: $URI1
105
106dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
107changetype: add
108objectClass: olcOverlayConfig
109objectClass: olcSyncProvConfig
110olcOverlay: syncprov
111EOF
112RC=$?
113if test $RC != 0 ; then
114	echo "ldapmodify failed for syncrepl config ($RC)!"
115	test $KILLSERVERS != no && kill -HUP $KILLPIDS
116	exit $RC
117fi
118
119echo "Starting consumer slapd on TCP/IP port $PORT2..."
120$SLAPADD -F $CFCON -n 0 -l $CONFLDIF
121cd $CONDIR
122$SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
123SLAVEPID=$!
124if test $WAIT != 0 ; then
125    echo SLAVEPID $SLAVEPID
126    read foo
127fi
128KILLPIDS="$KILLPIDS $SLAVEPID"
129cd $TESTWD
130
131sleep 1
132
133echo "Using ldapsearch to check that consumer slapd is running..."
134for i in 0 1 2 3 4 5; do
135	$LDAPSEARCH -s base -b "" -H $URI2 \
136		'objectclass=*' > /dev/null 2>&1
137	RC=$?
138	if test $RC = 0 ; then
139		break
140	fi
141	echo "Waiting 5 seconds for slapd to start..."
142	sleep 5
143done
144
145if test $RC != 0 ; then
146	echo "ldapsearch failed ($RC)!"
147	test $KILLSERVERS != no && kill -HUP $KILLPIDS
148	exit $RC
149fi
150
151echo "Configuring syncrepl on consumer..."
152$LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
153dn: olcDatabase={0}config,cn=config
154changetype: modify
155add: olcSyncRepl
156olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
157  credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
158  interval=00:00:00:10
159-
160add: olcUpdateRef
161olcUpdateRef: $URI1
162EOF
163
164SLEEP=10
165echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
166sleep $SLEEP
167
168echo "Using ldapsearch to check that syncrepl received config changes..."
169RC=32
170for i in 0 1 2 3 4 5; do
171	RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
172		-s base -b "olcDatabase={0}config,cn=config" \
173		'(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
174	if test "x$RESULT" = "xOK" ; then
175		RC=0
176		break
177	fi
178	echo "Waiting 5 seconds for syncrepl to receive changes..."
179	sleep 5
180done
181
182if test $RC != 0 ; then
183	echo "ldapsearch failed ($RC)!"
184	test $KILLSERVERS != no && kill -HUP $KILLPIDS
185	exit $RC
186fi
187
188echo "Adding schema and databases on producer..."
189$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
190include: file://$ABS_SCHEMADIR/core.ldif
191
192include: file://$ABS_SCHEMADIR/cosine.ldif
193
194include: file://$ABS_SCHEMADIR/inetorgperson.ldif
195
196include: file://$ABS_SCHEMADIR/openldap.ldif
197
198include: file://$ABS_SCHEMADIR/nis.ldif
199EOF
200RC=$?
201if test $RC != 0 ; then
202	echo "ldapadd failed for schema config ($RC)!"
203	test $KILLSERVERS != no && kill -HUP $KILLPIDS
204	exit $RC
205fi
206
207if [ "$BACKENDTYPE" = mod ]; then
208	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
209dn: cn=module,cn=config
210objectClass: olcModuleList
211cn: module
212olcModulePath: ../../../servers/slapd/back-$BACKEND
213olcModuleLoad: back_$BACKEND.la
214EOF
215	RC=$?
216	if test $RC != 0 ; then
217		echo "ldapadd failed for backend config ($RC)!"
218		test $KILLSERVERS != no && kill -HUP $KILLPIDS
219		exit $RC
220	fi
221fi
222
223$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
224dn: olcDatabase={1}$BACKEND,cn=config
225objectClass: olcDatabaseConfig
226objectClass: olc${BACKEND}Config
227olcDatabase: {1}$BACKEND
228olcSuffix: $BASEDN
229olcDbDirectory: ./db
230olcRootDN: $MANAGERDN
231olcRootPW: $PASSWD
232olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
233  credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
234  interval=00:00:00:10
235olcUpdateRef: $URI1
236
237dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
238changetype: add
239objectClass: olcOverlayConfig
240objectClass: olcSyncProvConfig
241olcOverlay: syncprov
242EOF
243RC=$?
244if test $RC != 0 ; then
245	echo "ldapadd failed for database config ($RC)!"
246	test $KILLSERVERS != no && kill -HUP $KILLPIDS
247	exit $RC
248fi
249
250echo "Using ldapadd to populate producer..."
251$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
252	>> $TESTOUT 2>&1
253RC=$?
254if test $RC != 0 ; then
255	echo "ldapadd failed for database config ($RC)!"
256	test $KILLSERVERS != no && kill -HUP $KILLPIDS
257	exit $RC
258fi
259
260SLEEP=20
261echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
262sleep $SLEEP
263
264echo "Using ldapsearch to check that syncrepl received database changes..."
265RC=32
266for i in 0 1 2 3 4 5; do
267	RESULT=`$LDAPSEARCH -H $URI2 \
268		-s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
269		'(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
270	if test "x$RESULT" = "xOK" ; then
271		RC=0
272		break
273	fi
274	echo "Waiting 5 seconds for syncrepl to receive changes..."
275	sleep 5
276done
277
278if test $RC != 0 ; then
279	echo "ldapsearch failed ($RC)!"
280	test $KILLSERVERS != no && kill -HUP $KILLPIDS
281	exit $RC
282fi
283
284echo "Using ldapsearch to read config from the producer..."
285$LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
286	'objectclass=*' > $MASTEROUT 2>&1
287RC=$?
288
289if test $RC != 0 ; then
290	echo "ldapsearch failed at producer ($RC)!"
291	test $KILLSERVERS != no && kill -HUP $KILLPIDS
292	exit $RC
293fi
294
295echo "Using ldapsearch to read config from the consumer..."
296$LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
297	'objectclass=*' > $SLAVEOUT 2>&1
298RC=$?
299
300if test $RC != 0 ; then
301	echo "ldapsearch failed at consumer ($RC)!"
302	test $KILLSERVERS != no && kill -HUP $KILLPIDS
303	exit $RC
304fi
305
306echo "Filtering producer results..."
307. $LDIFFILTER < $MASTEROUT > $MASTERFLT
308echo "Filtering consumer results..."
309. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
310
311echo "Comparing retrieved configs from producer and consumer..."
312$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
313
314if test $? != 0 ; then
315	echo "test failed - producer and consumer configs differ"
316	test $KILLSERVERS != no && kill -HUP $KILLPIDS
317	exit 1
318fi
319
320echo "Using ldapsearch to read all the entries from the producer..."
321$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
322	'objectclass=*' > $MASTEROUT 2>&1
323RC=$?
324
325if test $RC != 0 ; then
326	echo "ldapsearch failed at producer ($RC)!"
327	test $KILLSERVERS != no && kill -HUP $KILLPIDS
328	exit $RC
329fi
330
331echo "Using ldapsearch to read all the entries from the consumer..."
332$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
333	'objectclass=*' > $SLAVEOUT 2>&1
334RC=$?
335
336if test $RC != 0 ; then
337	echo "ldapsearch failed at consumer ($RC)!"
338	test $KILLSERVERS != no && kill -HUP $KILLPIDS
339	exit $RC
340fi
341
342test $KILLSERVERS != no && kill -HUP $KILLPIDS
343
344echo "Filtering producer results..."
345. $LDIFFILTER < $MASTEROUT > $MASTERFLT
346echo "Filtering consumer results..."
347. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
348
349echo "Comparing retrieved entries from producer and consumer..."
350$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
351
352if test $? != 0 ; then
353	echo "test failed - producer and consumer databases differ"
354	exit 1
355fi
356
357echo ">>>>> Test succeeded"
358
359test $KILLSERVERS != no && wait
360
361exit 0
362