test049-sync-config revision 1.1.1.2 1 1.1 lukem #! /bin/sh
2 1.1.1.2 lukem # OpenLDAP: pkg/ldap/tests/scripts/test049-sync-config,v 1.4.2.11 2009/03/05 23:32:21 quanah Exp
3 1.1 lukem ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 1.1 lukem ##
5 1.1.1.2 lukem ## Copyright 1998-2009 The OpenLDAP Foundation.
6 1.1 lukem ## All rights reserved.
7 1.1 lukem ##
8 1.1 lukem ## Redistribution and use in source and binary forms, with or without
9 1.1 lukem ## modification, are permitted only as authorized by the OpenLDAP
10 1.1 lukem ## Public License.
11 1.1 lukem ##
12 1.1 lukem ## A copy of this license is available in the file LICENSE in the
13 1.1 lukem ## top-level directory of the distribution or, alternatively, at
14 1.1 lukem ## <http://www.OpenLDAP.org/license.html>.
15 1.1 lukem
16 1.1 lukem echo "running defines.sh"
17 1.1 lukem . $SRCDIR/scripts/defines.sh
18 1.1 lukem
19 1.1 lukem if test $SYNCPROV = syncprovno; then
20 1.1 lukem echo "Syncrepl provider overlay not available, test skipped"
21 1.1 lukem exit 0
22 1.1 lukem fi
23 1.1 lukem
24 1.1 lukem PRODIR=$TESTDIR/pro
25 1.1.1.2 lukem CONDIR=$TESTDIR/con1
26 1.1 lukem DBPRO=$PRODIR/db
27 1.1 lukem DBCON=$CONDIR/db
28 1.1 lukem CFPRO=$PRODIR/slapd.d
29 1.1 lukem CFCON=$CONDIR/slapd.d
30 1.1 lukem
31 1.1 lukem mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
32 1.1 lukem
33 1.1 lukem $SLAPPASSWD -g -n >$CONFIGPWF
34 1.1 lukem
35 1.1.1.2 lukem if test x"$SYNCMODE" = x ; then
36 1.1.1.2 lukem SYNCMODE=rp
37 1.1.1.2 lukem fi
38 1.1.1.2 lukem case "$SYNCMODE" in
39 1.1.1.2 lukem ro)
40 1.1.1.2 lukem SYNCTYPE="type=refreshOnly interval=00:00:00:03"
41 1.1.1.2 lukem ;;
42 1.1.1.2 lukem rp)
43 1.1.1.2 lukem SYNCTYPE="type=refreshAndPersist"
44 1.1.1.2 lukem ;;
45 1.1.1.2 lukem *)
46 1.1.1.2 lukem echo "unknown sync mode $SYNCMODE"
47 1.1.1.2 lukem exit 1;
48 1.1.1.2 lukem ;;
49 1.1.1.2 lukem esac
50 1.1.1.2 lukem
51 1.1 lukem #
52 1.1 lukem # Test replication of dynamic config:
53 1.1 lukem # - start producer
54 1.1 lukem # - start consumer
55 1.1 lukem # - configure over ldap
56 1.1 lukem # - populate over ldap
57 1.1 lukem # - configure syncrepl over ldap
58 1.1 lukem # - retrieve database over ldap and compare against expected results
59 1.1 lukem #
60 1.1 lukem
61 1.1 lukem echo "Starting producer slapd on TCP/IP port $PORT1..."
62 1.1 lukem . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
63 1.1 lukem $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
64 1.1 lukem cd $PRODIR
65 1.1 lukem $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
66 1.1 lukem PID=$!
67 1.1 lukem if test $WAIT != 0 ; then
68 1.1 lukem echo PID $PID
69 1.1 lukem read foo
70 1.1 lukem fi
71 1.1 lukem KILLPIDS="$PID"
72 1.1 lukem cd $TESTWD
73 1.1 lukem
74 1.1 lukem sleep 1
75 1.1 lukem
76 1.1 lukem echo "Using ldapsearch to check that producer slapd is running..."
77 1.1 lukem for i in 0 1 2 3 4 5; do
78 1.1 lukem $LDAPSEARCH -s base -b "" -H $URI1 \
79 1.1 lukem 'objectclass=*' > /dev/null 2>&1
80 1.1 lukem RC=$?
81 1.1 lukem if test $RC = 0 ; then
82 1.1 lukem break
83 1.1 lukem fi
84 1.1 lukem echo "Waiting 5 seconds for slapd to start..."
85 1.1 lukem sleep 5
86 1.1 lukem done
87 1.1 lukem
88 1.1 lukem if test $RC != 0 ; then
89 1.1 lukem echo "ldapsearch failed ($RC)!"
90 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
91 1.1 lukem exit $RC
92 1.1 lukem fi
93 1.1 lukem
94 1.1 lukem echo "Inserting syncprov overlay on producer..."
95 1.1 lukem if [ "$SYNCPROV" = syncprovmod ]; then
96 1.1 lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
97 1.1 lukem dn: cn=module,cn=config
98 1.1 lukem objectClass: olcModuleList
99 1.1 lukem cn: module
100 1.1 lukem olcModulePath: ../../../servers/slapd/overlays
101 1.1 lukem olcModuleLoad: syncprov.la
102 1.1 lukem EOF
103 1.1 lukem RC=$?
104 1.1 lukem if test $RC != 0 ; then
105 1.1 lukem echo "ldapadd failed for moduleLoad ($RC)!"
106 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
107 1.1 lukem exit $RC
108 1.1 lukem fi
109 1.1 lukem fi
110 1.1 lukem read CONFIGPW < $CONFIGPWF
111 1.1 lukem $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
112 1.1 lukem dn: olcDatabase={0}config,cn=config
113 1.1 lukem changetype: modify
114 1.1 lukem add: olcSyncRepl
115 1.1 lukem olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
116 1.1.1.2 lukem credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
117 1.1.1.2 lukem retry="3 5 300 5" timeout=3
118 1.1 lukem -
119 1.1 lukem add: olcUpdateRef
120 1.1 lukem olcUpdateRef: $URI1
121 1.1 lukem
122 1.1 lukem dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
123 1.1 lukem changetype: add
124 1.1 lukem objectClass: olcOverlayConfig
125 1.1 lukem objectClass: olcSyncProvConfig
126 1.1 lukem olcOverlay: syncprov
127 1.1 lukem EOF
128 1.1 lukem RC=$?
129 1.1 lukem if test $RC != 0 ; then
130 1.1 lukem echo "ldapmodify failed for syncrepl config ($RC)!"
131 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
132 1.1 lukem exit $RC
133 1.1 lukem fi
134 1.1 lukem
135 1.1 lukem echo "Starting consumer slapd on TCP/IP port $PORT2..."
136 1.1 lukem $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
137 1.1 lukem cd $CONDIR
138 1.1 lukem $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
139 1.1 lukem SLAVEPID=$!
140 1.1 lukem if test $WAIT != 0 ; then
141 1.1 lukem echo SLAVEPID $SLAVEPID
142 1.1 lukem read foo
143 1.1 lukem fi
144 1.1 lukem KILLPIDS="$KILLPIDS $SLAVEPID"
145 1.1 lukem cd $TESTWD
146 1.1 lukem
147 1.1 lukem sleep 1
148 1.1 lukem
149 1.1 lukem echo "Using ldapsearch to check that consumer slapd is running..."
150 1.1 lukem for i in 0 1 2 3 4 5; do
151 1.1 lukem $LDAPSEARCH -s base -b "" -H $URI2 \
152 1.1 lukem 'objectclass=*' > /dev/null 2>&1
153 1.1 lukem RC=$?
154 1.1 lukem if test $RC = 0 ; then
155 1.1 lukem break
156 1.1 lukem fi
157 1.1 lukem echo "Waiting 5 seconds for slapd to start..."
158 1.1 lukem sleep 5
159 1.1 lukem done
160 1.1 lukem
161 1.1 lukem if test $RC != 0 ; then
162 1.1 lukem echo "ldapsearch failed ($RC)!"
163 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
164 1.1 lukem exit $RC
165 1.1 lukem fi
166 1.1 lukem
167 1.1 lukem echo "Configuring syncrepl on consumer..."
168 1.1 lukem $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
169 1.1 lukem dn: olcDatabase={0}config,cn=config
170 1.1 lukem changetype: modify
171 1.1 lukem add: olcSyncRepl
172 1.1 lukem olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
173 1.1.1.2 lukem credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
174 1.1.1.2 lukem retry="3 5 300 5" timeout=3
175 1.1 lukem -
176 1.1 lukem add: olcUpdateRef
177 1.1 lukem olcUpdateRef: $URI1
178 1.1 lukem EOF
179 1.1 lukem
180 1.1.1.2 lukem echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
181 1.1.1.2 lukem sleep $SLEEP1
182 1.1 lukem
183 1.1 lukem echo "Using ldapsearch to check that syncrepl received config changes..."
184 1.1 lukem RC=32
185 1.1 lukem for i in 0 1 2 3 4 5; do
186 1.1 lukem RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
187 1.1 lukem -s base -b "olcDatabase={0}config,cn=config" \
188 1.1 lukem '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
189 1.1 lukem if test "x$RESULT" = "xOK" ; then
190 1.1 lukem RC=0
191 1.1 lukem break
192 1.1 lukem fi
193 1.1.1.2 lukem echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
194 1.1.1.2 lukem sleep $SLEEP1
195 1.1 lukem done
196 1.1 lukem
197 1.1 lukem if test $RC != 0 ; then
198 1.1 lukem echo "ldapsearch failed ($RC)!"
199 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
200 1.1 lukem exit $RC
201 1.1 lukem fi
202 1.1 lukem
203 1.1 lukem echo "Adding schema and databases on producer..."
204 1.1 lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
205 1.1 lukem include: file://$ABS_SCHEMADIR/core.ldif
206 1.1 lukem
207 1.1 lukem include: file://$ABS_SCHEMADIR/cosine.ldif
208 1.1 lukem
209 1.1 lukem include: file://$ABS_SCHEMADIR/inetorgperson.ldif
210 1.1 lukem
211 1.1 lukem include: file://$ABS_SCHEMADIR/openldap.ldif
212 1.1 lukem
213 1.1 lukem include: file://$ABS_SCHEMADIR/nis.ldif
214 1.1 lukem EOF
215 1.1 lukem RC=$?
216 1.1 lukem if test $RC != 0 ; then
217 1.1 lukem echo "ldapadd failed for schema config ($RC)!"
218 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
219 1.1 lukem exit $RC
220 1.1 lukem fi
221 1.1 lukem
222 1.1 lukem if [ "$BACKENDTYPE" = mod ]; then
223 1.1 lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
224 1.1 lukem dn: cn=module,cn=config
225 1.1 lukem objectClass: olcModuleList
226 1.1 lukem cn: module
227 1.1 lukem olcModulePath: ../../../servers/slapd/back-$BACKEND
228 1.1 lukem olcModuleLoad: back_$BACKEND.la
229 1.1 lukem EOF
230 1.1 lukem RC=$?
231 1.1 lukem if test $RC != 0 ; then
232 1.1 lukem echo "ldapadd failed for backend config ($RC)!"
233 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
234 1.1 lukem exit $RC
235 1.1 lukem fi
236 1.1 lukem fi
237 1.1 lukem
238 1.1 lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
239 1.1 lukem dn: olcDatabase={1}$BACKEND,cn=config
240 1.1 lukem objectClass: olcDatabaseConfig
241 1.1 lukem objectClass: olc${BACKEND}Config
242 1.1 lukem olcDatabase: {1}$BACKEND
243 1.1 lukem olcSuffix: $BASEDN
244 1.1 lukem olcDbDirectory: ./db
245 1.1 lukem olcRootDN: $MANAGERDN
246 1.1 lukem olcRootPW: $PASSWD
247 1.1 lukem olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
248 1.1.1.2 lukem credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
249 1.1.1.2 lukem retry="3 5 300 5" timeout=3
250 1.1 lukem olcUpdateRef: $URI1
251 1.1 lukem
252 1.1 lukem dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
253 1.1 lukem changetype: add
254 1.1 lukem objectClass: olcOverlayConfig
255 1.1 lukem objectClass: olcSyncProvConfig
256 1.1 lukem olcOverlay: syncprov
257 1.1 lukem EOF
258 1.1 lukem RC=$?
259 1.1 lukem if test $RC != 0 ; then
260 1.1 lukem echo "ldapadd failed for database config ($RC)!"
261 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
262 1.1 lukem exit $RC
263 1.1 lukem fi
264 1.1 lukem
265 1.1.1.2 lukem case $BACKEND in
266 1.1.1.2 lukem bdb | hdb)
267 1.1.1.2 lukem $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
268 1.1.1.2 lukem dn: olcDatabase={1}$BACKEND,cn=config
269 1.1.1.2 lukem changetype: modify
270 1.1.1.2 lukem add: olcDbIndex
271 1.1.1.2 lukem olcDbIndex: objectClass,entryUUID,entryCSN eq
272 1.1.1.2 lukem olcDbIndex: cn,uid pres,eq,sub
273 1.1.1.2 lukem EOF
274 1.1.1.2 lukem RC=$?
275 1.1.1.2 lukem if test $RC != 0 ; then
276 1.1.1.2 lukem echo "ldapadd modify for database config ($RC)!"
277 1.1.1.2 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
278 1.1.1.2 lukem exit $RC
279 1.1.1.2 lukem fi
280 1.1.1.2 lukem ;;
281 1.1.1.2 lukem esac
282 1.1.1.2 lukem
283 1.1 lukem echo "Using ldapadd to populate producer..."
284 1.1 lukem $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
285 1.1 lukem >> $TESTOUT 2>&1
286 1.1 lukem RC=$?
287 1.1 lukem if test $RC != 0 ; then
288 1.1 lukem echo "ldapadd failed for database config ($RC)!"
289 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
290 1.1 lukem exit $RC
291 1.1 lukem fi
292 1.1 lukem
293 1.1.1.2 lukem echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
294 1.1.1.2 lukem sleep $SLEEP1
295 1.1 lukem
296 1.1 lukem echo "Using ldapsearch to check that syncrepl received database changes..."
297 1.1 lukem RC=32
298 1.1 lukem for i in 0 1 2 3 4 5; do
299 1.1 lukem RESULT=`$LDAPSEARCH -H $URI2 \
300 1.1 lukem -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
301 1.1 lukem '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
302 1.1 lukem if test "x$RESULT" = "xOK" ; then
303 1.1 lukem RC=0
304 1.1 lukem break
305 1.1 lukem fi
306 1.1.1.2 lukem echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
307 1.1.1.2 lukem sleep $SLEEP1
308 1.1 lukem done
309 1.1 lukem
310 1.1 lukem if test $RC != 0 ; then
311 1.1 lukem echo "ldapsearch failed ($RC)!"
312 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
313 1.1 lukem exit $RC
314 1.1 lukem fi
315 1.1 lukem
316 1.1.1.2 lukem echo "Replacing olcSyncrepl on producer..."
317 1.1.1.2 lukem $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
318 1.1.1.2 lukem dn: olcDatabase={0}config,cn=config
319 1.1.1.2 lukem changetype: modify
320 1.1.1.2 lukem replace: olcSyncRepl
321 1.1.1.2 lukem olcSyncRepl: rid=002 provider=$URI1 binddn="cn=config" bindmethod=simple
322 1.1.1.2 lukem credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
323 1.1.1.2 lukem retry="3 5 300 5" timeout=3
324 1.1.1.2 lukem EOF
325 1.1.1.2 lukem echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
326 1.1.1.2 lukem sleep $SLEEP1
327 1.1.1.2 lukem
328 1.1 lukem echo "Using ldapsearch to read config from the producer..."
329 1.1 lukem $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
330 1.1 lukem 'objectclass=*' > $MASTEROUT 2>&1
331 1.1 lukem RC=$?
332 1.1 lukem
333 1.1 lukem if test $RC != 0 ; then
334 1.1 lukem echo "ldapsearch failed at producer ($RC)!"
335 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
336 1.1 lukem exit $RC
337 1.1 lukem fi
338 1.1 lukem
339 1.1 lukem echo "Using ldapsearch to read config from the consumer..."
340 1.1 lukem $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
341 1.1 lukem 'objectclass=*' > $SLAVEOUT 2>&1
342 1.1 lukem RC=$?
343 1.1 lukem
344 1.1 lukem if test $RC != 0 ; then
345 1.1 lukem echo "ldapsearch failed at consumer ($RC)!"
346 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
347 1.1 lukem exit $RC
348 1.1 lukem fi
349 1.1 lukem
350 1.1 lukem echo "Filtering producer results..."
351 1.1 lukem . $LDIFFILTER < $MASTEROUT > $MASTERFLT
352 1.1 lukem echo "Filtering consumer results..."
353 1.1 lukem . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
354 1.1 lukem
355 1.1 lukem echo "Comparing retrieved configs from producer and consumer..."
356 1.1 lukem $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
357 1.1 lukem
358 1.1 lukem if test $? != 0 ; then
359 1.1 lukem echo "test failed - producer and consumer configs differ"
360 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
361 1.1 lukem exit 1
362 1.1 lukem fi
363 1.1 lukem
364 1.1 lukem echo "Using ldapsearch to read all the entries from the producer..."
365 1.1 lukem $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
366 1.1 lukem 'objectclass=*' > $MASTEROUT 2>&1
367 1.1 lukem RC=$?
368 1.1 lukem
369 1.1 lukem if test $RC != 0 ; then
370 1.1 lukem echo "ldapsearch failed at producer ($RC)!"
371 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
372 1.1 lukem exit $RC
373 1.1 lukem fi
374 1.1 lukem
375 1.1 lukem echo "Using ldapsearch to read all the entries from the consumer..."
376 1.1 lukem $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
377 1.1 lukem 'objectclass=*' > $SLAVEOUT 2>&1
378 1.1 lukem RC=$?
379 1.1 lukem
380 1.1 lukem if test $RC != 0 ; then
381 1.1 lukem echo "ldapsearch failed at consumer ($RC)!"
382 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
383 1.1 lukem exit $RC
384 1.1 lukem fi
385 1.1 lukem
386 1.1 lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
387 1.1 lukem
388 1.1 lukem echo "Filtering producer results..."
389 1.1 lukem . $LDIFFILTER < $MASTEROUT > $MASTERFLT
390 1.1 lukem echo "Filtering consumer results..."
391 1.1 lukem . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
392 1.1 lukem
393 1.1 lukem echo "Comparing retrieved entries from producer and consumer..."
394 1.1 lukem $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
395 1.1 lukem
396 1.1 lukem if test $? != 0 ; then
397 1.1 lukem echo "test failed - producer and consumer databases differ"
398 1.1 lukem exit 1
399 1.1 lukem fi
400 1.1 lukem
401 1.1 lukem echo ">>>>> Test succeeded"
402 1.1 lukem
403 1.1 lukem test $KILLSERVERS != no && wait
404 1.1 lukem
405 1.1 lukem exit 0
406