]> git.sur5r.net Git - openldap/blob - tests/scripts/test007-replication
if enabled, test the chain overlay with global scope to propagate writes from shadow...
[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 # - retrieve database over ldap and compare against expected results
35 #
36
37 echo "Starting master slapd on TCP/IP port $PORT1..."
38 . $CONFFILTER $BACKEND $MONITORDB < $MASTERCONF > $CONF1
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40 PID=$!
41 if test $WAIT != 0 ; then
42     echo PID $PID
43     read foo
44 fi
45 KILLPIDS="$PID"
46
47 echo "Starting slave slapd on TCP/IP port $PORT2..."
48 . $CONFFILTER $BACKEND $MONITORDB < $SLAVECONF > $CONF2
49 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
50 SLAVEPID=$!
51 if test $WAIT != 0 ; then
52     echo SLAVEPID $SLAVEPID
53     read foo
54 fi
55 KILLPIDS="$KILLPIDS $SLAVEPID"
56
57 echo "Using ldapsearch to check that master slapd is running..."
58 for i in 0 1 2 3 4 5; do
59         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
60                 'objectclass=*' > /dev/null 2>&1
61         RC=$?
62         if test $RC = 0 ; then
63                 break
64         fi
65         echo "Waiting 5 seconds for slapd to start..."
66         sleep 5
67 done
68
69 echo "Using ldapsearch to check that slave slapd is running..."
70 for i in 0 1 2 3 4 5; do
71         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
72                 'objectclass=*' > /dev/null 2>&1
73         RC=$?
74         if test $RC = 0 ; then
75                 break
76         fi
77         echo "Waiting 5 seconds for slapd to start..."
78         sleep 5
79 done
80
81 echo "Starting slurpd..."
82 $SLURPD -f $CONF1 -d ${SLURPD_DEBUG-5} -t $DBDIR1B > $SLURPLOG 2>&1 &
83 SLURPPID=$!
84 if test $WAIT != 0 ; then
85     echo SLURPPID $SLURPPID
86     read foo
87 fi
88 KILLPIDS="$KILLPIDS $SLURPPID"
89
90 echo "Using ldapadd to populate the master directory..."
91 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
92         $LDIFORDERED > /dev/null 2>&1
93 RC=$?
94 if test $RC != 0 ; then
95         echo "ldapadd failed ($RC)!"
96         test $KILLSERVERS != no && kill -HUP $KILLPIDS
97         exit $RC
98 fi
99
100 echo "Waiting 15 seconds for slurpd to send changes..."
101 sleep 15
102
103 echo "Using ldapmodify to modify master directory..."
104
105 #
106 # Do some modifications
107 #
108
109 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
110         $TESTOUT 2>&1 << EOMODS
111 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
112 changetype: modify
113 add: drink
114 drink: Orange Juice
115 -
116 delete: sn
117 sn: Jones
118 -
119 add: sn
120 sn: Jones
121
122 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example, dc=com
123 changetype: modify
124 replace: drink
125 drink: Iced Tea
126 drink: Mad Dog 20/20
127
128 dn: cn=ITD Staff,ou=Groups,dc=example, dc=com
129 changetype: modify
130 delete: uniqueMember
131 uniqueMember: cn=James A Jones 2, ou=Information Technology Division,
132  ou=People, dc=example, dc=com
133 uniqueMember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example, dc=com
134 -
135 add: uniqueMember
136 uniqueMember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example, dc=com
137 uniqueMember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
138
139 dn: cn=All Staff,ou=Groups,dc=example, dc=com
140 changetype: modify
141 delete: description
142
143 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example, dc=com
144 changetype: add
145 objectclass: OpenLDAPperson
146 cn: Gern Jensen
147 sn: Jensen
148 uid: gjensen
149 title: Chief Investigator, ITD
150 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
151 seealso: cn=All Staff, ou=Groups, dc=example, dc=com
152 drink: Coffee
153 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
154 description: Very odd
155 facsimiletelephonenumber: +1 313 555 7557
156 telephonenumber: +1 313 555 8343
157 mail: gjensen@mailgw.example.com
158 homephone: +1 313 555 8844
159
160 dn: ou=Retired, ou=People, dc=example, dc=com
161 changetype: add
162 objectclass: organizationalUnit
163 ou: Retired
164
165 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example, dc=com
166 changetype: add
167 objectclass: OpenLDAPperson
168 cn: Rosco P. Coltrane
169 sn: Coltrane
170 uid: rosco
171
172 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example, dc=com
173 changetype: modrdn
174 newrdn: cn=Rosco P. Coltrane
175 deleteoldrdn: 1
176 newsuperior: ou=Retired, ou=People, dc=example, dc=com
177
178 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example, dc=com
179 changetype: delete
180
181 EOMODS
182
183 RC=$?
184 if test $RC != 0 ; then
185         echo "ldapmodify failed ($RC)!"
186         test $KILLSERVERS != no && kill -HUP $KILLPIDS
187         exit $RC
188 fi
189
190 echo "Waiting 15 seconds for slurpd to send changes..."
191 sleep 15
192
193 echo "Try updating the slave..."
194 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
195         $TESTOUT 2>&1 << EOMODS
196 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
197 changetype: modify
198 add: description
199 description: This write must fail because directed to a shadow context,
200 description: unless the chain overlay is configured appropriately ;)
201
202 EOMODS
203
204 RC=$?
205
206 if test $BACKLDAP = "ldapno" ; then
207         # expect 10 (LDAP_REFERRAL)...
208         if test $RC != 10 ; then
209                 echo "ldapmodify should have failed ($RC)!"
210                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
211                 exit $RC
212         fi
213
214 else
215         # expect 0 (LDAP_SUCCESS)...
216         if test $RC != 0 ; then
217                 echo "ldapmodify failed ($RC)!"
218                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
219                 exit $RC
220         fi
221
222         echo "Waiting 5 seconds for slurpd to send changes..."
223         sleep 5
224 fi
225
226 echo "Using ldapsearch to read all the entries from the master..."
227 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
228         'objectclass=*' > $MASTEROUT 2>&1
229 RC=$?
230
231 if test $RC != 0 ; then
232         echo "ldapsearch failed ($RC)!"
233         test $KILLSERVERS != no && kill -HUP $KILLPIDS
234         exit $RC
235 fi
236
237 echo "Using ldapsearch to read all the entries from the slave..."
238 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
239         'objectclass=*' > $SLAVEOUT 2>&1
240 RC=$?
241
242 if test $RC != 0 ; then
243         echo "ldapsearch failed ($RC)!"
244         test $KILLSERVERS != no && kill -HUP $KILLPIDS
245         exit $RC
246 fi
247
248 test $KILLSERVERS != no && kill -HUP $KILLPIDS
249
250 echo "Filtering master results..."
251 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
252 echo "Filtering slave results..."
253 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
254
255 echo "Comparing retrieved entries from master and slave..."
256 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
257
258 if test $? != 0 ; then
259         echo "test failed - master and slave databases differ"
260         exit 1
261 fi
262
263 echo ">>>>> Test succeeded"
264 exit 0