test078-persistent-sessionlog revision 1.1 1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2021 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 retry="3 +" timeout=3
169 olcMirrorMode: TRUE
170 $INDEX2
171
172 dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
173 objectClass: olcOverlayConfig
174 objectClass: olcSyncProvConfig
175 olcOverlay: syncprov
176 olcSpSessionlogSource: cn=log
177
178 dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
179 objectClass: olcOverlayConfig
180 objectClass: olcAccessLogConfig
181 olcOverlay: accesslog
182 olcAccessLogDB: cn=log
183 olcAccessLogOps: writes
184 olcAccessLogSuccess: TRUE
185
186 EOF
187 $SLAPADD -F $CFDIR -n 0 -d-1< $TMP > $TESTOUT 2>&1
188 PORT=`eval echo '$PORT'$n`
189 echo "Starting server $n on TCP/IP port $PORT..."
190 cd ${XDIR}${n}
191 LOG=`eval echo '$LOG'$n`
192 $SLAPD -F slapd.d -h $MYURI -d $LVL > $LOG 2>&1 &
193 PID=$!
194 if test $WAIT != 0 ; then
195 echo PID $PID
196 read foo
197 fi
198 KILLPIDS="$PID $KILLPIDS"
199 cd $TESTWD
200
201 echo "Using ldapsearch to check that server $n is running..."
202 for i in 0 1 2 3 4 5; do
203 $LDAPSEARCH -s base -b "" -H $MYURI \
204 'objectclass=*' > /dev/null 2>&1
205 RC=$?
206 if test $RC = 0 ; then
207 break
208 fi
209 echo "Waiting 5 seconds for slapd to start..."
210 sleep 5
211 done
212
213 if test $RC != 0 ; then
214 echo "ldapsearch failed ($RC)!"
215 test $KILLSERVERS != no && kill -HUP $KILLPIDS
216 exit $RC
217 fi
218
219 if [ $n = 1 ]; then
220 echo "Using ldapadd for context on server 1..."
221 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDCP \
222 >> $TESTOUT 2>&1
223 RC=$?
224 if test $RC != 0 ; then
225 echo "ldapadd failed for server $n database ($RC)!"
226 test $KILLSERVERS != no && kill -HUP $KILLPIDS
227 exit $RC
228 fi
229 fi
230
231 n=`expr $n + 1`
232 done
233
234 echo "Using ldapadd to populate server 1..."
235 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDNOCP \
236 >> $TESTOUT 2>&1
237 RC=$?
238 if test $RC != 0 ; then
239 echo "ldapadd failed for server 1 database ($RC)!"
240 test $KILLSERVERS != no && kill -HUP $KILLPIDS
241 exit $RC
242 fi
243
244 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
245 sleep $SLEEP1
246
247 n=1
248 while [ $n -le $MMR ]; do
249 URI=`eval echo '$URI'$n`
250
251 echo "Using ldapsearch to read all the entries from server $n..."
252 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
253 'objectclass=*' > $TESTDIR/server$n.out 2>&1
254 RC=$?
255
256 if test $RC != 0 ; then
257 echo "ldapsearch failed at server $n ($RC)!"
258 test $KILLSERVERS != no && kill -HUP $KILLPIDS
259 exit $RC
260 fi
261 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
262 n=`expr $n + 1`
263 done
264
265 n=2
266 while [ $n -le $MMR ]; do
267 echo "Comparing retrieved entries from server 1 and server $n..."
268 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
269
270 if test $? != 0 ; then
271 echo "test failed - server 1 and server $n databases differ"
272 test $KILLSERVERS != no && kill -HUP $KILLPIDS
273 exit 1
274 fi
275 n=`expr $n + 1`
276 done
277
278 echo "Using ldapadd to populate server 2..."
279 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
280 >> $TESTOUT 2>&1
281 RC=$?
282 if test $RC != 0 ; then
283 echo "ldapadd failed for server 2 database ($RC)!"
284 test $KILLSERVERS != no && kill -HUP $KILLPIDS
285 exit $RC
286 fi
287
288 THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
289 sleep 1
290 for i in 1 2 3; do
291 $LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
292 -s base '(objectClass=*)' entryCSN > "${PROVIDEROUT}.$i" 2>&1
293 RC=$?
294
295 if test $RC = 0 ; then
296 break
297 fi
298
299 if test $RC != 32 ; then
300 echo "ldapsearch failed at slave ($RC)!"
301 test $KILLSERVERS != no && kill -HUP $KILLPIDS
302 exit $RC
303 fi
304
305 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
306 sleep $SLEEP1
307 done
308
309 n=1
310 while [ $n -le $MMR ]; do
311 URI=`eval echo '$URI'$n`
312
313 echo "Using ldapsearch to read all the entries from server $n..."
314 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
315 'objectclass=*' > $TESTDIR/server$n.out 2>&1
316 RC=$?
317
318 if test $RC != 0 ; then
319 echo "ldapsearch failed at server $n ($RC)!"
320 test $KILLSERVERS != no && kill -HUP $KILLPIDS
321 exit $RC
322 fi
323 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
324 n=`expr $n + 1`
325 done
326
327 n=2
328 while [ $n -le $MMR ]; do
329 echo "Comparing retrieved entries from server 1 and server $n..."
330 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
331
332 if test $? != 0 ; then
333 echo "test failed - server 1 and server $n databases differ"
334 test $KILLSERVERS != no && kill -HUP $KILLPIDS
335 exit 1
336 fi
337 n=`expr $n + 1`
338 done
339
340 echo "Retrieving syncrepl cookie..."
341 cookie=`$LDAPRSEARCH -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
342 -E "sync=ro" 'objectclass=*' 1.1 | grep cookie | sed "s/.*cookie: //"`
343
344 if test -z "$cookie"; then
345 echo "Failed to retrieve cookie from server!"
346 test $KILLSERVERS != no && kill -HUP $KILLPIDS
347 exit 1
348 fi
349
350 echo "Deleting an entry from server 1..."
351 $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD \
352 "cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN" \
353 >> $TESTOUT 2>&1
354 RC=$?
355 if test $RC != 0 ; then
356 echo "ldapdelete failed for server 1 database ($RC)!"
357 test $KILLSERVERS != no && kill -HUP $KILLPIDS
358 exit $RC
359 fi
360
361
362 echo "Restarting servers..."
363 kill -HUP $KILLPIDS
364 wait
365 KILLPIDS=""
366 n=1
367 while [ $n -le $MMR ]; do
368 o=`expr 3 - $n`
369 MYURI=`eval echo '$URI'$n`
370 PROVIDERURI=`eval echo '$URI'$o`
371
372 echo "Starting server $n again..."
373 cd ${XDIR}${n}
374 LOG=`eval echo '$LOG'$n`
375 echo "RESTART" >> $LOG
376 #if test $n = 2; then
377 #echo $SLAPD -F slapd.d -h $MYURI -d $LVL
378 #else
379 $SLAPD -F slapd.d -h $MYURI -d $LVL > $LOG 2>&1 &
380 #fi
381 PID=$!
382 if test $WAIT != 0 ; then
383 echo PID $PID
384 read foo
385 fi
386 KILLPIDS="$PID $KILLPIDS"
387 cd $TESTWD
388
389 echo "Using ldapsearch to check that server $n is running..."
390 for i in 0 1 2 3 4 5; do
391 $LDAPSEARCH -s base -b "" -H $MYURI \
392 'objectclass=*' > /dev/null 2>&1
393 RC=$?
394 if test $RC = 0 ; then
395 break
396 fi
397 echo "Waiting 5 seconds for slapd to start..."
398 sleep 5
399 done
400
401 echo "Breaking replication between server $n and $o..."
402 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
403 dn: olcDatabase={2}$BACKEND,cn=config
404 changetype: modify
405 replace: olcSyncRepl
406 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
407 credentials=InvalidPw searchbase="$BASEDN" $SYNCTYPE retry="3 +" timeout=3
408 -
409 replace: olcMirrorMode
410 olcMirrorMode: TRUE
411
412 EOF
413 RC=$?
414 if test $RC != 0 ; then
415 echo "ldapmodify failed for server $n config ($RC)!"
416 test $KILLSERVERS != no && kill -HUP $KILLPIDS
417 exit $RC
418 fi
419 n=`expr $n + 1`
420 done
421
422 echo "Using ldapmodify to force conflicts between server 1 and 2..."
423 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
424 >> $TESTOUT 2>&1 << EOF
425 dn: $THEDN
426 changetype: modify
427 add: description
428 description: Amazing
429
430 EOF
431 RC=$?
432 if test $RC != 0 ; then
433 echo "ldapmodify failed for server 1 database ($RC)!"
434 test $KILLSERVERS != no && kill -HUP $KILLPIDS
435 exit $RC
436 fi
437
438 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
439 >> $TESTOUT 2>&1 << EOF
440 dn: $THEDN
441 changetype: modify
442 add: description
443 description: Stupendous
444
445 EOF
446 RC=$?
447 if test $RC != 0 ; then
448 echo "ldapmodify failed for server 2 database ($RC)!"
449 test $KILLSERVERS != no && kill -HUP $KILLPIDS
450 exit $RC
451 fi
452
453 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
454 >> $TESTOUT 2>&1 << EOF
455 dn: $THEDN
456 changetype: modify
457 delete: description
458 description: Outstanding
459 -
460 add: description
461 description: Mindboggling
462
463 EOF
464 RC=$?
465 if test $RC != 0 ; then
466 echo "ldapmodify failed for server 1 database ($RC)!"
467 test $KILLSERVERS != no && kill -HUP $KILLPIDS
468 exit $RC
469 fi
470
471 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
472 >> $TESTOUT 2>&1 << EOF
473 dn: $THEDN
474 changetype: modify
475 delete: description
476 description: OutStanding
477 -
478 add: description
479 description: Bizarre
480
481 EOF
482 RC=$?
483 if test $RC != 0 ; then
484 echo "ldapmodify failed for server 2 database ($RC)!"
485 test $KILLSERVERS != no && kill -HUP $KILLPIDS
486 exit $RC
487 fi
488
489 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
490 >> $TESTOUT 2>&1 << EOF
491 dn: $THEDN
492 changetype: modify
493 add: carLicense
494 carLicense: 123-XYZ
495 -
496 add: employeeNumber
497 employeeNumber: 32
498
499 EOF
500 RC=$?
501 if test $RC != 0 ; then
502 echo "ldapmodify failed for server 1 database ($RC)!"
503 test $KILLSERVERS != no && kill -HUP $KILLPIDS
504 exit $RC
505 fi
506
507 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
508 >> $TESTOUT 2>&1 << EOF
509 dn: $THEDN
510 changetype: modify
511 add: employeeType
512 employeeType: deadwood
513 -
514 add: employeeNumber
515 employeeNumber: 64
516
517 EOF
518 RC=$?
519 if test $RC != 0 ; then
520 echo "ldapmodify failed for server 2 database ($RC)!"
521 test $KILLSERVERS != no && kill -HUP $KILLPIDS
522 exit $RC
523 fi
524
525 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
526 >> $TESTOUT 2>&1 << EOF
527 dn: $THEDN
528 changetype: modify
529 replace: sn
530 sn: Replaced later
531 -
532 replace: sn
533 sn: Surname
534 EOF
535 RC=$?
536 if test $RC != 0 ; then
537 echo "ldapmodify failed for server 1 database ($RC)!"
538 test $KILLSERVERS != no && kill -HUP $KILLPIDS
539 exit $RC
540 fi
541
542 echo "Deleting an entry from both servers..."
543 $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD \
544 "cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN" \
545 >> $TESTOUT 2>&1
546 RC=$?
547 if test $RC != 0 ; then
548 echo "ldapdelete failed for server 1 database ($RC)!"
549 test $KILLSERVERS != no && kill -HUP $KILLPIDS
550 exit $RC
551 fi
552
553 $LDAPDELETE -D "$MANAGERDN" -H $URI2 -w $PASSWD \
554 "cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN" \
555 >> $TESTOUT 2>&1
556 RC=$?
557 if test $RC != 0 ; then
558 echo "ldapdelete failed for server 2 database ($RC)!"
559 test $KILLSERVERS != no && kill -HUP $KILLPIDS
560 exit $RC
561 fi
562
563 echo "Restoring replication between server 1 and 2..."
564 n=1
565 while [ $n -le $MMR ]; do
566 o=`expr 3 - $n`
567 MYURI=`eval echo '$URI'$n`
568 PROVIDERURI=`eval echo '$URI'$o`
569 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
570 dn: olcDatabase={2}$BACKEND,cn=config
571 changetype: modify
572 replace: olcSyncRepl
573 olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
574 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE retry="3 +" timeout=3
575 -
576 replace: olcMirrorMode
577 olcMirrorMode: TRUE
578
579 EOF
580 RC=$?
581 if test $RC != 0 ; then
582 echo "ldapmodify failed for server $n config ($RC)!"
583 test $KILLSERVERS != no && kill -HUP $KILLPIDS
584 exit $RC
585 fi
586 n=`expr $n + 1`
587 done
588
589 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
590 sleep $SLEEP1
591
592 echo 2 >$TESTDIR/repl.test
593 echo 1 >>$TESTDIR/repl.test
594
595 n=1
596 while [ $n -le $MMR ]; do
597 URI=`eval echo '$URI'$n`
598
599 echo "Using ldapsearch to read all the entries from server $n..."
600 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
601 'objectclass=*' > $TESTDIR/server$n.out 2>&1
602 RC=$?
603
604 if test $RC != 0 ; then
605 echo "ldapsearch failed at server $n ($RC)!"
606 test $KILLSERVERS != no && kill -HUP $KILLPIDS
607 exit $RC
608 fi
609 $LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
610
611 echo "Checking server $n can remember which entries have been deleted even after it's been restarted..."
612 $LDAPRSEARCH -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
613 -E "sync=ro/$cookie" 'objectclass=*' 1.1 | awk '/syncUUIDs/ {count++} END {print count}' >$TESTDIR/repl.out
614 $LDAPRSEARCH -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
615 -E "sync=ro/$cookie" 'objectclass=*' 1.1 | grep SyncDone | awk '/refreshDeletes=1/ {count++} END {print count}' >>$TESTDIR/repl.out
616
617 $CMP $TESTDIR/repl.out $TESTDIR/repl.test > $CMPOUT
618
619 if test $? != 0 ; then
620 echo "test failed - server did not respond with delete phase"
621 test $KILLSERVERS != no && kill -HUP $KILLPIDS
622 exit 1
623 fi
624 n=`expr $n + 1`
625 done
626
627 n=2
628 while [ $n -le $MMR ]; do
629 echo "Comparing retrieved entries from server 1 and server $n..."
630 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
631
632 if test $? != 0 ; then
633 echo "test failed - server 1 and server $n databases differ"
634 test $KILLSERVERS != no && kill -HUP $KILLPIDS
635 exit 1
636 fi
637 n=`expr $n + 1`
638 done
639
640 test $KILLSERVERS != no && kill -HUP $KILLPIDS
641
642 echo ">>>>> Test succeeded"
643
644 test $KILLSERVERS != no && wait
645
646 exit 0
647