]> git.sur5r.net Git - openldap/blob - tests/scripts/test049-sync-config
d8f29fa9c4358f118ad3b574ff594d8ca062ad45
[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 master
38 # - start slave
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 master 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 master 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 master..."
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 slave 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 slave 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 slave..."
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 echo "Waiting 10 seconds for syncrepl to receive changes..."
164 sleep 10
165
166 echo "Adding schema and databases on master..."
167 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
168 include: file:$SCHEMADIR/core.ldif
169
170 include: file:$SCHEMADIR/cosine.ldif
171
172 include: file:$SCHEMADIR/inetorgperson.ldif
173
174 include: file:$SCHEMADIR/openldap.ldif
175
176 include: file:$SCHEMADIR/nis.ldif
177 EOF
178 RC=$?
179 if test $RC != 0 ; then
180         echo "ldapadd failed for schema config ($RC)!"
181         test $KILLSERVERS != no && kill -HUP $KILLPIDS
182         exit $RC
183 fi
184
185 if [ "$BACKENDTYPE" = mod ]; then
186         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
187 dn: cn=module,cn=config
188 objectClass: olcModuleList
189 cn: module
190 olcModulePath: ../../../servers/slapd/back-$BACKEND
191 olcModuleLoad: back_$BACKEND.la
192 EOF
193         RC=$?
194         if test $RC != 0 ; then
195                 echo "ldapadd failed for backend config ($RC)!"
196                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
197                 exit $RC
198         fi
199 fi
200
201 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
202 dn: olcDatabase={1}$BACKEND,cn=config
203 objectClass: olcDatabaseConfig
204 objectClass: olc${BACKEND}Config
205 olcDatabase: {1}$BACKEND
206 olcSuffix: $BASEDN
207 olcDbDirectory: ./db
208 olcRootDN: $MANAGERDN
209 olcRootPW: $PASSWD
210 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
211   credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
212   interval=00:00:00:10
213 olcUpdateRef: $URI1
214
215 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
216 changetype: add
217 objectClass: olcOverlayConfig
218 objectClass: olcSyncProvConfig
219 olcOverlay: syncprov
220 EOF
221 RC=$?
222 if test $RC != 0 ; then
223         echo "ldapadd failed for database config ($RC)!"
224         test $KILLSERVERS != no && kill -HUP $KILLPIDS
225         exit $RC
226 fi
227
228 echo "Using ldapadd to populate master..."
229 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
230         >> $TESTOUT 2>&1
231 RC=$?
232 if test $RC != 0 ; then
233         echo "ldapadd failed for database config ($RC)!"
234         test $KILLSERVERS != no && kill -HUP $KILLPIDS
235         exit $RC
236 fi
237
238 echo "Waiting 20 seconds for syncrepl to receive changes..."
239 sleep 20
240
241 echo "Using ldapsearch to read config from the master..."
242 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
243         'objectclass=*' > $MASTEROUT 2>&1
244 RC=$?
245
246 if test $RC != 0 ; then
247         echo "ldapsearch failed at master ($RC)!"
248         test $KILLSERVERS != no && kill -HUP $KILLPIDS
249         exit $RC
250 fi
251
252 echo "Using ldapsearch to read config from the slave..."
253 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
254         'objectclass=*' > $SLAVEOUT 2>&1
255 RC=$?
256
257 if test $RC != 0 ; then
258         echo "ldapsearch failed at slave ($RC)!"
259         test $KILLSERVERS != no && kill -HUP $KILLPIDS
260         exit $RC
261 fi
262
263 echo "Filtering master results..."
264 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
265 echo "Filtering slave results..."
266 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
267
268 echo "Comparing retrieved entries from master and slave..."
269 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
270
271 if test $? != 0 ; then
272         echo "test failed - master and slave databases differ"
273         test $KILLSERVERS != no && kill -HUP $KILLPIDS
274         exit 1
275 fi
276
277 echo "Using ldapsearch to read all the entries from the master..."
278 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
279         'objectclass=*' > $MASTEROUT 2>&1
280 RC=$?
281
282 if test $RC != 0 ; then
283         echo "ldapsearch failed at master ($RC)!"
284         test $KILLSERVERS != no && kill -HUP $KILLPIDS
285         exit $RC
286 fi
287
288 echo "Using ldapsearch to read all the entries from the slave..."
289 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
290         'objectclass=*' > $SLAVEOUT 2>&1
291 RC=$?
292
293 if test $RC != 0 ; then
294         echo "ldapsearch failed at slave ($RC)!"
295         test $KILLSERVERS != no && kill -HUP $KILLPIDS
296         exit $RC
297 fi
298
299 test $KILLSERVERS != no && kill -HUP $KILLPIDS
300
301 echo "Filtering master results..."
302 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
303 echo "Filtering slave results..."
304 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
305
306 echo "Comparing retrieved entries from master and slave..."
307 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
308
309 if test $? != 0 ; then
310         echo "test failed - master and slave databases differ"
311         exit 1
312 fi
313
314 echo ">>>>> Test succeeded"
315
316 test $KILLSERVERS != no && wait
317
318 exit 0