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