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