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