]> git.sur5r.net Git - openldap/blob - tests/scripts/test018-syncreplication-persist
0eea26243b5db82f5810c21981943b8de59a7def
[openldap] / tests / scripts / test018-syncreplication-persist
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 if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
17         echo "Test does not support $BACKEND"
18         exit 0
19 fi
20
21 echo "running defines.sh"
22 . $SRCDIR/scripts/defines.sh
23
24 if test $SYNCPROV = syncprovno; then 
25         echo "Syncrepl provider overlay not available, test skipped"
26         exit 0
27 fi 
28
29 mkdir -p $TESTDIR $DBDIR1 $DBDIR4
30
31 #
32 # Test replication:
33 # - start master
34 # - start slave
35 # - populate over ldap
36 # - perform some modifies and deleted
37 # - attempt to modify the slave (referral or chain)
38 # - retrieve database over ldap and compare against expected results
39 #
40
41 echo "Starting master slapd on TCP/IP port $PORT1..."
42 . $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1
43 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
44 PID=$!
45 if test $WAIT != 0 ; then
46     echo PID $PID
47     read foo
48 fi
49 KILLPIDS="$PID"
50
51 sleep 1
52
53 echo "Using ldapsearch to check that master slapd is running..."
54 for i in 0 1 2 3 4 5; do
55         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
56                 'objectclass=*' > /dev/null 2>&1
57         RC=$?
58         if test $RC = 0 ; then
59                 break
60         fi
61         echo "Waiting 5 seconds for slapd to start..."
62         sleep 5
63 done
64
65 if test $RC != 0 ; then
66         echo "ldapsearch failed ($RC)!"
67         test $KILLSERVERS != no && kill -HUP $KILLPIDS
68         exit $RC
69 fi
70
71 echo "Using ldapadd to create the context prefix entry in the master..."
72 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
73         $LDIFORDEREDCP > /dev/null 2>&1
74 RC=$?
75 if test $RC != 0 ; then
76         echo "ldapadd failed ($RC)!"
77         test $KILLSERVERS != no && kill -HUP $KILLPIDS
78         exit $RC
79 fi
80
81 echo "Starting slave slapd on TCP/IP port $PORT4..."
82 . $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $CONF4
83 $SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
84 SLAVEPID=$!
85 if test $WAIT != 0 ; then
86     echo SLAVEPID $SLAVEPID
87     read foo
88 fi
89 KILLPIDS="$KILLPIDS $SLAVEPID"
90
91 sleep 1
92
93 echo "Using ldapsearch to check that slave slapd is running..."
94 for i in 0 1 2 3 4 5; do
95         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT4 \
96                 'objectclass=*' > /dev/null 2>&1
97         RC=$?
98         if test $RC = 0 ; then
99                 break
100         fi
101         echo "Waiting 5 seconds for slapd to start..."
102         sleep 5
103 done
104
105 if test $RC != 0 ; then
106         echo "ldapsearch failed ($RC)!"
107         test $KILLSERVERS != no && kill -HUP $KILLPIDS
108         exit $RC
109 fi
110
111 echo "Using ldapadd to populate the master directory..."
112 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
113         $LDIFORDEREDNOCP > /dev/null 2>&1
114 RC=$?
115 if test $RC != 0 ; then
116         echo "ldapadd failed ($RC)!"
117         test $KILLSERVERS != no && kill -HUP $KILLPIDS
118         exit $RC
119 fi
120
121 echo "Waiting 15 seconds for syncrepl to receive changes..."
122 sleep 15
123
124 echo "Stopping the provider, sleeping 10 seconds and restarting it..."
125 kill -HUP "$PID"
126 sleep 10
127 echo "RESTART" >> $LOG1
128 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
129 PID=$!
130 if test $WAIT != 0 ; then
131     echo PID $PID
132     read foo
133 fi
134 KILLPIDS="$PID $SLAVEPID"
135
136 sleep 1
137
138 echo "Using ldapsearch to check that master slapd is running..."
139 for i in 0 1 2 3 4 5; do
140         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
141                 'objectclass=*' > /dev/null 2>&1
142         RC=$?
143         if test $RC = 0 ; then
144                 break
145         fi
146         echo "Waiting 5 seconds for slapd to start..."
147         sleep 5
148 done
149
150 if test $RC != 0 ; then
151         echo "ldapsearch failed ($RC)!"
152         test $KILLSERVERS != no && kill -HUP $KILLPIDS
153         exit $RC
154 fi
155
156 echo "Using ldapmodify to modify master directory..."
157
158 #
159 # Do some modifications
160 #
161
162 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
163         $TESTOUT 2>&1 << EOMODS
164 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
165 changetype: modify
166 add: drink
167 drink: Orange Juice
168 -
169 delete: sn
170 sn: Jones
171 -
172 add: sn
173 sn: Jones
174
175 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
176 changetype: modify
177 replace: drink
178 drink: Iced Tea
179
180 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
181 changetype: modify
182 delete: uniquemember
183 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
184 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
185 -
186 add: uniquemember
187 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
188 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
189
190 dn: cn=All Staff,ou=Groups,dc=example,dc=com
191 changetype: modify
192 delete: description
193
194 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
195 changetype: add
196 objectclass: OpenLDAPperson
197 cn: Gern Jensen
198 sn: Jensen
199 uid: gjensen
200 title: Chief Investigator, ITD
201 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
202 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
203 drink: Coffee
204 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
205 description: Very odd
206 facsimiletelephonenumber: +1 313 555 7557
207 telephonenumber: +1 313 555 8343
208 mail: gjensen@mailgw.example.com
209 homephone: +1 313 555 8844
210
211 dn: ou=Retired, ou=People, dc=example,dc=com
212 changetype: add
213 objectclass: organizationalUnit
214 ou: Retired
215
216 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
217 changetype: add
218 objectclass: OpenLDAPperson
219 cn: Rosco P. Coltrane
220 sn: Coltrane
221 uid: rosco
222 description: Fat tycoon
223
224 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
225 changetype: modrdn
226 newrdn: cn=Rosco P. Coltrane
227 deleteoldrdn: 1
228 newsuperior: ou=Retired, ou=People, dc=example,dc=com
229
230 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
231 changetype: delete
232
233 EOMODS
234
235 RC=$?
236 if test $RC != 0 ; then
237         echo "ldapmodify failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 echo "Waiting 15 seconds for syncrepl to receive changes..."
243 sleep 15
244
245 echo "Stopping consumer to test recovery..."
246 kill -HUP $SLAVEPID
247 sleep 10
248
249 echo "Modifying more entries on the master..."
250 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
251         $TESTOUT 2>&1 << EOMODS
252 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
253 changetype: delete
254
255 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
256 changetype: modify
257 add: drink
258 drink: Mad Dog 20/20
259
260 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
261 changetype: add
262 objectclass: OpenLDAPperson
263 sn: Coltrane
264 uid: rosco
265 cn: Rosco P. Coltrane
266
267 EOMODS
268
269 echo "Restarting consumer..."
270 echo "RESTART" >> $LOG4
271 $SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
272 SLAVEPID=$!
273 if test $WAIT != 0 ; then
274     echo SLAVEPID $SLAVEPID
275     read foo
276 fi
277 KILLPIDS="$PID $SLAVEPID"
278
279 echo "Waiting 25 seconds for syncrepl to receive changes..."
280 sleep 25
281
282 if test ! $BACKLDAP = "ldapno" ; then
283         echo "Try updating the slave slapd..."
284         $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \
285                 $TESTOUT 2>&1 << EOMODS
286 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
287 changetype: modify
288 add: description
289 description: This write must fail because directed to a shadow context,
290 description: unless the chain overlay is configured appropriately ;)
291
292 EOMODS
293
294         RC=$?
295         if test $RC != 0 ; then
296                 echo "ldapmodify failed ($RC)!"
297                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
298                 exit $RC
299         fi
300
301         echo "Waiting 15 seconds for syncrepl to receive changes..."
302         sleep 15
303 fi
304
305 echo "Using ldapsearch to read all the entries from the master..."
306 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
307         'objectclass=*' > $MASTEROUT 2>&1
308 RC=$?
309
310 if test $RC != 0 ; then
311         echo "ldapsearch failed at master ($RC)!"
312         test $KILLSERVERS != no && kill -HUP $KILLPIDS
313         exit $RC
314 fi
315
316 echo "Using ldapsearch to read all the entries from the slave..."
317 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
318         'objectclass=*' > $SLAVEOUT 2>&1
319 RC=$?
320
321 if test $RC != 0 ; then
322         echo "ldapsearch failed at slave ($RC)!"
323         test $KILLSERVERS != no && kill -HUP $KILLPIDS
324         exit $RC
325 fi
326
327 test $KILLSERVERS != no && kill -HUP $KILLPIDS
328
329 echo "Filtering master results..."
330 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
331 echo "Filtering slave results..."
332 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
333
334 echo "Comparing retrieved entries from master and slave..."
335 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
336
337 if test $? != 0 ; then
338         echo "test failed - master and slave databases differ"
339         exit 1
340 fi
341
342 echo ">>>>> Test succeeded"
343 exit 0