]> git.sur5r.net Git - openldap/blob - tests/scripts/test063-delta-multimaster
More fixes, add test script
[openldap] / tests / scripts / test063-delta-multimaster
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2011 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 if test $ACCESSLOG = accesslogno; then
24         echo "Accesslog overlay not available, test skipped"
25         exit 0
26 fi
27
28 MMR=2
29
30 XDIR=$TESTDIR/srv
31 TMP=$TESTDIR/tmp
32
33 mkdir -p $TESTDIR
34
35 $SLAPPASSWD -g -n >$CONFIGPWF
36
37 if test x"$SYNCMODE" = x ; then
38         SYNCMODE=rp
39 fi
40 case "$SYNCMODE" in
41         ro)
42                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
43                 ;;
44         rp)
45                 SYNCTYPE="type=refreshAndPersist"
46                 ;;
47         *)
48                 echo "unknown sync mode $SYNCMODE"
49                 exit 1;
50                 ;;
51 esac
52
53 #
54 # Test delta-sync mmr
55 # - start servers
56 # - configure over ldap
57 # - populate over ldap
58 # - configure syncrepl over ldap
59 # - break replication
60 # - modify each server separately
61 # - restore replication
62 # - compare results
63 #
64
65 nullExclude=""
66 test $BACKEND = null && nullExclude="# "
67
68 KILLPIDS=
69
70 echo "Initializing server configurations..."
71 n=1
72 while [ $n -le $MMR ]; do
73
74 DBDIR=${XDIR}$n/db
75 CFDIR=${XDIR}$n/slapd.d
76
77 mkdir -p ${XDIR}$n $DBDIR.1 $DBDIR.2 $CFDIR
78
79 o=`expr 3 - $n`
80 cat > $TMP <<EOF
81 dn: cn=config
82 objectClass: olcGlobal
83 cn: config
84 olcServerID: $n
85
86 EOF
87
88 if [ "$SYNCPROV" = syncprovmod -o "$ACCESSLOG" = accesslogmod ]; then
89   cat <<EOF >> $TMP
90 dn: cn=module,cn=config
91 objectClass: olcModuleList
92 cn: module
93 olcModulePath: $TESTWD/../servers/slapd/overlays
94 EOF
95   if [ "$SYNCPROV" = syncprovmod ]; then
96   echo "olcModuleLoad: syncprov.la" >> $TMP
97   fi
98   if [ "$ACCESSLOG" = accesslogmod ]; then
99   echo "olcModuleLoad: accesslog.la" >> $TMP
100   fi
101   echo "" >> $TMP
102 fi
103
104 if [ "$BACKENDTYPE" = mod ]; then
105 cat <<EOF >> $TMP
106 dn: cn=module,cn=config
107 objectClass: olcModuleList
108 cn: module
109 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
110 olcModuleLoad: back_$BACKEND.la
111
112 EOF
113 fi
114 MYURI=`eval echo '$URI'$n`
115 PROVIDERURI=`eval echo '$URI'$o`
116 if [ $BACKEND = hdb -o $BACKEND = bdb ]; then
117 INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN eq"
118 INDEX2="olcDbIndex: objectClass,entryCSN,entryUUID eq"
119 else
120 INDEX1=
121 INDEX2=
122 fi
123 cat >> $TMP <<EOF
124 dn: cn=schema,cn=config
125 objectclass: olcSchemaconfig
126 cn: schema
127
128 include: file://$ABS_SCHEMADIR/core.ldif
129
130 include: file://$ABS_SCHEMADIR/cosine.ldif
131
132 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
133
134 include: file://$ABS_SCHEMADIR/openldap.ldif
135
136 include: file://$ABS_SCHEMADIR/nis.ldif
137
138 dn: olcDatabase={0}config,cn=config
139 objectClass: olcDatabaseConfig
140 olcDatabase: {0}config
141 olcRootPW:< file://$CONFIGPWF
142
143 dn: olcDatabase={1}$BACKEND,cn=config
144 objectClass: olcDatabaseConfig
145 ${nullExclude}objectClass: olc${BACKEND}Config
146 olcDatabase: {1}$BACKEND
147 olcSuffix: cn=log
148 ${nullExclude}olcDbDirectory: ${DBDIR}.1
149 olcRootDN: $MANAGERDN
150 $INDEX1
151
152 dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
153 objectClass: olcOverlayConfig
154 objectClass: olcSyncProvConfig
155 olcOverlay: syncprov
156 olcSpNoPresent: TRUE
157 olcSpReloadHint: TRUE
158
159 dn: olcDatabase={2}$BACKEND,cn=config
160 objectClass: olcDatabaseConfig
161 ${nullExclude}objectClass: olc${BACKEND}Config
162 olcDatabase: {2}$BACKEND
163 olcSuffix: $BASEDN
164 ${nullExclude}olcDbDirectory: ${DBDIR}.2
165 olcRootDN: $MANAGERDN
166 olcRootPW: $PASSWD
167 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
168   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
169   retry="3 +" timeout=3 logbase="cn=log"
170   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
171   syncdata=accesslog
172 olcMirrorMode: TRUE
173 $INDEX2
174
175 dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
176 objectClass: olcOverlayConfig
177 objectClass: olcSyncProvConfig
178 olcOverlay: syncprov
179
180 dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
181 objectClass: olcOverlayConfig
182 objectClass: olcAccessLogConfig
183 olcOverlay: accesslog
184 olcAccessLogDB: cn=log
185 olcAccessLogOps: writes
186 olcAccessLogSuccess: TRUE
187
188 EOF
189 $SLAPADD -F $CFDIR -n 0  -d-1< $TMP > $TESTOUT 2>&1
190 PORT=`eval echo '$PORT'$n`
191 echo "Starting server $n on TCP/IP port $PORT..."
192 cd ${XDIR}${n}
193 LOG=`eval echo '$LOG'$n`
194 $SLAPD -F slapd.d -h $MYURI -d $LVL $TIMING > $LOG 2>&1 &
195 PID=$!
196 if test $WAIT != 0 ; then
197     echo PID $PID
198     read foo
199 fi
200 KILLPIDS="$PID $KILLPIDS"
201 cd $TESTWD
202
203 echo "Using ldapsearch to check that server $n is running..."
204 for i in 0 1 2 3 4 5; do
205         $LDAPSEARCH -s base -b "" -H $MYURI \
206                 'objectclass=*' > /dev/null 2>&1
207         RC=$?
208         if test $RC = 0 ; then
209                 break
210         fi
211         echo "Waiting 5 seconds for slapd to start..."
212         sleep 5
213 done
214
215 if test $RC != 0 ; then
216         echo "ldapsearch failed ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 if [ $n = 1 ]; then
222 echo "Using ldapadd for context on server 1..."
223 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDCP \
224         >> $TESTOUT 2>&1
225 RC=$?
226 if test $RC != 0 ; then
227         echo "ldapadd failed for server $n database ($RC)!"
228         test $KILLSERVERS != no && kill -HUP $KILLPIDS
229         exit $RC
230 fi
231 fi
232
233 n=`expr $n + 1`
234 done
235
236 echo "Using ldapadd to populate server 1..."
237 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDNOCP \
238         >> $TESTOUT 2>&1
239 RC=$?
240 if test $RC != 0 ; then
241         echo "ldapadd failed for server $n database ($RC)!"
242         test $KILLSERVERS != no && kill -HUP $KILLPIDS
243         exit $RC
244 fi
245
246 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
247 sleep $SLEEP1
248
249 n=1
250 while [ $n -le $MMR ]; do
251 PORT=`expr $BASEPORT + $n`
252 URI="ldap://${LOCALHOST}:$PORT/"
253
254 echo "Using ldapsearch to read all the entries from server $n..."
255 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
256         'objectclass=*' > $TESTDIR/server$n.out 2>&1
257 RC=$?
258
259 if test $RC != 0 ; then
260         echo "ldapsearch failed at server $n ($RC)!"
261         test $KILLSERVERS != no && kill -HUP $KILLPIDS
262         exit $RC
263 fi
264 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
265 n=`expr $n + 1`
266 done
267
268 n=2
269 while [ $n -le $MMR ]; do
270 echo "Comparing retrieved entries from server 1 and server $n..."
271 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
272
273 if test $? != 0 ; then
274         echo "test failed - server 1 and server $n databases differ"
275         test $KILLSERVERS != no && kill -HUP $KILLPIDS
276         exit 1
277 fi
278 n=`expr $n + 1`
279 done
280
281 echo "Using ldapadd to populate server 2..."
282 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
283         >> $TESTOUT 2>&1
284 RC=$?
285 if test $RC != 0 ; then
286         echo "ldapadd failed for server 2 database ($RC)!"
287         test $KILLSERVERS != no && kill -HUP $KILLPIDS
288         exit $RC
289 fi
290
291 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
292 sleep $SLEEP1
293
294 n=1
295 while [ $n -le $MMR ]; do
296 PORT=`expr $BASEPORT + $n`
297 URI="ldap://${LOCALHOST}:$PORT/"
298
299 echo "Using ldapsearch to read all the entries from server $n..."
300 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
301         'objectclass=*' > $TESTDIR/server$n.out 2>&1
302 RC=$?
303
304 if test $RC != 0 ; then
305         echo "ldapsearch failed at server $n ($RC)!"
306         test $KILLSERVERS != no && kill -HUP $KILLPIDS
307         exit $RC
308 fi
309 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
310 n=`expr $n + 1`
311 done
312
313 n=2
314 while [ $n -le $MMR ]; do
315 echo "Comparing retrieved entries from server 1 and server $n..."
316 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
317
318 if test $? != 0 ; then
319         echo "test failed - server 1 and server $n databases differ"
320         test $KILLSERVERS != no && kill -HUP $KILLPIDS
321         exit 1
322 fi
323 n=`expr $n + 1`
324 done
325
326 echo "Breaking replication between server 1 and 2..."
327 n=1
328 while [ $n -le $MMR ]; do
329 o=`expr 3 - $n`
330 MYURI=`eval echo '$URI'$n`
331 PROVIDERURI=`eval echo '$URI'$o`
332 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
333 dn: olcDatabase={2}$BACKEND,cn=config
334 changetype: modify
335 replace: olcSyncRepl
336 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
337   credentials=InvalidPw searchbase="$BASEDN" $SYNCTYPE
338   retry="3 +" timeout=3 logbase="cn=log"
339   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
340   syncdata=accesslog
341 -
342 replace: olcMirrorMode
343 olcMirrorMode: TRUE
344
345 EOF
346 RC=$?
347 if test $RC != 0 ; then
348         echo "ldapmodify failed for server $n config ($RC)!"
349         test $KILLSERVERS != no && kill -HUP $KILLPIDS
350         exit $RC
351 fi
352 n=`expr $n + 1`
353 done
354
355 echo "Using ldapmodify to force conflicts between server 1 and 2..."
356 THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
357 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
358         >> $TESTOUT 2>&1 << EOF
359 dn: $THEDN
360 changetype: modify
361 add: description
362 description: Amazing
363
364 EOF
365 RC=$?
366 if test $RC != 0 ; then
367         echo "ldapmodify failed for server 1 database ($RC)!"
368         test $KILLSERVERS != no && kill -HUP $KILLPIDS
369         exit $RC
370 fi
371
372 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
373         >> $TESTOUT 2>&1 << EOF
374 dn: $THEDN
375 changetype: modify
376 add: description
377 description: Stupendous
378
379 EOF
380 RC=$?
381 if test $RC != 0 ; then
382         echo "ldapmodify failed for server 2 database ($RC)!"
383         test $KILLSERVERS != no && kill -HUP $KILLPIDS
384         exit $RC
385 fi
386
387 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
388         >> $TESTOUT 2>&1 << EOF
389 dn: $THEDN
390 changetype: modify
391 delete: description
392 description: Outstanding
393 -
394 add: description
395 description: Mindboggling
396
397 EOF
398 RC=$?
399 if test $RC != 0 ; then
400         echo "ldapmodify failed for server 1 database ($RC)!"
401         test $KILLSERVERS != no && kill -HUP $KILLPIDS
402         exit $RC
403 fi
404
405 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
406         >> $TESTOUT 2>&1 << EOF
407 dn: $THEDN
408 changetype: modify
409 delete: description
410 description: OutStanding
411 -
412 add: description
413 description: Bizarre
414
415 EOF
416 RC=$?
417 if test $RC != 0 ; then
418         echo "ldapmodify failed for server 2 database ($RC)!"
419         test $KILLSERVERS != no && kill -HUP $KILLPIDS
420         exit $RC
421 fi
422
423 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
424         >> $TESTOUT 2>&1 << EOF
425 dn: $THEDN
426 changetype: modify
427 add: carLicense
428 carLicense: 123-XYZ
429 -
430 add: employeeNumber
431 employeeNumber: 32
432
433 EOF
434 RC=$?
435 if test $RC != 0 ; then
436         echo "ldapmodify failed for server 1 database ($RC)!"
437         test $KILLSERVERS != no && kill -HUP $KILLPIDS
438         exit $RC
439 fi
440
441 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
442         >> $TESTOUT 2>&1 << EOF
443 dn: $THEDN
444 changetype: modify
445 add: employeeType
446 employeeType: deadwood
447 -
448 add: employeeNumber
449 employeeNumber: 64
450
451 EOF
452 RC=$?
453 if test $RC != 0 ; then
454         echo "ldapmodify failed for server 2 database ($RC)!"
455         test $KILLSERVERS != no && kill -HUP $KILLPIDS
456         exit $RC
457 fi
458
459 echo "Restoring replication between server 1 and 2..."
460 n=1
461 while [ $n -le $MMR ]; do
462 o=`expr 3 - $n`
463 MYURI=`eval echo '$URI'$n`
464 PROVIDERURI=`eval echo '$URI'$o`
465 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
466 dn: olcDatabase={2}$BACKEND,cn=config
467 changetype: modify
468 replace: olcSyncRepl
469 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
470   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
471   retry="3 +" timeout=3 logbase="cn=log"
472   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
473   syncdata=accesslog
474 -
475 replace: olcMirrorMode
476 olcMirrorMode: TRUE
477
478 EOF
479 RC=$?
480 if test $RC != 0 ; then
481         echo "ldapmodify failed for server $n config ($RC)!"
482         test $KILLSERVERS != no && kill -HUP $KILLPIDS
483         exit $RC
484 fi
485 n=`expr $n + 1`
486 done
487
488 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
489 sleep $SLEEP1
490
491 n=1
492 while [ $n -le $MMR ]; do
493 PORT=`expr $BASEPORT + $n`
494 URI="ldap://${LOCALHOST}:$PORT/"
495
496 echo "Using ldapsearch to read all the entries from server $n..."
497 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
498         'objectclass=*' > $TESTDIR/server$n.out 2>&1
499 RC=$?
500
501 if test $RC != 0 ; then
502         echo "ldapsearch failed at server $n ($RC)!"
503         test $KILLSERVERS != no && kill -HUP $KILLPIDS
504         exit $RC
505 fi
506 $LDIFFILTER -s $BACKEND=a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
507 n=`expr $n + 1`
508 done
509
510 n=2
511 while [ $n -le $MMR ]; do
512 echo "Comparing retrieved entries from server 1 and server $n..."
513 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
514
515 if test $? != 0 ; then
516         echo "test failed - server 1 and server $n databases differ"
517         test $KILLSERVERS != no && kill -HUP $KILLPIDS
518         exit 1
519 fi
520 n=`expr $n + 1`
521 done
522
523 test $KILLSERVERS != no && kill -HUP $KILLPIDS
524
525 echo ">>>>> Test succeeded"
526
527 test $KILLSERVERS != no && wait
528
529 exit 0