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