]> git.sur5r.net Git - openldap/blob - tests/scripts/test063-delta-multimaster
Happy New Year
[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-2018 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 interval=00:00:00:03"
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 test $INDEXDB = indexdb ; then
117 INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN,reqResult 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 THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
292 sleep 1
293 for i in 1 2 3; do
294         $LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
295                 -s base '(objectClass=*)' entryCSN > "${MASTEROUT}.$i" 2>&1
296         RC=$?
297
298         if test $RC = 0 ; then
299                 break
300         fi
301
302         if test $RC != 32 ; then
303                 echo "ldapsearch failed at slave ($RC)!"
304                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
305                 exit $RC
306         fi
307
308         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
309         sleep $SLEEP1
310 done
311
312 n=1
313 while [ $n -le $MMR ]; do
314 PORT=`expr $BASEPORT + $n`
315 URI="ldap://${LOCALHOST}:$PORT/"
316
317 echo "Using ldapsearch to read all the entries from server $n..."
318 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
319         'objectclass=*' > $TESTDIR/server$n.out 2>&1
320 RC=$?
321
322 if test $RC != 0 ; then
323         echo "ldapsearch failed at server $n ($RC)!"
324         test $KILLSERVERS != no && kill -HUP $KILLPIDS
325         exit $RC
326 fi
327 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
328 n=`expr $n + 1`
329 done
330
331 n=2
332 while [ $n -le $MMR ]; do
333 echo "Comparing retrieved entries from server 1 and server $n..."
334 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
335
336 if test $? != 0 ; then
337         echo "test failed - server 1 and server $n databases differ"
338         test $KILLSERVERS != no && kill -HUP $KILLPIDS
339         exit 1
340 fi
341 n=`expr $n + 1`
342 done
343
344 echo "Breaking replication between server 1 and 2..."
345 n=1
346 while [ $n -le $MMR ]; do
347 o=`expr 3 - $n`
348 MYURI=`eval echo '$URI'$n`
349 PROVIDERURI=`eval echo '$URI'$o`
350 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
351 dn: olcDatabase={2}$BACKEND,cn=config
352 changetype: modify
353 replace: olcSyncRepl
354 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
355   credentials=InvalidPw searchbase="$BASEDN" $SYNCTYPE
356   retry="3 +" timeout=3 logbase="cn=log"
357   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
358   syncdata=accesslog
359 -
360 replace: olcMirrorMode
361 olcMirrorMode: TRUE
362
363 EOF
364 RC=$?
365 if test $RC != 0 ; then
366         echo "ldapmodify failed for server $n config ($RC)!"
367         test $KILLSERVERS != no && kill -HUP $KILLPIDS
368         exit $RC
369 fi
370 n=`expr $n + 1`
371 done
372
373 echo "Using ldapmodify to force conflicts between server 1 and 2..."
374 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
375         >> $TESTOUT 2>&1 << EOF
376 dn: $THEDN
377 changetype: modify
378 add: description
379 description: Amazing
380
381 EOF
382 RC=$?
383 if test $RC != 0 ; then
384         echo "ldapmodify failed for server 1 database ($RC)!"
385         test $KILLSERVERS != no && kill -HUP $KILLPIDS
386         exit $RC
387 fi
388
389 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
390         >> $TESTOUT 2>&1 << EOF
391 dn: $THEDN
392 changetype: modify
393 add: description
394 description: Stupendous
395
396 EOF
397 RC=$?
398 if test $RC != 0 ; then
399         echo "ldapmodify failed for server 2 database ($RC)!"
400         test $KILLSERVERS != no && kill -HUP $KILLPIDS
401         exit $RC
402 fi
403
404 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
405         >> $TESTOUT 2>&1 << EOF
406 dn: $THEDN
407 changetype: modify
408 delete: description
409 description: Outstanding
410 -
411 add: description
412 description: Mindboggling
413
414 EOF
415 RC=$?
416 if test $RC != 0 ; then
417         echo "ldapmodify failed for server 1 database ($RC)!"
418         test $KILLSERVERS != no && kill -HUP $KILLPIDS
419         exit $RC
420 fi
421
422 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
423         >> $TESTOUT 2>&1 << EOF
424 dn: $THEDN
425 changetype: modify
426 delete: description
427 description: OutStanding
428 -
429 add: description
430 description: Bizarre
431
432 EOF
433 RC=$?
434 if test $RC != 0 ; then
435         echo "ldapmodify failed for server 2 database ($RC)!"
436         test $KILLSERVERS != no && kill -HUP $KILLPIDS
437         exit $RC
438 fi
439
440 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
441         >> $TESTOUT 2>&1 << EOF
442 dn: $THEDN
443 changetype: modify
444 add: carLicense
445 carLicense: 123-XYZ
446 -
447 add: employeeNumber
448 employeeNumber: 32
449
450 EOF
451 RC=$?
452 if test $RC != 0 ; then
453         echo "ldapmodify failed for server 1 database ($RC)!"
454         test $KILLSERVERS != no && kill -HUP $KILLPIDS
455         exit $RC
456 fi
457
458 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
459         >> $TESTOUT 2>&1 << EOF
460 dn: $THEDN
461 changetype: modify
462 add: employeeType
463 employeeType: deadwood
464 -
465 add: employeeNumber
466 employeeNumber: 64
467
468 EOF
469 RC=$?
470 if test $RC != 0 ; then
471         echo "ldapmodify failed for server 2 database ($RC)!"
472         test $KILLSERVERS != no && kill -HUP $KILLPIDS
473         exit $RC
474 fi
475
476 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
477         >> $TESTOUT 2>&1 << EOF
478 dn: $THEDN
479 changetype: modify
480 replace: sn
481 sn: Replaced later
482 -
483 replace: sn
484 sn: Surname
485 EOF
486 RC=$?
487 if test $RC != 0 ; then
488         echo "ldapmodify failed for server 1 database ($RC)!"
489         test $KILLSERVERS != no && kill -HUP $KILLPIDS
490         exit $RC
491 fi
492
493 echo "Restoring replication between server 1 and 2..."
494 n=1
495 while [ $n -le $MMR ]; do
496 o=`expr 3 - $n`
497 MYURI=`eval echo '$URI'$n`
498 PROVIDERURI=`eval echo '$URI'$o`
499 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
500 dn: olcDatabase={2}$BACKEND,cn=config
501 changetype: modify
502 replace: olcSyncRepl
503 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
504   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
505   retry="3 +" timeout=3 logbase="cn=log"
506   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
507   syncdata=accesslog
508 -
509 replace: olcMirrorMode
510 olcMirrorMode: TRUE
511
512 EOF
513 RC=$?
514 if test $RC != 0 ; then
515         echo "ldapmodify failed for server $n config ($RC)!"
516         test $KILLSERVERS != no && kill -HUP $KILLPIDS
517         exit $RC
518 fi
519 n=`expr $n + 1`
520 done
521
522 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
523 sleep $SLEEP1
524
525 n=1
526 while [ $n -le $MMR ]; do
527 PORT=`expr $BASEPORT + $n`
528 URI="ldap://${LOCALHOST}:$PORT/"
529
530 echo "Using ldapsearch to read all the entries from server $n..."
531 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
532         'objectclass=*' > $TESTDIR/server$n.out 2>&1
533 RC=$?
534
535 if test $RC != 0 ; then
536         echo "ldapsearch failed at server $n ($RC)!"
537         test $KILLSERVERS != no && kill -HUP $KILLPIDS
538         exit $RC
539 fi
540 $LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
541 n=`expr $n + 1`
542 done
543
544 n=2
545 while [ $n -le $MMR ]; do
546 echo "Comparing retrieved entries from server 1 and server $n..."
547 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
548
549 if test $? != 0 ; then
550         echo "test failed - server 1 and server $n databases differ"
551         test $KILLSERVERS != no && kill -HUP $KILLPIDS
552         exit 1
553 fi
554 n=`expr $n + 1`
555 done
556
557 test $KILLSERVERS != no && kill -HUP $KILLPIDS
558
559 echo ">>>>> Test succeeded"
560
561 test $KILLSERVERS != no && wait
562
563 exit 0