]> git.sur5r.net Git - openldap/blob - tests/scripts/test059-slave-config
Happy New Year
[openldap] / tests / scripts / test059-slave-config
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
24 CFPRO=$TESTDIR/cfpro.d
25 CFCON=$TESTDIR/cfcon.d
26
27 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2A $CFPRO $CFCON
28
29 $SLAPPASSWD -g -n >$CONFIGPWF
30
31 if test x"$SYNCMODE" = x ; then
32         SYNCMODE=rp
33 fi
34 case "$SYNCMODE" in
35         ro)
36                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
37                 ;;
38         rp)
39                 SYNCTYPE="type=refreshAndPersist"
40                 ;;
41         *)
42                 echo "unknown sync mode $SYNCMODE"
43                 exit 1;
44                 ;;
45 esac
46
47 #
48 # Test replication of dynamic config with alternate slave config:
49 # - start provider
50 # - start consumer
51 # - configure over ldap
52 # - populate over ldap
53 # - configure syncrepl over ldap
54 # - retrieve database over ldap and compare against expected results
55 #
56
57 echo "Starting provider slapd on TCP/IP port $PORT1..."
58 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
59 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
60 $SLAPD -F $CFPRO -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
61 PID=$!
62 if test $WAIT != 0 ; then
63     echo PID $PID
64     read foo
65 fi
66 KILLPIDS="$PID"
67
68 sleep 1
69
70 echo "Using ldapsearch to check that provider slapd is running..."
71 for i in 0 1 2 3 4 5; do
72         $LDAPSEARCH -s base -b "" -H $URI1 \
73                 'objectclass=*' > /dev/null 2>&1
74         RC=$?
75         if test $RC = 0 ; then
76                 break
77         fi
78         echo "Waiting 5 seconds for slapd to start..."
79         sleep 5
80 done
81
82 if test $RC != 0 ; then
83         echo "ldapsearch failed ($RC)!"
84         test $KILLSERVERS != no && kill -HUP $KILLPIDS
85         exit $RC
86 fi
87
88 echo "Inserting syncprov overlay on provider..."
89 if [ "$SYNCPROV" = syncprovmod ]; then
90         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
91 dn: cn=module,cn=config
92 objectClass: olcModuleList
93 cn: module
94 olcModulePath: ../servers/slapd/overlays
95 olcModuleLoad: syncprov.la
96 EOF
97         RC=$?
98         if test $RC != 0 ; then
99                 echo "ldapadd failed for moduleLoad ($RC)!"
100                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
101                 exit $RC
102         fi
103 fi
104 read CONFIGPW < $CONFIGPWF
105 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
106 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
107 changetype: add
108 objectClass: olcOverlayConfig
109 objectClass: olcSyncProvConfig
110 olcOverlay: syncprov
111 EOF
112 RC=$?
113 if test $RC != 0 ; then
114         echo "ldapmodify failed for syncprov config ($RC)!"
115         test $KILLSERVERS != no && kill -HUP $KILLPIDS
116         exit $RC
117 fi
118
119 # Slaves will not replicate the master's actual cn=config.
120 # Instead, they will use an alternate DB so that they may be
121 # configured differently from the master. This alternate DB
122 # will also be a consumer for the real cn=schema,cn=config tree.
123 # It has MirrorMode enabled so that it can be written directly
124 # while being a slave of the main schema.
125 echo "Configuring slave config DB on provider..."
126 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
127 dn: cn=config
128 changetype: modify
129 add: olcServerID
130 olcServerID: 1
131
132 dn: olcDatabase={1}ldif,cn=config
133 changetype: add
134 objectClass: olcDatabaseConfig
135 objectClass: olcLdifConfig
136 olcDatabase: {1}ldif
137 olcDbDirectory: $DBDIR1A
138 olcSuffix: cn=config,cn=slave
139 olcRootDN: cn=config,cn=slave
140 olcRootPW: repsecret
141 olcAccess: to * by dn.base="cn=config" write
142
143 dn: olcOverlay=syncprov,olcDatabase={1}ldif,cn=config
144 changetype: add
145 objectClass: olcOverlayConfig
146 objectClass: olcSyncProvConfig
147 olcOverlay: syncprov
148
149 dn: cn=config,cn=slave
150 changetype: add
151 objectClass: olcGlobal
152 cn: slaveconfig
153
154 dn: cn=schema,cn=config,cn=slave
155 changetype: add
156 objectClass: olcSchemaConfig
157 cn: schema
158
159 dn: olcDatabase={0}config,cn=config,cn=slave
160 changetype: add
161 objectClass: olcDatabaseConfig
162 olcDatabase: {0}config
163 olcRootPW: topsecret
164 olcSyncrepl: {0}rid=001 provider=$URI1 binddn="cn=config,cn=slave"
165   bindmethod=simple credentials=repsecret searchbase="cn=config,cn=slave"
166   $SYNCTYPE retry="3 5 300 5" timeout=3 suffixmassage="cn=config"
167 olcUpdateRef: $URI1
168
169 dn: olcDatabase={1}ldif,cn=config
170 changetype: modify
171 add: olcSyncrepl
172 olcSyncrepl: {0}rid=001 provider=$URI1 binddn="cn=config"
173   bindmethod=simple credentials=$CONFIGPW searchbase="cn=schema,cn=config"
174   $SYNCTYPE retry="3 5 300 5" timeout=3
175   suffixmassage="cn=schema,cn=config,cn=slave"
176 -
177 add: olcMirrorMode
178 olcMirrorMode: TRUE
179
180 EOF
181 RC=$?
182 if test $RC != 0 ; then
183         echo "ldapmodify failed for slave DB config ($RC)!"
184         test $KILLSERVERS != no && kill -HUP $KILLPIDS
185         exit $RC
186 fi
187
188 echo "Starting consumer slapd on TCP/IP port $PORT2..."
189 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
190 $SLAPD -F $CFCON -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
191 SLAVEPID=$!
192 if test $WAIT != 0 ; then
193     echo SLAVEPID $SLAVEPID
194     read foo
195 fi
196 KILLPIDS="$KILLPIDS $SLAVEPID"
197
198 sleep 1
199
200 echo "Using ldapsearch to check that consumer slapd is running..."
201 for i in 0 1 2 3 4 5; do
202         $LDAPSEARCH -s base -b "" -H $URI2 \
203                 'objectclass=*' > /dev/null 2>&1
204         RC=$?
205         if test $RC = 0 ; then
206                 break
207         fi
208         echo "Waiting 5 seconds for slapd to start..."
209         sleep 5
210 done
211
212 if test $RC != 0 ; then
213         echo "ldapsearch failed ($RC)!"
214         test $KILLSERVERS != no && kill -HUP $KILLPIDS
215         exit $RC
216 fi
217
218 echo "Configuring syncrepl on consumer..."
219 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
220 dn: olcDatabase={0}config,cn=config
221 changetype: modify
222 add: olcSyncRepl
223 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config,cn=slave"
224   bindmethod=simple credentials=repsecret searchbase="cn=config,cn=slave"
225   $SYNCTYPE retry="3 5 300 5" timeout=3
226   suffixmassage="cn=config"
227 -
228 add: olcUpdateRef
229 olcUpdateRef: $URI1
230 EOF
231
232 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
233 sleep $SLEEP1
234
235 echo "Using ldapsearch to check that syncrepl received config changes..."
236 RC=32
237 for i in 0 1 2 3 4 5; do
238         RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
239                 -s base -b "olcDatabase={0}config,cn=config" \
240                 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
241         if test "x$RESULT" = "xOK" ; then
242                 RC=0
243                 break
244         fi
245         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
246         sleep $SLEEP1
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 echo "Adding schema and databases on provider..."
256 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
257 include: file://$ABS_SCHEMADIR/core.ldif
258
259 include: file://$ABS_SCHEMADIR/cosine.ldif
260
261 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
262
263 include: file://$ABS_SCHEMADIR/openldap.ldif
264
265 include: file://$ABS_SCHEMADIR/nis.ldif
266 EOF
267 RC=$?
268 if test $RC != 0 ; then
269         echo "ldapadd failed for schema config ($RC)!"
270         test $KILLSERVERS != no && kill -HUP $KILLPIDS
271         exit $RC
272 fi
273
274 echo "Using ldapsearch to check that syncrepl received the schema changes..."
275 RC=32
276 for i in 0 1 2 3 4 5; do
277         RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
278                 -s base -b "cn=schema,cn=config" \
279                 '(cn=openldap)' 2>&1 | awk '/^dn:/ {print "OK"}'`
280         if test "x$RESULT" = "xOK" ; then
281                 RC=0
282                 break
283         fi
284         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
285         sleep $SLEEP1
286 done
287
288 nullExclude="" nullOK=""
289 test $BACKEND = null && nullExclude="# " nullOK="OK"
290
291 if [ "$BACKENDTYPE" = mod ]; then
292         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
293 dn: cn=module,cn=config
294 objectClass: olcModuleList
295 cn: module
296 olcModulePath: ../servers/slapd/back-$BACKEND
297 olcModuleLoad: back_$BACKEND.la
298
299 dn: cn=module,cn=config,cn=slave
300 objectClass: olcModuleList
301 cn: module
302 olcModulePath: ../servers/slapd/back-$BACKEND
303 olcModuleLoad: back_$BACKEND.la
304 EOF
305         RC=$?
306         if test $RC != 0 ; then
307                 echo "ldapadd failed for backend config ($RC)!"
308                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
309                 exit $RC
310         fi
311 fi
312
313 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
314 dn: olcDatabase={2}$BACKEND,cn=config
315 objectClass: olcDatabaseConfig
316 ${nullExclude}objectClass: olc${BACKEND}Config
317 olcDatabase: {2}$BACKEND
318 olcSuffix: $BASEDN
319 ${nullExclude}olcDbDirectory: $DBDIR1B
320 olcRootDN: $MANAGERDN
321 olcRootPW: $PASSWD
322 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
323   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
324   retry="3 5 300 5" timeout=3
325 olcUpdateRef: $URI1
326
327 dn: olcOverlay=syncprov,olcDatabase={2}${BACKEND},cn=config
328 changetype: add
329 objectClass: olcOverlayConfig
330 objectClass: olcSyncProvConfig
331 olcOverlay: syncprov
332
333 dn: olcDatabase={1}$BACKEND,cn=config,cn=slave
334 objectClass: olcDatabaseConfig
335 ${nullExclude}objectClass: olc${BACKEND}Config
336 olcDatabase: {1}$BACKEND
337 olcSuffix: $BASEDN
338 ${nullExclude}olcDbDirectory: $DBDIR2A
339 olcRootDN: $MANAGERDN
340 olcRootPW: $PASSWD
341 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
342   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
343   retry="3 5 300 5" timeout=3
344 olcUpdateRef: $URI1
345
346 EOF
347 RC=$?
348 if test $RC != 0 ; then
349         echo "ldapadd failed for database config ($RC)!"
350         test $KILLSERVERS != no && kill -HUP $KILLPIDS
351         exit $RC
352 fi
353
354 if test $INDEXDB = indexdb ; then
355         $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
356 dn: olcDatabase={2}$BACKEND,cn=config
357 changetype: modify
358 add: olcDbIndex
359 olcDbIndex: objectClass,entryUUID,entryCSN eq
360 olcDbIndex: cn,uid pres,eq,sub
361 EOF
362         RC=$?
363         if test $RC != 0 ; then
364                 echo "ldapadd modify for database config ($RC)!"
365                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
366                 exit $RC
367         fi
368 fi
369
370 echo "Using ldapadd to populate provider..."
371 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
372         >> $TESTOUT 2>&1
373 RC=$?
374 if test $RC != 0 ; then
375         echo "ldapadd failed for database config ($RC)!"
376         test $KILLSERVERS != no && kill -HUP $KILLPIDS
377         exit $RC
378 fi
379
380 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
381 sleep $SLEEP1
382
383 echo "Using ldapsearch to check that syncrepl received database changes..."
384 RC=32
385 for i in 0 1 2 3 4 5; do
386         RESULT=`$LDAPSEARCH -H $URI2 \
387                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
388                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
389         if test "x$RESULT$nullOK" = "xOK" ; then
390                 RC=0
391                 break
392         fi
393         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
394         sleep $SLEEP1
395 done
396
397 if test $RC != 0 ; then
398         echo "ldapsearch failed ($RC)!"
399         test $KILLSERVERS != no && kill -HUP $KILLPIDS
400         exit $RC
401 fi
402
403 echo "Using ldapsearch to read all the entries from the provider..."
404 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
405         'objectclass=*' > $MASTEROUT 2>&1
406 RC=$?
407
408 if test $RC != 0 ; then
409         echo "ldapsearch failed at provider ($RC)!"
410         test $KILLSERVERS != no && kill -HUP $KILLPIDS
411         exit $RC
412 fi
413
414 echo "Using ldapsearch to read all the entries from the consumer..."
415 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
416         'objectclass=*' > $SLAVEOUT 2>&1
417 RC=$?
418
419 if test $RC != 0 ; then
420         echo "ldapsearch failed at consumer ($RC)!"
421         test $KILLSERVERS != no && kill -HUP $KILLPIDS
422         exit $RC
423 fi
424
425 test $KILLSERVERS != no && kill -HUP $KILLPIDS
426
427 echo "Filtering provider results..."
428 $LDIFFILTER < $MASTEROUT > $MASTERFLT
429 echo "Filtering consumer results..."
430 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
431
432 echo "Comparing retrieved entries from provider and consumer..."
433 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
434
435 if test $? != 0 ; then
436         echo "test failed - provider and consumer databases differ"
437         exit 1
438 fi
439
440 echo ">>>>> Test succeeded"
441
442 test $KILLSERVERS != no && wait
443
444 exit 0