Debian Codegraph @

tests/scripts/test063-delta-multiprovider

raw
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2024 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 MPR=${MPR-4}
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 mpr
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 $MPR ]; 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 cat > $TMP <<EOF
80 dn: cn=config
81 objectClass: olcGlobal
82 cn: config
83 EOF
84
85 o=1
86 while [ $o -le $MPR ]; do
87 PORT=`expr $BASEPORT + $o`
88 URI="ldap://${LOCALHOST}:$PORT/"
89 echo "olcServerID: $o $URI" >> $TMP
90 o=`expr $o + 1`
91 done
92 echo "" >> $TMP
93
94 if [ "$SYNCPROV" = syncprovmod -o "$ACCESSLOG" = accesslogmod ]; then
95 cat <<EOF >> $TMP
96 dn: cn=module,cn=config
97 objectClass: olcModuleList
98 cn: module
99 olcModulePath: $TESTWD/../servers/slapd/overlays
100 EOF
101 if [ "$SYNCPROV" = syncprovmod ]; then
102 echo "olcModuleLoad: syncprov.la" >> $TMP
103 fi
104 if [ "$ACCESSLOG" = accesslogmod ]; then
105 echo "olcModuleLoad: accesslog.la" >> $TMP
106 fi
107 echo "" >> $TMP
108 fi
109
110 if [ "$BACKENDTYPE" = mod ]; then
111 cat <<EOF >> $TMP
112 dn: cn=module,cn=config
113 objectClass: olcModuleList
114 cn: module
115 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
116 olcModuleLoad: back_$BACKEND.la
117
118 EOF
119 fi
120
121 MYURI=`eval echo '$URI'$n`
122 PROVIDERURI=`eval echo '$URI'$o`
123 if test $INDEXDB = indexdb ; then
124 INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN,reqResult eq"
125 INDEX2="olcDbIndex: objectClass,entryCSN,entryUUID eq"
126 else
127 INDEX1=
128 INDEX2=
129 fi
130 cat >> $TMP <<EOF
131 dn: cn=schema,cn=config
132 objectclass: olcSchemaconfig
133 cn: schema
134
135 include: file://$ABS_SCHEMADIR/core.ldif
136
137 include: file://$ABS_SCHEMADIR/cosine.ldif
138
139 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
140
141 include: file://$ABS_SCHEMADIR/openldap.ldif
142
143 include: file://$ABS_SCHEMADIR/nis.ldif
144
145 dn: olcDatabase={0}config,cn=config
146 objectClass: olcDatabaseConfig
147 olcDatabase: {0}config
148 olcRootPW:< file://$CONFIGPWF
149
150 dn: olcDatabase={1}$BACKEND,cn=config
151 objectClass: olcDatabaseConfig
152 ${nullExclude}objectClass: olc${BACKEND}Config
153 olcDatabase: {1}$BACKEND
154 olcSuffix: cn=log
155 ${nullExclude}olcDbDirectory: ${DBDIR}.1
156 olcRootDN: $MANAGERDN
157 $INDEX1
158
159 dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
160 objectClass: olcOverlayConfig
161 objectClass: olcSyncProvConfig
162 olcOverlay: syncprov
163 olcSpNoPresent: TRUE
164 olcSpReloadHint: TRUE
165
166 dn: olcDatabase={2}$BACKEND,cn=config
167 objectClass: olcDatabaseConfig
168 ${nullExclude}objectClass: olc${BACKEND}Config
169 olcDatabase: {2}$BACKEND
170 olcSuffix: $BASEDN
171 ${nullExclude}olcDbDirectory: ${DBDIR}.2
172 olcRootDN: $MANAGERDN
173 olcRootPW: $PASSWD
174 EOF
175
176 o=1
177 while [ $o -le $MPR ]; do
178 PORT=`expr $BASEPORT + $o`
179 URI="ldap://${LOCALHOST}:$PORT/"
180 cat >>$TMP <<EOF
181 olcSyncRepl: rid=00$o provider=$URI binddn="$MANAGERDN" bindmethod=simple
182 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
183 retry="3 +" timeout=3 logbase="cn=log"
184 logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
185 syncdata=accesslog
186 EOF
187 o=`expr $o + 1`
188 done
189
190 cat >> $TMP <<EOF
191 olcMultiProvider: TRUE
192 $INDEX2
193
194 dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
195 objectClass: olcOverlayConfig
196 objectClass: olcSyncProvConfig
197 olcOverlay: syncprov
198
199 dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
200 objectClass: olcOverlayConfig
201 objectClass: olcAccessLogConfig
202 olcOverlay: accesslog
203 olcAccessLogDB: cn=log
204 olcAccessLogOps: writes
205 olcAccessLogSuccess: TRUE
206
207 EOF
208 cat <<EOF >> $TMP
209 dn: olcDatabase={3}monitor,cn=config
210 objectClass: olcDatabaseConfig
211 objectClass: olcmonitorConfig
212 olcDatabase: {3}monitor
213
214 EOF
215
216 $SLAPADD -F $CFDIR -n 0 -d-1< $TMP > $TESTOUT 2>&1
217 RC=$?
218 if test $RC != 0 ; then
219 echo "slapadd failed ($RC)!"
220 exit $RC
221 fi
222
223 PORT=`eval echo '$PORT'$n`
224 echo "Starting server $n on TCP/IP port $PORT..."
225 cd ${XDIR}${n}
226 LOG=`eval echo '$LOG'$n`
227 $SLAPD -F slapd.d -h $MYURI -d $LVL > $LOG 2>&1 &
228 PID=$!
229 if test $WAIT != 0 ; then
230 echo PID $PID
231 read foo
232 fi
233 KILLPIDS="$PID $KILLPIDS"
234 cd $TESTWD
235
236 echo "Using ldapsearch to check that server $n is running..."
237 sleep 1
238 for i in 0 1 2 3 4 5; do
239 $LDAPSEARCH -s base -b "" -H $MYURI \
240 'objectclass=*' > /dev/null 2>&1
241 RC=$?
242 if test $RC = 0 ; then
243 break
244 fi
245 echo "Waiting 5 seconds for slapd to start..."
246 sleep 5
247 done
248
249 if test $RC != 0 ; then
250 echo "ldapsearch failed ($RC)!"
251 test $KILLSERVERS != no && kill -HUP $KILLPIDS
252 exit $RC
253 fi
254
255 if [ $n = 1 ]; then
256 echo "Using ldapadd for context on server 1..."
257 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDCP \
258 >> $TESTOUT 2>&1
259 RC=$?
260 if test $RC != 0 ; then
261 echo "ldapadd failed for server $n database ($RC)!"
262 test $KILLSERVERS != no && kill -HUP $KILLPIDS
263 exit $RC
264 fi
265 fi
266
267 n=`expr $n + 1`
268 done
269
270 echo "Using ldapadd to populate server 1..."
271 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDNOCP \
272 >> $TESTOUT 2>&1
273 RC=$?
274 if test $RC != 0 ; then
275 echo "ldapadd failed for server $n database ($RC)!"
276 test $KILLSERVERS != no && kill -HUP $KILLPIDS
277 exit $RC
278 fi
279
280 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
281 sleep $SLEEP1
282
283 n=1
284 while [ $n -le $MPR ]; do
285 PORT=`expr $BASEPORT + $n`
286 URI="ldap://${LOCALHOST}:$PORT/"
287
288 echo "Using ldapsearch to read all the entries from server $n..."
289 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
290 'objectclass=*' > $TESTDIR/server$n.out 2>&1
291 RC=$?
292
293 if test $RC != 0 ; then
294 echo "ldapsearch failed at server $n ($RC)!"
295 test $KILLSERVERS != no && kill -HUP $KILLPIDS
296 exit $RC
297 fi
298 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
299 n=`expr $n + 1`
300 done
301
302 n=2
303 while [ $n -le $MPR ]; do
304 echo "Comparing retrieved entries from server 1 and server $n..."
305 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
306
307 if test $? != 0 ; then
308 echo "test failed - server 1 and server $n databases differ"
309 test $KILLSERVERS != no && kill -HUP $KILLPIDS
310 exit 1
311 fi
312 n=`expr $n + 1`
313 done
314
315 echo "Using ldapadd to populate server 2..."
316 cp $LDIFADD1 $TESTDIR/add.ldif
317 echo "displayName: The other" >>$TESTDIR/add.ldif
318 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $TESTDIR/add.ldif \
319 >> $TESTOUT 2>&1
320 RC=$?
321 if test $RC != 0 ; then
322 echo "ldapadd failed for server 2 database ($RC)!"
323 test $KILLSERVERS != no && kill -HUP $KILLPIDS
324 exit $RC
325 fi
326
327 THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
328 sleep 1
329 for i in 1 2 3; do
330 $LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
331 -s base '(objectClass=*)' entryCSN > "${PROVIDEROUT}.$i" 2>&1
332 RC=$?
333
334 if test $RC = 0 ; then
335 break
336 fi
337
338 if test $RC != 32 ; then
339 echo "ldapsearch failed at consumer ($RC)!"
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
341 exit $RC
342 fi
343
344 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
345 sleep $SLEEP1
346 done
347
348 n=1
349 while [ $n -le $MPR ]; do
350 PORT=`expr $BASEPORT + $n`
351 URI="ldap://${LOCALHOST}:$PORT/"
352
353 echo "Using ldapsearch to read all the entries from server $n..."
354 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
355 'objectclass=*' > $TESTDIR/server$n.out 2>&1
356 RC=$?
357
358 if test $RC != 0 ; then
359 echo "ldapsearch failed at server $n ($RC)!"
360 test $KILLSERVERS != no && kill -HUP $KILLPIDS
361 exit $RC
362 fi
363 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
364 n=`expr $n + 1`
365 done
366
367 n=2
368 while [ $n -le $MPR ]; do
369 echo "Comparing retrieved entries from server 1 and server $n..."
370 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
371
372 if test $? != 0 ; then
373 echo "test failed - server 1 and server $n databases differ"
374 test $KILLSERVERS != no && kill -HUP $KILLPIDS
375 exit 1
376 fi
377 n=`expr $n + 1`
378 done
379
380 echo "Breaking replication between server 1 and 2..."
381 n=1
382 while [ $n -le 2 ]; do
383 MYURI=`eval echo '$URI'$n`
384 o=`expr $n - 1`
385 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
386 dn: olcDatabase={2}$BACKEND,cn=config
387 changetype: modify
388 delete: olcSyncRepl
389 -
390
391 EOF
392 RC=$?
393 if test $RC != 0 ; then
394 echo "ldapmodify failed for server $n config ($RC)!"
395 test $KILLSERVERS != no && kill -HUP $KILLPIDS
396 exit $RC
397 fi
398 n=`expr $n + 1`
399 done
400
401 echo "Using ldapmodify to force conflicts between server 1 and 2..."
402 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
403 >> $TESTOUT 2>&1 << EOF
404 dn: $THEDN
405 changetype: modify
406 add: description
407 description: Amazing
408 -
409 add: displayName
410 displayName: James the Second
411 -
412 delete: displayName
413 displayName: The other
414 -
415 replace: mail
416 mail: [email protected]
417
418 EOF
419 RC=$?
420 if test $RC != 0 ; then
421 echo "ldapmodify failed for server 1 database ($RC)!"
422 test $KILLSERVERS != no && kill -HUP $KILLPIDS
423 exit $RC
424 fi
425
426 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
427 >> $TESTOUT 2>&1 << EOF
428 dn: $THEDN
429 changetype: modify
430 replace: employeetype
431 -
432 add: description
433 description: Stupendous
434 -
435 add: displayName
436 displayName: James II
437 -
438 delete: displayName
439 displayName: The other
440 -
441 add: mail
442 mail: [email protected]
443
444 EOF
445 RC=$?
446 if test $RC != 0 ; then
447 echo "ldapmodify failed for server 2 database ($RC)!"
448 test $KILLSERVERS != no && kill -HUP $KILLPIDS
449 exit $RC
450 fi
451
452 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
453 >> $TESTOUT 2>&1 << EOF
454 dn: $THEDN
455 changetype: modify
456 delete: description
457 description: Outstanding
458 -
459 add: description
460 description: Mindboggling
461
462 EOF
463 RC=$?
464 if test $RC != 0 ; then
465 echo "ldapmodify failed for server 1 database ($RC)!"
466 test $KILLSERVERS != no && kill -HUP $KILLPIDS
467 exit $RC
468 fi
469
470 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
471 >> $TESTOUT 2>&1 << EOF
472 dn: $THEDN
473 changetype: modify
474 delete: description
475 description: OutStanding
476 -
477 add: description
478 description: Bizarre
479
480 EOF
481 RC=$?
482 if test $RC != 0 ; then
483 echo "ldapmodify failed for server 2 database ($RC)!"
484 test $KILLSERVERS != no && kill -HUP $KILLPIDS
485 exit $RC
486 fi
487
488 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
489 >> $TESTOUT 2>&1 << EOF
490 dn: $THEDN
491 changetype: modify
492 add: carLicense
493 carLicense: 123-XYZ
494 -
495 add: employeeNumber
496 employeeNumber: 32
497
498 EOF
499 RC=$?
500 if test $RC != 0 ; then
501 echo "ldapmodify failed for server 1 database ($RC)!"
502 test $KILLSERVERS != no && kill -HUP $KILLPIDS
503 exit $RC
504 fi
505
506 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
507 >> $TESTOUT 2>&1 << EOF
508 dn: $THEDN
509 changetype: modify
510 add: employeeType
511 employeeType: deadwood
512 -
513 add: employeeNumber
514 employeeNumber: 64
515
516 EOF
517 RC=$?
518 if test $RC != 0 ; then
519 echo "ldapmodify failed for server 2 database ($RC)!"
520 test $KILLSERVERS != no && kill -HUP $KILLPIDS
521 exit $RC
522 fi
523
524 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
525 >> $TESTOUT 2>&1 << EOF
526 dn: $THEDN
527 changetype: modify
528 replace: sn
529 sn: Replaced later
530 -
531 replace: sn
532 sn: Surname
533 EOF
534 RC=$?
535 if test $RC != 0 ; then
536 echo "ldapmodify failed for server 1 database ($RC)!"
537 test $KILLSERVERS != no && kill -HUP $KILLPIDS
538 exit $RC
539 fi
540
541 echo "Restoring replication between server 1 and 2..."
542 cat > $TMP <<EOF
543 dn: olcDatabase={2}$BACKEND,cn=config
544 changetype: modify
545 add: olcSyncRepl
546 EOF
547 n=1
548 while [ $n -le $MPR ]; do
549 MYURI=`eval echo '$URI'$n`
550 PROVIDERURI=`eval echo '$URI'$n`
551 cat >> $TMP <<EOF
552 olcSyncRepl: rid=00$n provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
553 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
554 retry="3 +" timeout=3 logbase="cn=log"
555 logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
556 syncdata=accesslog
557 EOF
558 n=`expr $n + 1`
559 done
560 cat >> $TMP <<EOF
561 -
562 replace: olcMultiProvider
563 olcMultiProvider: TRUE
564 EOF
565 n=1
566 while [ $n -le 2 ]; do
567 MYURI=`eval echo '$URI'$n`
568 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <$TMP
569 RC=$?
570 if test $RC != 0 ; then
571 echo "ldapmodify failed for server $n config ($RC)!"
572 test $KILLSERVERS != no && kill -HUP $KILLPIDS
573 exit $RC
574 fi
575 n=`expr $n + 1`
576 done
577
578 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
579 sleep $SLEEP1
580
581 n=1
582 while [ $n -le $MPR ]; do
583 PORT=`expr $BASEPORT + $n`
584 URI="ldap://${LOCALHOST}:$PORT/"
585
586 echo "Using ldapsearch to read all the entries from server $n..."
587 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
588 'objectclass=*' > $TESTDIR/server$n.out 2>&1
589 RC=$?
590
591 if test $RC != 0 ; then
592 echo "ldapsearch failed at server $n ($RC)!"
593 test $KILLSERVERS != no && kill -HUP $KILLPIDS
594 exit $RC
595 fi
596 $LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
597 n=`expr $n + 1`
598 done
599
600 n=2
601 while [ $n -le $MPR ]; do
602 echo "Comparing retrieved entries from server 1 and server $n..."
603 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
604
605 if test $? != 0 ; then
606 echo "test failed - server 1 and server $n databases differ"
607 test $KILLSERVERS != no && kill -HUP $KILLPIDS
608 exit 1
609 fi
610 n=`expr $n + 1`
611 done
612
613 test $KILLSERVERS != no && kill -HUP $KILLPIDS
614
615 echo ">>>>> Test succeeded"
616
617 test $KILLSERVERS != no && wait
618
619 exit 0