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