]> git.sur5r.net Git - openldap/blob - tests/scripts/test049-sync-config
allow each (back-config) syncrepl test to use the preferred sync type, but allow...
[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 else
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 fi
51
52 #
53 # Test replication of dynamic config:
54 # - start producer
55 # - start consumer
56 # - configure over ldap
57 # - populate over ldap
58 # - configure syncrepl over ldap
59 # - retrieve database over ldap and compare against expected results
60 #
61
62 echo "Starting producer slapd on TCP/IP port $PORT1..."
63 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
64 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
65 cd $PRODIR
66 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
67 PID=$!
68 if test $WAIT != 0 ; then
69     echo PID $PID
70     read foo
71 fi
72 KILLPIDS="$PID"
73 cd $TESTWD
74
75 sleep 1
76
77 echo "Using ldapsearch to check that producer slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "" -H $URI1 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88
89 if test $RC != 0 ; then
90         echo "ldapsearch failed ($RC)!"
91         test $KILLSERVERS != no && kill -HUP $KILLPIDS
92         exit $RC
93 fi
94
95 echo "Inserting syncprov overlay on producer..."
96 if [ "$SYNCPROV" = syncprovmod ]; then
97         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
98 dn: cn=module,cn=config
99 objectClass: olcModuleList
100 cn: module
101 olcModulePath: ../../../servers/slapd/overlays
102 olcModuleLoad: syncprov.la
103 EOF
104         RC=$?
105         if test $RC != 0 ; then
106                 echo "ldapadd failed for moduleLoad ($RC)!"
107                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
108                 exit $RC
109         fi
110 fi
111 read CONFIGPW < $CONFIGPWF
112 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
113 dn: olcDatabase={0}config,cn=config
114 changetype: modify
115 add: olcSyncRepl
116 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
117   credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
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 -
175 add: olcUpdateRef
176 olcUpdateRef: $URI1
177 EOF
178
179 SLEEP=10
180 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
181 sleep $SLEEP
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 5 seconds for syncrepl to receive changes..."
194         sleep 5
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 producer..."
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 if [ "$BACKENDTYPE" = mod ]; then
223         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
224 dn: cn=module,cn=config
225 objectClass: olcModuleList
226 cn: module
227 olcModulePath: ../../../servers/slapd/back-$BACKEND
228 olcModuleLoad: back_$BACKEND.la
229 EOF
230         RC=$?
231         if test $RC != 0 ; then
232                 echo "ldapadd failed for backend config ($RC)!"
233                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
234                 exit $RC
235         fi
236 fi
237
238 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
239 dn: olcDatabase={1}$BACKEND,cn=config
240 objectClass: olcDatabaseConfig
241 objectClass: olc${BACKEND}Config
242 olcDatabase: {1}$BACKEND
243 olcSuffix: $BASEDN
244 olcDbDirectory: ./db
245 olcRootDN: $MANAGERDN
246 olcRootPW: $PASSWD
247 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
248   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
249 olcUpdateRef: $URI1
250
251 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
252 changetype: add
253 objectClass: olcOverlayConfig
254 objectClass: olcSyncProvConfig
255 olcOverlay: syncprov
256 EOF
257 RC=$?
258 if test $RC != 0 ; then
259         echo "ldapadd failed for database config ($RC)!"
260         test $KILLSERVERS != no && kill -HUP $KILLPIDS
261         exit $RC
262 fi
263
264 echo "Using ldapadd to populate producer..."
265 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
266         >> $TESTOUT 2>&1
267 RC=$?
268 if test $RC != 0 ; then
269         echo "ldapadd failed for database config ($RC)!"
270         test $KILLSERVERS != no && kill -HUP $KILLPIDS
271         exit $RC
272 fi
273
274 SLEEP=20
275 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
276 sleep $SLEEP
277
278 echo "Using ldapsearch to check that syncrepl received database changes..."
279 RC=32
280 for i in 0 1 2 3 4 5; do
281         RESULT=`$LDAPSEARCH -H $URI2 \
282                 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
283                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
284         if test "x$RESULT" = "xOK" ; then
285                 RC=0
286                 break
287         fi
288         echo "Waiting 5 seconds for syncrepl to receive changes..."
289         sleep 5
290 done
291
292 if test $RC != 0 ; then
293         echo "ldapsearch failed ($RC)!"
294         test $KILLSERVERS != no && kill -HUP $KILLPIDS
295         exit $RC
296 fi
297
298 echo "Using ldapsearch to read config from the producer..."
299 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
300         'objectclass=*' > $MASTEROUT 2>&1
301 RC=$?
302
303 if test $RC != 0 ; then
304         echo "ldapsearch failed at producer ($RC)!"
305         test $KILLSERVERS != no && kill -HUP $KILLPIDS
306         exit $RC
307 fi
308
309 echo "Using ldapsearch to read config from the consumer..."
310 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
311         'objectclass=*' > $SLAVEOUT 2>&1
312 RC=$?
313
314 if test $RC != 0 ; then
315         echo "ldapsearch failed at consumer ($RC)!"
316         test $KILLSERVERS != no && kill -HUP $KILLPIDS
317         exit $RC
318 fi
319
320 echo "Filtering producer results..."
321 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
322 echo "Filtering consumer results..."
323 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
324
325 echo "Comparing retrieved configs from producer and consumer..."
326 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
327
328 if test $? != 0 ; then
329         echo "test failed - producer and consumer configs differ"
330         test $KILLSERVERS != no && kill -HUP $KILLPIDS
331         exit 1
332 fi
333
334 echo "Using ldapsearch to read all the entries from the producer..."
335 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
336         'objectclass=*' > $MASTEROUT 2>&1
337 RC=$?
338
339 if test $RC != 0 ; then
340         echo "ldapsearch failed at producer ($RC)!"
341         test $KILLSERVERS != no && kill -HUP $KILLPIDS
342         exit $RC
343 fi
344
345 echo "Using ldapsearch to read all the entries from the consumer..."
346 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
347         'objectclass=*' > $SLAVEOUT 2>&1
348 RC=$?
349
350 if test $RC != 0 ; then
351         echo "ldapsearch failed at consumer ($RC)!"
352         test $KILLSERVERS != no && kill -HUP $KILLPIDS
353         exit $RC
354 fi
355
356 test $KILLSERVERS != no && kill -HUP $KILLPIDS
357
358 echo "Filtering producer results..."
359 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
360 echo "Filtering consumer results..."
361 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
362
363 echo "Comparing retrieved entries from producer and consumer..."
364 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
365
366 if test $? != 0 ; then
367         echo "test failed - producer and consumer databases differ"
368         exit 1
369 fi
370
371 echo ">>>>> Test succeeded"
372
373 test $KILLSERVERS != no && wait
374
375 exit 0