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