]> git.sur5r.net Git - openldap/blob - tests/scripts/test011-subtree-repl
Minor cleanup
[openldap] / tests / scripts / test011-subtree-repl
1 #! /bin/sh
2 # $OpenLDAP$
3
4 SRCDIR="."
5 if test $# -ge 1 ; then
6         SRCDIR=$1; shift
7 fi
8 BACKEND=ldbm
9 if test $# -ge 1 ; then
10         BACKEND=$1; shift
11 fi
12 WAIT=0
13 if test $# -ge 1 ; then
14         WAIT=1; shift
15 fi
16
17 echo "running defines.sh"
18 . $SRCDIR/scripts/defines.sh
19
20 #
21 # Test replication:
22 # - start master
23 # - start slave
24 # - create root entry in slave
25 # - start slurpd
26 # - populate over ldap
27 # - perform some modifies and deleted
28 # - retrieve database over ldap and compare against expected results
29 #
30
31 if test ! -x $SLURPD ; then
32         echo ">>>>> $SLURPD is not executable or do not exist."
33         echo ">>>>> Test skipped."
34         exit 0
35 fi
36
37 echo "Cleaning up in $DBDIR..."
38 rm -f $DBDIR/[!C]*
39 echo "Cleaning up in $REPLDIR..."
40 rm -f $REPLDIR/replica/[!C]*
41 rm -f $REPLDIR/[!C]*
42
43 echo "Starting master slapd on TCP/IP port $PORT..."
44 . $CONFFILTER $BACKEND < $SUBMASTERCONF > $DBCONF
45 $SLAPD -f $DBCONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
46 PID=$!
47 if test $WAIT != 0 ; then
48     echo PID $PID
49     read foo
50 fi
51
52 echo "Starting slave slapd on TCP/IP port $SLAVEPORT..."
53 . $CONFFILTER $BACKEND < $SUBSLAVECONF > $REPLCONF
54 $SLAPD -f $REPLCONF -h $SLAVEURI -d $LVL $TIMING > $SLAVELOG 2>&1 &
55 SLAVEPID=$!
56 if test $WAIT != 0 ; then
57     echo SLAVEPID $SLAVEPID
58     read foo
59 fi
60
61 echo "Using ldapsearch to check that master slapd is running..."
62 for i in 0 1 2 3 4 5; do
63         $LDAPSEARCH -s base -b "$MONITOR" -h localhost -p $PORT \
64                 'objectclass=*' > /dev/null 2>&1
65         RC=$?
66         if test $RC = 1 ; then
67                 echo "Waiting 5 seconds for slapd to start..."
68                 sleep 5
69         fi
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 $PORT \
75                 'objectclass=*' > /dev/null 2>&1
76         RC=$?
77         if test $RC = 1 ; then
78                 echo "Waiting 5 seconds for slapd to start..."
79                 sleep 5
80         fi
81 done
82
83 echo "Starting slurpd..."
84 $SLURPD -f $SUBMASTERCONF -d ${SLURPD_DEBUG-5} -t $REPLDIR > $SLURPLOG 2>&1 &
85 SLURPPID=$!
86
87 echo "Using ldapadd to populate the master directory..."
88 $LDAPADD -D "$MANAGERDN" -h localhost -p $PORT -w $PASSWD < \
89         $LDIFORDERED > /dev/null 2>&1
90 RC=$?
91 if test $RC != 0 ; then
92         echo "ldapadd failed ($RC)!"
93         kill -INT $PID $SLAVEPID
94         kill -KILL $SLURPPID
95         exit $RC
96 fi
97
98 echo "Waiting 15 seconds for slurpd to send changes..."
99 sleep 15
100
101 echo "Using ldapmodify to modify master directory..."
102
103 #
104 # Do some modifications
105 #
106
107 $LDAPMODIFY -v -D "$MANAGERDN" -h localhost -p $PORT -w $PASSWD > \
108         $TESTOUT 2>&1 << EOMODS
109 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
110 changetype: modify
111 add: drink
112 drink: Orange Juice
113
114 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
115 changetype: modify
116 replace: drink
117 drink: Iced Tea
118 drink: Mad Dog 20/20
119
120 dn: cn=ITD Staff,ou=Groups,o=University of Michigan,c=US
121 delete: member
122 member: cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
123 member: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
124 -
125 add: member
126 member: cn=Dorothy Stevens, ou=Alumni Association, ou=People, o=University of Michigan, c=US
127 member: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
128
129 dn: cn=All Staff,ou=Groups,o=University of Michigan,c=US
130 changetype: modify
131 delete: member
132
133 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
134 changetype: add
135 objectclass: top
136 objectclass: person
137 objectclass: OpenLDAPperson
138 cn: Gern Jensen
139 sn: Jensen
140 uid: gjensen
141 title: Chief Investigator, ITD
142 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
143 seealso: cn=All Staff, ou=Groups, o=University of Michigan, c=US
144 drink: Coffee
145 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
146 description: Very odd
147 facsimiletelephonenumber: +1 313 555 7557
148 telephonenumber: +1 313 555 8343
149 mail: gjensen@mailgw.umich.edu
150 homephone: +1 313 555 8844
151
152 dn: ou=Retired, ou=People, o=University of Michigan, c=US
153 changetype: add
154 objectclass: top
155 objectclass: organizationalUnit
156 ou: Retired
157
158 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
159 changetype: add
160 objectclass: top
161 objectclass: person
162 cn: Rosco P. Coltrane
163 sn: Coltrane
164
165 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
166 changetype: modrdn
167 newrdn: cn=Rosco P. Coltrane
168 deleteoldrdn: 1
169 newsuperior: ou=Retired, ou=People, o=University of Michigan, c=US
170
171 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
172 changetype: delete
173
174 EOMODS
175
176 echo "Waiting 15 seconds for slurpd to send changes..."
177 sleep 15
178
179 echo "Using ldapsearch to read all the entries from the master..."
180 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
181         'objectclass=*' > $MASTEROUT 2>&1
182
183 if test $RC != 0 ; then
184         echo "ldapsearch failed ($RC)!"
185         kill -INT $PID $SLAVEPID
186         kill -KILL $SLURPPID
187         exit $RC
188 fi
189
190 echo "Using ldapsearch to read the subtree entries from the master..."
191 $LDAPSEARCH -S "" -b "ou=Groups, $BASEDN" -h localhost -p $PORT \
192         'objectclass=*' > $SUBMASTEROUT 2>&1
193
194 if test $RC != 0 ; then
195         echo "ldapsearch failed ($RC)!"
196         kill -INT $PID $SLAVEPID
197         kill -KILL $SLURPPID
198         exit $RC
199 fi
200
201 echo "Using ldapsearch to read all the entries from the slave..."
202 $LDAPSEARCH -S "" -b "ou=Groups, $BASEDN" -h localhost -p $SLAVEPORT \
203         'objectclass=*' > $SLAVEOUT 2>&1
204
205 if test $RC != 0 ; then
206         echo "ldapsearch failed ($RC)!"
207         kill -INT $PID $SLAVEPID
208         kill -KILL $SLURPPID
209         exit $RC
210 fi
211
212 kill -INT $PID $SLAVEPID
213 kill -KILL $SLURPPID
214
215 SEARCHOUT=$SUBMASTEROUT
216 LDIF=$SLAVEOUT
217
218 echo "Filtering master ldapsearch results..."
219 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
220 echo "Filtering slave ldapsearch results..."
221 . $LDIFFILTER < $LDIF > $LDIFFLT
222
223 echo "Comparing retrieved entries from master and slave..."
224 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
225
226 if test $? != 0 ; then
227         echo "test failed - master and slave databases differ"
228         exit 1
229 fi
230
231 SEARCHOUT=$MASTEROUT
232
233 echo "Filtering remaining data"
234 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
235
236 echo "Stripping slave entries from master output..."
237 $CMP $SEARCHFLT $LDIFFLT | $UNDIFFFILTER > $SUBFLT
238
239 echo "Stripping subtree entries from master output..."
240 . $SUBFILTER 'ou=Groups,[ ]?o=University of Michigan,[ ]?c=US' < $SEARCHOUT \
241         | $UNDIFFFILTER > $SUBFLT2
242
243 echo "Comparing master minus subtree and master minus slave..."
244 $CMP $SUBFLT $SUBFLT2 > $CMPOUT
245
246 if test $? != 0 ; then
247         echo "test failed - master and slave databases differ"
248         exit 1
249 fi
250
251 echo ">>>>> Test succeeded"
252
253 exit 0