]> git.sur5r.net Git - openldap/blob - tests/scripts/test007-replication
A tests for a few allowed oddities
[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 -rf $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         if test $RC = 0 ; then
69                 break
70         fi
71         echo "Waiting 5 seconds for slapd to start..."
72         sleep 5
73 done
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 -HUP $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: description
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.example.com
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 uid: rosco
165
166 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
167 changetype: modrdn
168 newrdn: cn=Rosco P. Coltrane
169 deleteoldrdn: 1
170 newsuperior: ou=Retired, ou=People, o=University of Michigan, c=US
171
172 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
173 changetype: delete
174
175 EOMODS
176
177 echo "Waiting 15 seconds for slurpd to send changes..."
178 sleep 15
179
180 echo "Using ldapsearch to read all the entries from the master..."
181 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT \
182         'objectclass=*' > $MASTEROUT 2>&1
183 RC=$?
184
185 if test $RC != 0 ; then
186         echo "ldapsearch failed ($RC)!"
187         kill -HUP $PID $SLAVEPID
188         kill -KILL $SLURPPID
189         exit $RC
190 fi
191
192 echo "Using ldapsearch to read all the entries from the slave..."
193 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
194         'objectclass=*' > $SLAVEOUT 2>&1
195 RC=$?
196
197 if test $RC != 0 ; then
198         echo "ldapsearch failed ($RC)!"
199         kill -HUP $PID $SLAVEPID
200         kill -KILL $SLURPPID
201         exit $RC
202 fi
203
204 kill -HUP $PID $SLAVEPID
205 kill -KILL $SLURPPID
206
207 SEARCHOUT=$MASTEROUT
208 LDIF=$SLAVEOUT
209
210 echo "Filtering ldapsearch results..."
211 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
212 echo "Filtering original ldif used to create database..."
213 . $LDIFFILTER < $LDIF > $LDIFFLT
214
215 echo "Comparing retrieved entries from master and slave..."
216 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
217
218 if test $? != 0 ; then
219         echo "test failed - master and slave databases differ"
220         exit 1
221 fi
222
223 echo ">>>>> Test succeeded"
224
225
226 exit 0