]> git.sur5r.net Git - openldap/blob - tests/scripts/test053-syncprov-glue
859132d0174a53f18a0e74757f7d536bb9117068
[openldap] / tests / scripts / test053-syncprov-glue
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2017 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 # This script tests a bug where syncprov used on a glue database
17 # with a subordinate syncrepl consumer database looses a read-lock
18 # on the glue suffix entry when a modification is received on the
19 # syncrepl consumer.  The bug is only triggered when there is an
20 # active syncrepl consumers of the glue suffix entry.
21
22 echo "running defines.sh"
23 . $SRCDIR/scripts/defines.sh
24
25 if test $SYNCPROV = syncprovno; then 
26         echo "Syncrepl provider overlay not available, test skipped"
27         exit 0
28 fi 
29
30 PRODDIR=$TESTDIR/prod
31 PRO2DIR=$TESTDIR/pro2
32 CONSDIR=$TESTDIR/cons
33 CFPROD=$PRODDIR/slapd.d
34 CFPRO2=$PRO2DIR/slapd.d
35 CFCONS=$CONSDIR/slapd.d
36
37 mkdir -p $TESTDIR
38 mkdir -p $PRODDIR $CFPROD $PRODDIR/db $PRODDIR/ou1
39 mkdir -p $PRO2DIR $CFPRO2 $PRO2DIR/db
40 mkdir -p $CONSDIR $CFCONS $CONSDIR/db 
41
42 cd $TESTDIR
43
44 KILLPIDS=
45
46 $SLAPPASSWD -g -n >$CONFIGPWF
47
48 if test x"$SYNCMODE" = x ; then
49         SYNCMODE=rp
50 fi
51 case "$SYNCMODE" in
52         ro)
53                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
54                 ;;
55         rp)
56                 SYNCTYPE="type=refreshAndPersist"
57                 ;;
58         *)
59                 echo "unknown sync mode $SYNCMODE"
60                 exit 1;
61                 ;;
62 esac
63
64 echo "Initializing provider configurations..."
65 $SLAPADD -F $CFPROD -n 0 <<EOF
66 dn: cn=config
67 objectClass: olcGlobal
68 cn: config
69 olcServerID: 1
70
71 dn: olcDatabase={0}config,cn=config
72 objectClass: olcDatabaseConfig
73 olcDatabase: {0}config
74 olcRootPW:< file://$CONFIGPWF
75
76 EOF
77
78 echo "Initializing provider2 configurations..."
79 $SLAPADD -F $CFPRO2 -n 0 <<EOF
80 dn: cn=config
81 objectClass: olcGlobal
82 cn: config
83
84 dn: olcDatabase={0}config,cn=config
85 objectClass: olcDatabaseConfig
86 olcDatabase: {0}config
87 olcRootPW:< file://$CONFIGPWF
88
89 EOF
90
91 $SLAPADD -F $CFCONS -n 0 <<EOF
92 dn: cn=config
93 objectClass: olcGlobal
94 cn: config
95
96 dn: olcDatabase={0}config,cn=config
97 objectClass: olcDatabaseConfig
98 olcDatabase: {0}config
99 olcRootPW:< file://$CONFIGPWF
100 EOF
101
102 echo "Starting provider slapd on TCP/IP port $PORT1..."
103 cd $PRODDIR
104 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
105 PID=$!
106 if test $WAIT != 0 ; then
107     echo PID $PID
108     read foo
109 fi
110 KILLPIDS="$KILLPIDS $PID"
111 cd $TESTWD
112 sleep 1
113 echo "Using ldapsearch to check that provider slapd is running..."
114 for i in 0 1 2 3 4 5; do
115         $LDAPSEARCH -s base -b "" -H $URI1 \
116                 'objectclass=*' > /dev/null 2>&1
117         RC=$?
118         if test $RC = 0 ; then
119                 break
120         fi
121         echo "Waiting 5 seconds for slapd to start..."
122         sleep 5
123 done
124 if test $RC != 0 ; then
125         echo "ldapsearch failed ($RC)!"
126         test $KILLSERVERS != no && kill -HUP $KILLPIDS
127         exit $RC
128 fi
129
130 echo "Starting provider2 slapd on TCP/IP port $PORT2..."
131 cd $PRO2DIR
132 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
133 PID=$!
134 if test $WAIT != 0 ; then
135     echo PID $PID
136     read foo
137 fi
138 KILLPIDS="$KILLPIDS $PID"
139 cd $TESTWD
140 sleep 1
141 echo "Using ldapsearch to check that provider slapd is running..."
142 for i in 0 1 2 3 4 5; do
143         $LDAPSEARCH -s base -b "" -H $URI2 \
144                 'objectclass=*' > /dev/null 2>&1
145         RC=$?
146         if test $RC = 0 ; then
147                 break
148         fi
149         echo "Waiting 5 seconds for slapd to start..."
150         sleep 5
151 done
152 if test $RC != 0 ; then
153         echo "ldapsearch failed ($RC)!"
154         test $KILLSERVERS != no && kill -HUP $KILLPIDS
155         exit $RC
156 fi
157
158 echo "Starting consumer slapd on TCP/IP port $PORT3..."
159 cd $CONSDIR
160 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
161 PID=$!
162 if test $WAIT != 0 ; then
163     echo PID $PID
164     read foo
165 fi
166 KILLPIDS="$KILLPIDS $PID"
167 cd $TESTWD
168 sleep 1
169 echo "Using ldapsearch to check that consumer slapd is running..."
170 for i in 0 1 2 3 4 5; do
171         $LDAPSEARCH -s base -b "" -H $URI3 \
172                 'objectclass=*' > /dev/null 2>&1
173         RC=$?
174         if test $RC = 0 ; then
175                 break
176         fi
177         echo "Waiting 5 seconds for slapd to start..."
178         sleep 5
179 done
180 if test $RC != 0 ; then
181         echo "ldapsearch failed ($RC)!"
182         test $KILLSERVERS != no && kill -HUP $KILLPIDS
183         exit $RC
184 fi
185
186 for uri in $URI1 $URI2 $URI3; do
187         echo "Adding schema on $uri..."
188         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
189 include: file://$ABS_SCHEMADIR/core.ldif
190
191 include: file://$ABS_SCHEMADIR/cosine.ldif
192
193 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
194
195 include: file://$ABS_SCHEMADIR/openldap.ldif
196
197 include: file://$ABS_SCHEMADIR/nis.ldif
198 EOF
199         RC=$?
200         if test $RC != 0 ; then
201                 echo "ldapadd failed for schema config ($RC)!"
202                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
203                 exit $RC
204         fi
205
206         [ "$BACKENDTYPE" = mod ] || continue
207
208         echo "Adding backend module on $uri..."
209         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
210 dn: cn=module,cn=config
211 objectClass: olcModuleList
212 cn: module
213 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
214 olcModuleLoad: back_$BACKEND.la
215 EOF
216         RC=$?
217         if test $RC != 0 ; then
218                 echo "ldapadd failed for backend module ($RC)!"
219                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
220                 exit $RC
221         fi
222 done
223
224 echo "Adding databases on provider..."
225 if [ "$SYNCPROV" = syncprovmod ]; then
226         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
227 dn: cn=module,cn=config
228 objectClass: olcModuleList
229 cn: module
230 olcModulePath: $TESTWD/../servers/slapd/overlays
231 olcModuleLoad: syncprov.la
232
233 EOF
234         RC=$?
235         if test $RC != 0 ; then
236                 echo "ldapadd failed for moduleLoad ($RC)!"
237                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
238                 exit $RC
239         fi
240 fi
241
242 nullExclude="" nullOK=""
243 test $BACKEND = null && nullExclude="# " nullOK="OK"
244
245 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
246 dn: olcDatabase={1}$BACKEND,cn=config
247 objectClass: olcDatabaseConfig
248 ${nullExclude}objectClass: olc${BACKEND}Config
249 olcDatabase: {1}$BACKEND
250 ${nullExclude}olcDbDirectory: $PRODDIR/db
251 olcSuffix: $BASEDN
252 olcRootDN: $MANAGERDN
253 olcRootPW: $PASSWD
254
255 EOF
256 RC=$?
257 if test $RC != 0 ; then
258         echo "ldapadd failed for provider database config1 ($RC)!"
259         test $KILLSERVERS != no && kill -HUP $KILLPIDS
260         exit $RC
261 fi
262
263 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
264 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
265 objectClass: olcOverlayConfig
266 olcOverlay: {0}glue
267
268 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
269 objectClass: olcOverlayConfig
270 objectClass: olcSyncProvConfig
271 olcOverlay: {1}syncprov
272
273 dn: olcDatabase={1}$BACKEND,cn=config
274 objectClass: olcDatabaseConfig
275 ${nullExclude}objectClass: olc${BACKEND}Config
276 olcDatabase: {1}$BACKEND
277 ${nullExclude}olcDbDirectory: $PRODDIR/ou1
278 olcSubordinate: TRUE
279 olcSuffix: ou=ou1,$BASEDN
280 olcRootDN: $MANAGERDN
281
282 EOF
283 RC=$?
284 if test $RC != 0 ; then
285         echo "ldapadd failed for provider database config ($RC)!"
286         test $KILLSERVERS != no && kill -HUP $KILLPIDS
287         exit $RC
288 fi
289
290 echo "Adding databases on provider2..."
291 if [ "$SYNCPROV" = syncprovmod ]; then
292         $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
293 dn: cn=module,cn=config
294 objectClass: olcModuleList
295 cn: module
296 olcModulePath: $TESTWD/../servers/slapd/overlays
297 olcModuleLoad: syncprov.la
298
299 EOF
300         RC=$?
301         if test $RC != 0 ; then
302                 echo "ldapadd failed for moduleLoad ($RC)!"
303                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
304                 exit $RC
305         fi
306 fi
307
308 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
309 dn: olcDatabase={1}$BACKEND,cn=config
310 objectClass: olcDatabaseConfig
311 ${nullExclude}objectClass: olc${BACKEND}Config
312 olcDatabase: {1}$BACKEND
313 ${nullExclude}olcDbDirectory: $PRO2DIR/db
314 olcSuffix: $BASEDN
315 olcRootDN: $MANAGERDN
316 olcRootPW: $PASSWD
317
318 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
319 objectClass: olcOverlayConfig
320 objectClass: olcSyncProvConfig
321 olcOverlay: {0}syncprov
322
323 EOF
324 RC=$?
325 if test $RC != 0 ; then
326         echo "ldapadd failed for provider database config ($RC)!"
327         test $KILLSERVERS != no && kill -HUP $KILLPIDS
328         exit $RC
329 fi
330
331 echo "Adding databases on consumer..."
332 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
333 dn: olcDatabase={1}$BACKEND,cn=config
334 objectClass: olcDatabaseConfig
335 ${nullExclude}objectClass: olc${BACKEND}Config
336 olcDatabase: {1}$BACKEND
337 ${nullExclude}olcDbDirectory: $CONSDIR/db
338 olcSuffix: $BASEDN
339 olcRootDN: $MANAGERDN
340
341 EOF
342 RC=$?
343 if test $RC != 0 ; then
344         echo "ldapadd failed for consumer database config ($RC)!"
345         test $KILLSERVERS != no && kill -HUP $KILLPIDS
346         exit $RC
347 fi
348
349 echo "Populating provider..."
350 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
351 dn: dc=example,dc=com
352 objectClass: top
353 objectClass: organization
354 objectClass: dcObject
355 dc: example
356 o: Example, Inc
357
358 dn: ou=ou1,dc=example,dc=com
359 objectClass: top
360 objectClass: organizationalUnit
361 ou: ou1
362
363 EOF
364 RC=$?
365 if test $RC != 0 ; then
366         echo "ldapadd failed to populate provider entry ($RC)!"
367         test $KILLSERVERS != no && kill -HUP $KILLPIDS
368         exit $RC
369 fi
370
371 echo "Populating provider2..."
372 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
373 dn: dc=example,dc=com
374 objectClass: top
375 objectClass: organization
376 objectClass: dcObject
377 dc: example
378 o: Example, Inc
379
380 dn: ou=ou1,dc=example,dc=com
381 objectClass: top
382 objectClass: organizationalUnit
383 ou: ou1
384
385 EOF
386 RC=$?
387 if test $RC != 0 ; then
388         echo "ldapadd failed to populate provider entry ($RC)!"
389         test $KILLSERVERS != no && kill -HUP $KILLPIDS
390         exit $RC
391 fi
392
393 echo "Adding syncrepl on provider..."
394 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
395 dn: olcDatabase={1}$BACKEND,cn=config
396 changetype: modify
397 add: olcSyncRepl
398 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
399   binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
400   $SYNCTYPE retry="3 5 300 5" timeout=1
401
402 EOF
403 RC=$?
404 if test $RC != 0 ; then
405         echo "ldapmodify failed to add syncrepl consumer ($RC)!"
406         test $KILLSERVERS != no && kill -HUP $KILLPIDS
407         exit $RC
408 fi
409
410 echo "Adding syncrepl consumer on consumer..."
411 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
412 dn: olcDatabase={1}$BACKEND,cn=config
413 changetype: modify
414 add: olcSyncRepl
415 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
416   binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
417   $SYNCTYPE retry="3 5 300 5" timeout=1
418
419 EOF
420 RC=$?
421 if test $RC != 0 ; then
422         echo "ldapmodify failed to add syncrepl consumer ($RC)!"
423         test $KILLSERVERS != no && kill -HUP $KILLPIDS
424         exit $RC
425 fi
426
427 echo "Using ldapsearch to check that consumer received changes..."
428 RC=32
429 for i in 0 1 2 3 4 5; do
430         RESULT=`$LDAPSEARCH -H $URI3 \
431                 -s base -b "ou=ou1,$BASEDN" \
432                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
433         if test "x$RESULT$nullOK" = "xOK" ; then
434                 RC=0
435                 break
436         fi
437         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
438         sleep $SLEEP1
439 done
440 if test $RC != 0 ; then
441         echo "ldapsearch failed ($RC)!"
442         test $KILLSERVERS != no && kill -HUP $KILLPIDS
443         exit $RC
444 fi
445
446 echo "Using ldapmodify to modify provider2..."
447 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
448 dn: ou=ou1,dc=example,dc=com
449 changetype: modify
450 add: description
451 description: Modify1
452
453 EOF
454 RC=$?
455 if test $RC != 0 ; then
456         echo "ldapmodify failed ($RC)!"
457         test $KILLSERVERS != no && kill -HUP $KILLPIDS
458         exit $RC
459 fi
460
461 sleep 1
462
463 echo "Using ldapsearch to check that consumer received changes..."
464 RC=32
465 for i in 0 1 2 3 4 5; do
466         RESULT=`$LDAPSEARCH -H $URI3 \
467                 -s base -b "ou=ou1,$BASEDN" \
468                 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
469         if test "x$RESULT$nullOK" = "xOK" ; then
470                 RC=0
471                 break
472         fi
473         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
474         sleep $SLEEP1
475 done
476 if test $RC != 0 ; then
477         echo "ldapsearch failed ($RC)!"
478         test $KILLSERVERS != no && kill -HUP $KILLPIDS
479         exit $RC
480 fi
481
482 case $BACKEND in bdb | hdb)
483 db_stat=
484 for path in `echo "$PATH" | sed -e 's/:/ /g'`; do
485         if test -f "$path/db_stat" && \
486                 "$path/db_stat" -E -h $PRODDIR/db > /dev/null 2>&1
487         then
488                 db_stat="$path/db_stat"
489                 break
490         fi
491 done
492
493 if test -z "$db_stat" ; then
494         echo "Could not find a working db_stat in PATH!"
495         lock_bug=1
496 elif "$db_stat" -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
497         echo "WARNING: Glue lock bug hit, next modify could deadlock"
498         lock_bug=2
499 else
500         echo "Glue lock bug not found :-)"
501         lock_bug=0
502 fi
503 esac
504
505 echo "Using ldapmodify to modify glue suffix on provider..."
506 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
507 dn: dc=example,dc=com
508 changetype: modify
509 add: description
510 description: Test1
511
512 EOF
513 RC=$?
514 if test $RC != 0 ; then
515         echo "ldapadd failed to modify suffix ($RC)!"
516         test $KILLSERVERS != no && kill -HUP $KILLPIDS
517         exit $RC
518 fi
519
520 test $KILLSERVERS != no && kill -HUP $KILLPIDS
521 test "$lock_bug" = 2    && exit 2
522
523 echo ">>>>> Test succeeded"
524
525 exit 0