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