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