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