]> git.sur5r.net Git - openldap/blob - tests/scripts/test050-syncrepl-multimaster
ITS#5189
[openldap] / tests / scripts / test050-syncrepl-multimaster
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2007 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
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $SYNCPROV = syncprovno; then 
20         echo "Syncrepl provider overlay not available, test skipped"
21         exit 0
22 fi 
23
24 PRODIR=$TESTDIR/pro
25 CONDIR=$TESTDIR/con
26 DBPRO=$PRODIR/db
27 DBCON=$CONDIR/db
28 CFPRO=$PRODIR/slapd.d
29 CFCON=$CONDIR/slapd.d
30
31 mkdir -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
45 echo "Initializing server configurations..."
46 $SLAPADD -F $CFCON -n 0 <<EOF
47 dn: cn=config
48 objectClass: olcGlobal
49 cn: config
50 olcServerID: 2
51
52 dn: olcDatabase={0}config,cn=config
53 objectClass: olcDatabaseConfig
54 olcDatabase: {0}config
55 olcRootPW:< file://$CONFIGPWF
56 EOF
57
58 $SLAPADD -F $CFPRO -n 0 <<EOF
59 dn: cn=config
60 objectClass: olcGlobal
61 cn: config
62 olcServerID: 1
63
64 dn: olcDatabase={0}config,cn=config
65 objectClass: olcDatabaseConfig
66 olcDatabase: {0}config
67 olcRootPW:< file://$CONFIGPWF
68 EOF
69
70 echo "Starting producer slapd on TCP/IP port $PORT1..."
71 cd $PRODIR
72 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
73 PID=$!
74 if test $WAIT != 0 ; then
75     echo PID $PID
76     read foo
77 fi
78 KILLPIDS="$PID"
79 cd $TESTWD
80
81 sleep 1
82
83 echo "Using ldapsearch to check that producer slapd is running..."
84 for i in 0 1 2 3 4 5; do
85         $LDAPSEARCH -s base -b "" -H $URI1 \
86                 'objectclass=*' > /dev/null 2>&1
87         RC=$?
88         if test $RC = 0 ; then
89                 break
90         fi
91         echo "Waiting 5 seconds for slapd to start..."
92         sleep 5
93 done
94
95 if test $RC != 0 ; then
96         echo "ldapsearch failed ($RC)!"
97         test $KILLSERVERS != no && kill -HUP $KILLPIDS
98         exit $RC
99 fi
100
101 echo "Inserting syncprov overlay on producer..."
102 if [ "$SYNCPROV" = syncprovmod ]; then
103         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
104 dn: cn=module,cn=config
105 objectClass: olcModuleList
106 cn: module
107 olcModulePath: ../../../servers/slapd/overlays
108 olcModuleLoad: syncprov.la
109 EOF
110         RC=$?
111         if test $RC != 0 ; then
112                 echo "ldapadd failed for moduleLoad ($RC)!"
113                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
114                 exit $RC
115         fi
116 fi
117 #
118 # Note that we configure a timeout here; it's possible for both
119 # servers to attempt to bind to each other while a modify to
120 # cn=config is in progress. When the modify pauses the thread pool
121 # neither server will progress. The timeout will drop the syncrepl
122 # attempt and allow the modifies to complete.
123 #
124 read CONFIGPW < $CONFIGPWF
125 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
126 dn: cn=config
127 changetype: modify
128 replace: olcServerID
129 olcServerID: 1 $URI1
130 olcServerID: 2 $URI2
131
132 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
133 changetype: add
134 objectClass: olcOverlayConfig
135 objectClass: olcSyncProvConfig
136 olcOverlay: syncprov
137
138 dn: olcDatabase={0}config,cn=config
139 changetype: modify
140 add: olcSyncRepl
141 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
142   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
143   retry="5 5 300 5" timeout=1
144 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
145   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
146   retry="5 5 300 5" timeout=1
147 -
148 add: olcMirrorMode
149 olcMirrorMode: TRUE
150 EOF
151 RC=$?
152 if test $RC != 0 ; then
153         echo "ldapmodify failed for syncrepl config ($RC)!"
154         test $KILLSERVERS != no && kill -HUP $KILLPIDS
155         exit $RC
156 fi
157
158 echo "Starting consumer slapd on TCP/IP port $PORT2..."
159 cd $CONDIR
160 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
161 SLAVEPID=$!
162 if test $WAIT != 0 ; then
163     echo SLAVEPID $SLAVEPID
164     read foo
165 fi
166 KILLPIDS="$KILLPIDS $SLAVEPID"
167 cd $TESTWD
168
169 sleep 1
170
171 echo "Using ldapsearch to check that consumer slapd is running..."
172 for i in 0 1 2 3 4 5; do
173         $LDAPSEARCH -s base -b "" -H $URI2 \
174                 'objectclass=*' > /dev/null 2>&1
175         RC=$?
176         if test $RC = 0 ; then
177                 break
178         fi
179         echo "Waiting 5 seconds for slapd to start..."
180         sleep 5
181 done
182
183 if test $RC != 0 ; then
184         echo "ldapsearch failed ($RC)!"
185         test $KILLSERVERS != no && kill -HUP $KILLPIDS
186         exit $RC
187 fi
188
189 echo "Configuring syncrepl on consumer..."
190 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
191 dn: olcDatabase={0}config,cn=config
192 changetype: modify
193 add: olcSyncRepl
194 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
195   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
196   retry="5 5 300 5" timeout=1
197 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
198   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
199   retry="5 5 300 5" timeout=1
200 -
201 add: olcMirrorMode
202 olcMirrorMode: TRUE
203 EOF
204
205 echo "Adding schema and databases on producer..."
206 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
207 include: file://$ABS_SCHEMADIR/core.ldif
208
209 include: file://$ABS_SCHEMADIR/cosine.ldif
210
211 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
212
213 include: file://$ABS_SCHEMADIR/openldap.ldif
214
215 include: file://$ABS_SCHEMADIR/nis.ldif
216 EOF
217 RC=$?
218 if test $RC != 0 ; then
219         echo "ldapadd failed for schema config ($RC)!"
220         test $KILLSERVERS != no && kill -HUP $KILLPIDS
221         exit $RC
222 fi
223
224 if [ "$BACKENDTYPE" = mod ]; then
225         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
226 dn: cn=module,cn=config
227 objectClass: olcModuleList
228 cn: module
229 olcModulePath: ../../../servers/slapd/back-$BACKEND
230 olcModuleLoad: back_$BACKEND.la
231 EOF
232         RC=$?
233         if test $RC != 0 ; then
234                 echo "ldapadd failed for backend config ($RC)!"
235                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
236                 exit $RC
237         fi
238 fi
239
240 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
241 dn: olcDatabase={1}$BACKEND,cn=config
242 objectClass: olcDatabaseConfig
243 objectClass: olc${BACKEND}Config
244 olcDatabase: {1}$BACKEND
245 olcSuffix: $BASEDN
246 olcDbDirectory: ./db
247 olcRootDN: $MANAGERDN
248 olcRootPW: $PASSWD
249 olcSyncRepl: rid=003 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
250   credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
251   interval=00:00:00:10 retry="5 5 300 5" timeout=1
252 olcSyncRepl: rid=004 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
253   credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
254   interval=00:00:00:10 retry="5 5 300 5" timeout=1
255 olcMirrorMode: TRUE
256
257 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
258 changetype: add
259 objectClass: olcOverlayConfig
260 objectClass: olcSyncProvConfig
261 olcOverlay: syncprov
262 EOF
263 RC=$?
264 if test $RC != 0 ; then
265         echo "ldapadd failed for database config ($RC)!"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit $RC
268 fi
269
270 echo "Using ldapadd to populate producer..."
271 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
272         >> $TESTOUT 2>&1
273 RC=$?
274 if test $RC != 0 ; then
275         echo "ldapadd failed for database config ($RC)!"
276         test $KILLSERVERS != no && kill -HUP $KILLPIDS
277         exit $RC
278 fi
279
280 SLEEP=20
281 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
282 sleep $SLEEP
283
284 echo "Using ldapsearch to check that syncrepl received database changes..."
285 RC=32
286 for i in 0 1 2 3 4 5; do
287         RESULT=`$LDAPSEARCH -H $URI2 \
288                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
289                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
290         if test "x$RESULT" = "xOK" ; then
291                 RC=0
292                 break
293         fi
294         echo "Waiting 5 seconds for syncrepl to receive changes..."
295         sleep 5
296 done
297
298 if test $RC != 0 ; then
299         echo "ldapsearch failed ($RC)!"
300         test $KILLSERVERS != no && kill -HUP $KILLPIDS
301         exit $RC
302 fi
303
304 echo "Using ldapsearch to read config from the producer..."
305 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
306         'objectclass=*' > $MASTEROUT 2>&1
307 RC=$?
308
309 if test $RC != 0 ; then
310         echo "ldapsearch failed at producer ($RC)!"
311         test $KILLSERVERS != no && kill -HUP $KILLPIDS
312         exit $RC
313 fi
314
315 echo "Using ldapsearch to read config from the consumer..."
316 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
317         'objectclass=*' > $SLAVEOUT 2>&1
318 RC=$?
319
320 if test $RC != 0 ; then
321         echo "ldapsearch failed at consumer ($RC)!"
322         test $KILLSERVERS != no && kill -HUP $KILLPIDS
323         exit $RC
324 fi
325
326 echo "Filtering producer results..."
327 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
328 echo "Filtering consumer results..."
329 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
330
331 echo "Comparing retrieved configs from producer and consumer..."
332 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
333
334 if test $? != 0 ; then
335         echo "test failed - producer and consumer configs differ"
336         test $KILLSERVERS != no && kill -HUP $KILLPIDS
337         exit 1
338 fi
339
340 echo "Using ldapsearch to read all the entries from the producer..."
341 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
342         'objectclass=*' > $MASTEROUT 2>&1
343 RC=$?
344
345 if test $RC != 0 ; then
346         echo "ldapsearch failed at producer ($RC)!"
347         test $KILLSERVERS != no && kill -HUP $KILLPIDS
348         exit $RC
349 fi
350
351 echo "Using ldapsearch to read all the entries from the consumer..."
352 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
353         'objectclass=*' > $SLAVEOUT 2>&1
354 RC=$?
355
356 if test $RC != 0 ; then
357         echo "ldapsearch failed at consumer ($RC)!"
358         test $KILLSERVERS != no && kill -HUP $KILLPIDS
359         exit $RC
360 fi
361
362 test $KILLSERVERS != no && kill -HUP $KILLPIDS
363
364 echo "Filtering producer results..."
365 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
366 echo "Filtering consumer results..."
367 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
368
369 echo "Comparing retrieved entries from producer and consumer..."
370 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
371
372 if test $? != 0 ; then
373         echo "test failed - producer and consumer databases differ"
374         exit 1
375 fi
376
377 test $KILLSERVERS != no && wait
378
379 echo "Restarting servers..."
380 echo "Starting producer slapd on TCP/IP port $PORT1..."
381 cd $PRODIR
382 echo "======================= RESTART =======================" >> $LOG1
383 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
384 PID=$!
385 if test $WAIT != 0 ; then
386     echo PID $PID
387     read foo
388 fi
389 KILLPIDS="$PID"
390 cd $TESTWD
391 echo "Using ldapsearch to check that producer slapd is running..."
392 for i in 0 1 2 3 4 5; do
393         $LDAPSEARCH -s base -b "" -H $URI1 \
394                 'objectclass=*' > /dev/null 2>&1
395         RC=$?
396         if test $RC = 0 ; then
397                 break
398         fi
399         echo "Waiting 5 seconds for slapd to start..."
400         sleep 5
401 done
402
403 if test $RC != 0 ; then
404         echo "ldapsearch failed ($RC)!"
405         test $KILLSERVERS != no && kill -HUP $KILLPIDS
406         exit $RC
407 fi
408 #exit 0
409 echo "Starting consumer slapd on TCP/IP port $PORT2..."
410 cd $CONDIR
411 echo "======================= RESTART =======================" >> $LOG2
412 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
413 SLAVEPID=$!
414 if test $WAIT != 0 ; then
415     echo SLAVEPID $SLAVEPID
416     read foo
417 fi
418 KILLPIDS="$KILLPIDS $SLAVEPID"
419 cd $TESTWD
420
421 sleep 1
422
423 echo "Using ldapsearch to check that consumer slapd is running..."
424 for i in 0 1 2 3 4 5; do
425         $LDAPSEARCH -s base -b "" -H $URI2 \
426                 'objectclass=*' > /dev/null 2>&1
427         RC=$?
428         if test $RC = 0 ; then
429                 break
430         fi
431         echo "Waiting 5 seconds for slapd to start..."
432         sleep 5
433 done
434
435 if test $RC != 0 ; then
436         echo "ldapsearch failed ($RC)!"
437         test $KILLSERVERS != no && kill -HUP $KILLPIDS
438         exit $RC
439 fi
440
441 # Insert modifications and more tests here.
442 SLEEP=10
443 echo "Waiting $SLEEP seconds for servers to resync..."
444 sleep $SLEEP
445
446 test $KILLSERVERS != no && kill -HUP $KILLPIDS
447
448 echo ">>>>> Test succeeded"
449
450 test $KILLSERVERS != no && wait
451
452 exit 0