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