]> git.sur5r.net Git - openldap/blob - tests/scripts/test049-sync-config
Fix prev commit
[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 -
118 add: olcUpdateRef
119 olcUpdateRef: $URI1
120
121 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
122 changetype: add
123 objectClass: olcOverlayConfig
124 objectClass: olcSyncProvConfig
125 olcOverlay: syncprov
126 EOF
127 RC=$?
128 if test $RC != 0 ; then
129         echo "ldapmodify failed for syncrepl config ($RC)!"
130         test $KILLSERVERS != no && kill -HUP $KILLPIDS
131         exit $RC
132 fi
133
134 echo "Starting consumer slapd on TCP/IP port $PORT2..."
135 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
136 cd $CONDIR
137 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
138 SLAVEPID=$!
139 if test $WAIT != 0 ; then
140     echo SLAVEPID $SLAVEPID
141     read foo
142 fi
143 KILLPIDS="$KILLPIDS $SLAVEPID"
144 cd $TESTWD
145
146 sleep 1
147
148 echo "Using ldapsearch to check that consumer slapd is running..."
149 for i in 0 1 2 3 4 5; do
150         $LDAPSEARCH -s base -b "" -H $URI2 \
151                 'objectclass=*' > /dev/null 2>&1
152         RC=$?
153         if test $RC = 0 ; then
154                 break
155         fi
156         echo "Waiting 5 seconds for slapd to start..."
157         sleep 5
158 done
159
160 if test $RC != 0 ; then
161         echo "ldapsearch failed ($RC)!"
162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
163         exit $RC
164 fi
165
166 echo "Configuring syncrepl on consumer..."
167 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
168 dn: olcDatabase={0}config,cn=config
169 changetype: modify
170 add: olcSyncRepl
171 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
172   credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
173 -
174 add: olcUpdateRef
175 olcUpdateRef: $URI1
176 EOF
177
178 SLEEP=10
179 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
180 sleep $SLEEP
181
182 echo "Using ldapsearch to check that syncrepl received config changes..."
183 RC=32
184 for i in 0 1 2 3 4 5; do
185         RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
186                 -s base -b "olcDatabase={0}config,cn=config" \
187                 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
188         if test "x$RESULT" = "xOK" ; then
189                 RC=0
190                 break
191         fi
192         echo "Waiting 5 seconds for syncrepl to receive changes..."
193         sleep 5
194 done
195
196 if test $RC != 0 ; then
197         echo "ldapsearch failed ($RC)!"
198         test $KILLSERVERS != no && kill -HUP $KILLPIDS
199         exit $RC
200 fi
201
202 echo "Adding schema and databases on producer..."
203 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
204 include: file://$ABS_SCHEMADIR/core.ldif
205
206 include: file://$ABS_SCHEMADIR/cosine.ldif
207
208 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
209
210 include: file://$ABS_SCHEMADIR/openldap.ldif
211
212 include: file://$ABS_SCHEMADIR/nis.ldif
213 EOF
214 RC=$?
215 if test $RC != 0 ; then
216         echo "ldapadd failed for schema config ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 if [ "$BACKENDTYPE" = mod ]; then
222         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
223 dn: cn=module,cn=config
224 objectClass: olcModuleList
225 cn: module
226 olcModulePath: ../../../servers/slapd/back-$BACKEND
227 olcModuleLoad: back_$BACKEND.la
228 EOF
229         RC=$?
230         if test $RC != 0 ; then
231                 echo "ldapadd failed for backend config ($RC)!"
232                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
233                 exit $RC
234         fi
235 fi
236
237 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
238 dn: olcDatabase={1}$BACKEND,cn=config
239 objectClass: olcDatabaseConfig
240 objectClass: olc${BACKEND}Config
241 olcDatabase: {1}$BACKEND
242 olcSuffix: $BASEDN
243 olcDbDirectory: ./db
244 olcRootDN: $MANAGERDN
245 olcRootPW: $PASSWD
246 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
247   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
248 olcUpdateRef: $URI1
249
250 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
251 changetype: add
252 objectClass: olcOverlayConfig
253 objectClass: olcSyncProvConfig
254 olcOverlay: syncprov
255 EOF
256 RC=$?
257 if test $RC != 0 ; then
258         echo "ldapadd failed for database config ($RC)!"
259         test $KILLSERVERS != no && kill -HUP $KILLPIDS
260         exit $RC
261 fi
262
263 echo "Using ldapadd to populate producer..."
264 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
265         >> $TESTOUT 2>&1
266 RC=$?
267 if test $RC != 0 ; then
268         echo "ldapadd failed for database config ($RC)!"
269         test $KILLSERVERS != no && kill -HUP $KILLPIDS
270         exit $RC
271 fi
272
273 SLEEP=20
274 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
275 sleep $SLEEP
276
277 echo "Using ldapsearch to check that syncrepl received database changes..."
278 RC=32
279 for i in 0 1 2 3 4 5; do
280         RESULT=`$LDAPSEARCH -H $URI2 \
281                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
282                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
283         if test "x$RESULT" = "xOK" ; then
284                 RC=0
285                 break
286         fi
287         echo "Waiting 5 seconds for syncrepl to receive changes..."
288         sleep 5
289 done
290
291 if test $RC != 0 ; then
292         echo "ldapsearch failed ($RC)!"
293         test $KILLSERVERS != no && kill -HUP $KILLPIDS
294         exit $RC
295 fi
296
297 echo "Using ldapsearch to read config from the producer..."
298 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
299         'objectclass=*' > $MASTEROUT 2>&1
300 RC=$?
301
302 if test $RC != 0 ; then
303         echo "ldapsearch failed at producer ($RC)!"
304         test $KILLSERVERS != no && kill -HUP $KILLPIDS
305         exit $RC
306 fi
307
308 echo "Using ldapsearch to read config from the consumer..."
309 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
310         'objectclass=*' > $SLAVEOUT 2>&1
311 RC=$?
312
313 if test $RC != 0 ; then
314         echo "ldapsearch failed at consumer ($RC)!"
315         test $KILLSERVERS != no && kill -HUP $KILLPIDS
316         exit $RC
317 fi
318
319 echo "Filtering producer results..."
320 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
321 echo "Filtering consumer results..."
322 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
323
324 echo "Comparing retrieved configs from producer and consumer..."
325 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
326
327 if test $? != 0 ; then
328         echo "test failed - producer and consumer configs differ"
329         test $KILLSERVERS != no && kill -HUP $KILLPIDS
330         exit 1
331 fi
332
333 echo "Using ldapsearch to read all the entries from the producer..."
334 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
335         'objectclass=*' > $MASTEROUT 2>&1
336 RC=$?
337
338 if test $RC != 0 ; then
339         echo "ldapsearch failed at producer ($RC)!"
340         test $KILLSERVERS != no && kill -HUP $KILLPIDS
341         exit $RC
342 fi
343
344 echo "Using ldapsearch to read all the entries from the consumer..."
345 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
346         'objectclass=*' > $SLAVEOUT 2>&1
347 RC=$?
348
349 if test $RC != 0 ; then
350         echo "ldapsearch failed at consumer ($RC)!"
351         test $KILLSERVERS != no && kill -HUP $KILLPIDS
352         exit $RC
353 fi
354
355 test $KILLSERVERS != no && kill -HUP $KILLPIDS
356
357 echo "Filtering producer results..."
358 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
359 echo "Filtering consumer results..."
360 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
361
362 echo "Comparing retrieved entries from producer and consumer..."
363 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
364
365 if test $? != 0 ; then
366         echo "test failed - producer and consumer databases differ"
367         exit 1
368 fi
369
370 echo ">>>>> Test succeeded"
371
372 test $KILLSERVERS != no && wait
373
374 exit 0