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