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