]> git.sur5r.net Git - openldap/blob - tests/scripts/test049-sync-config
5edbc54963dfc78aa703a6585a8169857e2b2c40
[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-2008 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/con
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:10"
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 producer
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 producer 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 producer 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 producer..."
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: ../../../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" $SYNCTYPE
117   retry="5 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" $SYNCTYPE
174   retry="5 5 300 5" timeout=3
175 -
176 add: olcUpdateRef
177 olcUpdateRef: $URI1
178 EOF
179
180 SLEEP=10
181 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
182 sleep $SLEEP
183
184 echo "Using ldapsearch to check that syncrepl received config changes..."
185 RC=32
186 for i in 0 1 2 3 4 5; do
187         RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
188                 -s base -b "olcDatabase={0}config,cn=config" \
189                 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
190         if test "x$RESULT" = "xOK" ; then
191                 RC=0
192                 break
193         fi
194         echo "Waiting 5 seconds for syncrepl to receive changes..."
195         sleep 5
196 done
197
198 if test $RC != 0 ; then
199         echo "ldapsearch failed ($RC)!"
200         test $KILLSERVERS != no && kill -HUP $KILLPIDS
201         exit $RC
202 fi
203
204 echo "Adding schema and databases on producer..."
205 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
206 include: file://$ABS_SCHEMADIR/core.ldif
207
208 include: file://$ABS_SCHEMADIR/cosine.ldif
209
210 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
211
212 include: file://$ABS_SCHEMADIR/openldap.ldif
213
214 include: file://$ABS_SCHEMADIR/nis.ldif
215 EOF
216 RC=$?
217 if test $RC != 0 ; then
218         echo "ldapadd failed for schema config ($RC)!"
219         test $KILLSERVERS != no && kill -HUP $KILLPIDS
220         exit $RC
221 fi
222
223 if [ "$BACKENDTYPE" = mod ]; then
224         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
225 dn: cn=module,cn=config
226 objectClass: olcModuleList
227 cn: module
228 olcModulePath: ../../../servers/slapd/back-$BACKEND
229 olcModuleLoad: back_$BACKEND.la
230 EOF
231         RC=$?
232         if test $RC != 0 ; then
233                 echo "ldapadd failed for backend config ($RC)!"
234                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
235                 exit $RC
236         fi
237 fi
238
239 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
240 dn: olcDatabase={1}$BACKEND,cn=config
241 objectClass: olcDatabaseConfig
242 objectClass: olc${BACKEND}Config
243 olcDatabase: {1}$BACKEND
244 olcSuffix: $BASEDN
245 olcDbDirectory: ./db
246 olcRootDN: $MANAGERDN
247 olcRootPW: $PASSWD
248 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
249   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
250   retry="5 5 300 5" timeout=3
251 olcUpdateRef: $URI1
252
253 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
254 changetype: add
255 objectClass: olcOverlayConfig
256 objectClass: olcSyncProvConfig
257 olcOverlay: syncprov
258 EOF
259 RC=$?
260 if test $RC != 0 ; then
261         echo "ldapadd failed for database config ($RC)!"
262         test $KILLSERVERS != no && kill -HUP $KILLPIDS
263         exit $RC
264 fi
265
266 echo "Using ldapadd to populate producer..."
267 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
268         >> $TESTOUT 2>&1
269 RC=$?
270 if test $RC != 0 ; then
271         echo "ldapadd failed for database config ($RC)!"
272         test $KILLSERVERS != no && kill -HUP $KILLPIDS
273         exit $RC
274 fi
275
276 SLEEP=20
277 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
278 sleep $SLEEP
279
280 echo "Using ldapsearch to check that syncrepl received database changes..."
281 RC=32
282 for i in 0 1 2 3 4 5; do
283         RESULT=`$LDAPSEARCH -H $URI2 \
284                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
285                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
286         if test "x$RESULT" = "xOK" ; then
287                 RC=0
288                 break
289         fi
290         echo "Waiting 5 seconds for syncrepl to receive changes..."
291         sleep 5
292 done
293
294 if test $RC != 0 ; then
295         echo "ldapsearch failed ($RC)!"
296         test $KILLSERVERS != no && kill -HUP $KILLPIDS
297         exit $RC
298 fi
299
300 echo "Using ldapsearch to read config from the producer..."
301 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
302         'objectclass=*' > $MASTEROUT 2>&1
303 RC=$?
304
305 if test $RC != 0 ; then
306         echo "ldapsearch failed at producer ($RC)!"
307         test $KILLSERVERS != no && kill -HUP $KILLPIDS
308         exit $RC
309 fi
310
311 echo "Using ldapsearch to read config from the consumer..."
312 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
313         'objectclass=*' > $SLAVEOUT 2>&1
314 RC=$?
315
316 if test $RC != 0 ; then
317         echo "ldapsearch failed at consumer ($RC)!"
318         test $KILLSERVERS != no && kill -HUP $KILLPIDS
319         exit $RC
320 fi
321
322 echo "Filtering producer results..."
323 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
324 echo "Filtering consumer results..."
325 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
326
327 echo "Comparing retrieved configs from producer and consumer..."
328 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
329
330 if test $? != 0 ; then
331         echo "test failed - producer and consumer configs differ"
332         test $KILLSERVERS != no && kill -HUP $KILLPIDS
333         exit 1
334 fi
335
336 echo "Using ldapsearch to read all the entries from the producer..."
337 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
338         'objectclass=*' > $MASTEROUT 2>&1
339 RC=$?
340
341 if test $RC != 0 ; then
342         echo "ldapsearch failed at producer ($RC)!"
343         test $KILLSERVERS != no && kill -HUP $KILLPIDS
344         exit $RC
345 fi
346
347 echo "Using ldapsearch to read all the entries from the consumer..."
348 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
349         'objectclass=*' > $SLAVEOUT 2>&1
350 RC=$?
351
352 if test $RC != 0 ; then
353         echo "ldapsearch failed at consumer ($RC)!"
354         test $KILLSERVERS != no && kill -HUP $KILLPIDS
355         exit $RC
356 fi
357
358 test $KILLSERVERS != no && kill -HUP $KILLPIDS
359
360 echo "Filtering producer results..."
361 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
362 echo "Filtering consumer results..."
363 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
364
365 echo "Comparing retrieved entries from producer and consumer..."
366 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
367
368 if test $? != 0 ; then
369         echo "test failed - producer and consumer databases differ"
370         exit 1
371 fi
372
373 echo ">>>>> Test succeeded"
374
375 test $KILLSERVERS != no && wait
376
377 exit 0