]> git.sur5r.net Git - openldap/blob - tests/scripts/test007-replication
fix messages
[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 "Try updating the slave slapd..."
195 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
196         $TESTOUT 2>&1 << EOMODS
197 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
198 changetype: modify
199 add: description
200 description: This write must fail because directed to a shadow context,
201 description: unless the chain overlay is configured appropriately ;)
202
203 EOMODS
204
205 RC=$?
206
207 if test $BACKLDAP = "ldapno" ; then
208         # expect 10 (LDAP_REFERRAL)...
209         if test $RC != 10 ; then
210                 echo "ldapmodify should have failed ($RC)!"
211                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
212                 exit $RC
213         fi
214
215 else
216         # expect 0 (LDAP_SUCCESS)...
217         if test $RC != 0 ; then
218                 echo "ldapmodify failed ($RC)!"
219                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
220                 exit $RC
221         fi
222
223         echo "Waiting 5 seconds for slurpd to send changes..."
224         sleep 5
225 fi
226
227 echo "Using ldapsearch to read all the entries from the master..."
228 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
229         'objectclass=*' > $MASTEROUT 2>&1
230 RC=$?
231
232 if test $RC != 0 ; then
233         echo "ldapsearch failed ($RC)!"
234         test $KILLSERVERS != no && kill -HUP $KILLPIDS
235         exit $RC
236 fi
237
238 echo "Using ldapsearch to read all the entries from the slave..."
239 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
240         'objectclass=*' > $SLAVEOUT 2>&1
241 RC=$?
242
243 if test $RC != 0 ; then
244         echo "ldapsearch failed ($RC)!"
245         test $KILLSERVERS != no && kill -HUP $KILLPIDS
246         exit $RC
247 fi
248
249 test $KILLSERVERS != no && kill -HUP $KILLPIDS
250
251 echo "Filtering master results..."
252 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
253 echo "Filtering slave results..."
254 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
255
256 echo "Comparing retrieved entries from master and slave..."
257 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
258
259 if test $? != 0 ; then
260         echo "test failed - master and slave databases differ"
261         exit 1
262 fi
263
264 echo ">>>>> Test succeeded"
265 exit 0