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