xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/lloadd/test004-monitor (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos# $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos
16*e670fd5cSchristosecho "running defines.sh"
17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
18*e670fd5cSchristos
19*e670fd5cSchristosmkdir -p $TESTDIR $DBDIR1 $DBDIR2
20*e670fd5cSchristos
21*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF
22*e670fd5cSchristosecho "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
23*e670fd5cSchristos
24*e670fd5cSchristosif test $AC_lloadd = lloaddyes ; then
25*e670fd5cSchristos    echo "Load balancer module not available, skipping..."
26*e670fd5cSchristos    exit 0
27*e670fd5cSchristosfi
28*e670fd5cSchristos
29*e670fd5cSchristos# Monitor counts are unstable in the face of concurrency, since different
30*e670fd5cSchristos# clients may get different upstreams assigned for their operations. This might
31*e670fd5cSchristos# also change later when tiered load balancing is available.
32*e670fd5cSchristos# Another constraint is that some global counts are updated by the statistics
33*e670fd5cSchristos# collection task scheduled to run every second.
34*e670fd5cSchristos#
35*e670fd5cSchristos# This test assumes current round-robin policy:
36*e670fd5cSchristos# - default backend is rotated every time we successfully pick an upstream
37*e670fd5cSchristos# - upstream connections within the same backend are rotated in the same way
38*e670fd5cSchristos# - the monitor entry order for upstream connections reflects the connection
39*e670fd5cSchristos#   order within its CIRCLEQ_
40*e670fd5cSchristos
41*e670fd5cSchristosecho "Starting the first slapd on TCP/IP port $PORT2..."
42*e670fd5cSchristos. $CONFFILTER $BACKEND < $CONF > $CONF2
43*e670fd5cSchristos$SLAPADD -f $CONF2 -l $LDIFORDERED
44*e670fd5cSchristosRC=$?
45*e670fd5cSchristosif test $RC != 0 ; then
46*e670fd5cSchristos    echo "slapadd failed ($RC)!"
47*e670fd5cSchristos    exit $RC
48*e670fd5cSchristosfi
49*e670fd5cSchristos
50*e670fd5cSchristosecho "Running slapindex to index slapd database..."
51*e670fd5cSchristos$SLAPINDEX -f $CONF2
52*e670fd5cSchristosRC=$?
53*e670fd5cSchristosif test $RC != 0 ; then
54*e670fd5cSchristos    echo "warning: slapindex failed ($RC)"
55*e670fd5cSchristos    echo "  assuming no indexing support"
56*e670fd5cSchristosfi
57*e670fd5cSchristos
58*e670fd5cSchristos$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
59*e670fd5cSchristosPID=$!
60*e670fd5cSchristosif test $WAIT != 0 ; then
61*e670fd5cSchristos    echo PID $PID
62*e670fd5cSchristos    read foo
63*e670fd5cSchristosfi
64*e670fd5cSchristosPID2="$PID"
65*e670fd5cSchristosKILLPIDS="$PID"
66*e670fd5cSchristos
67*e670fd5cSchristosecho "Testing slapd searching..."
68*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
69*e670fd5cSchristos    $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
70*e670fd5cSchristos        '(objectclass=*)' > /dev/null 2>&1
71*e670fd5cSchristos    RC=$?
72*e670fd5cSchristos    if test $RC = 0 ; then
73*e670fd5cSchristos        break
74*e670fd5cSchristos    fi
75*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds for slapd to start..."
76*e670fd5cSchristos    sleep $SLEEP1
77*e670fd5cSchristosdone
78*e670fd5cSchristosif test $RC != 0 ; then
79*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
80*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
81*e670fd5cSchristos    exit $RC
82*e670fd5cSchristosfi
83*e670fd5cSchristos
84*e670fd5cSchristosecho "Running slapadd to build slapd database..."
85*e670fd5cSchristos. $CONFFILTER $BACKEND < $CONFTWO > $CONF3
86*e670fd5cSchristos$SLAPADD -f $CONF3 -l $LDIFORDERED
87*e670fd5cSchristosRC=$?
88*e670fd5cSchristosif test $RC != 0 ; then
89*e670fd5cSchristos    echo "slapadd failed ($RC)!"
90*e670fd5cSchristos    exit $RC
91*e670fd5cSchristosfi
92*e670fd5cSchristos
93*e670fd5cSchristosecho "Running slapindex to index slapd database..."
94*e670fd5cSchristos$SLAPINDEX -f $CONF3
95*e670fd5cSchristosRC=$?
96*e670fd5cSchristosif test $RC != 0 ; then
97*e670fd5cSchristos    echo "warning: slapindex failed ($RC)"
98*e670fd5cSchristos    echo "  assuming no indexing support"
99*e670fd5cSchristosfi
100*e670fd5cSchristos
101*e670fd5cSchristosecho "Starting second slapd on TCP/IP port $PORT3..."
102*e670fd5cSchristos$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
103*e670fd5cSchristosPID=$!
104*e670fd5cSchristosif test $WAIT != 0 ; then
105*e670fd5cSchristos    echo PID $PID
106*e670fd5cSchristos    read foo
107*e670fd5cSchristosfi
108*e670fd5cSchristosPID3="$PID"
109*e670fd5cSchristosKILLPIDS="$KILLPIDS $PID"
110*e670fd5cSchristos
111*e670fd5cSchristossleep $SLEEP0
112*e670fd5cSchristos
113*e670fd5cSchristosecho "Testing slapd searching..."
114*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
115*e670fd5cSchristos    $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
116*e670fd5cSchristos        '(objectclass=*)' > /dev/null 2>&1
117*e670fd5cSchristos    RC=$?
118*e670fd5cSchristos    if test $RC = 0 ; then
119*e670fd5cSchristos        break
120*e670fd5cSchristos    fi
121*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds for slapd to start..."
122*e670fd5cSchristos    sleep $SLEEP1
123*e670fd5cSchristosdone
124*e670fd5cSchristosif test $RC != 0 ; then
125*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
126*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
127*e670fd5cSchristos    exit $RC
128*e670fd5cSchristosfi
129*e670fd5cSchristos
130*e670fd5cSchristosecho "Starting lloadd on TCP/IP port $PORT1..."
131*e670fd5cSchristos. $CONFFILTER $BACKEND < $LLOADDEMPTYCONF > $CONF1.lloadd
132*e670fd5cSchristos. $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
133*e670fd5cSchristos$SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 &
134*e670fd5cSchristosPID=$!
135*e670fd5cSchristosif test $WAIT != 0 ; then
136*e670fd5cSchristos    echo PID $PID
137*e670fd5cSchristos    read foo
138*e670fd5cSchristosfi
139*e670fd5cSchristosKILLPIDS="$KILLPIDS $PID"
140*e670fd5cSchristos
141*e670fd5cSchristosecho "Testing slapd searching..."
142*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
143*e670fd5cSchristos    $LDAPSEARCH -s base -b "$MONITOR" -H $URI6 \
144*e670fd5cSchristos        '(objectclass=*)' > /dev/null 2>&1
145*e670fd5cSchristos    RC=$?
146*e670fd5cSchristos    if test $RC = 0 ; then
147*e670fd5cSchristos        break
148*e670fd5cSchristos    fi
149*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds for lloadd to start..."
150*e670fd5cSchristos    sleep $SLEEP1
151*e670fd5cSchristosdone
152*e670fd5cSchristos
153*e670fd5cSchristosif test $RC != 0 ; then
154*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
155*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
156*e670fd5cSchristos    exit $RC
157*e670fd5cSchristosfi
158*e670fd5cSchristos
159*e670fd5cSchristosecho "Sending a search request to prime the counters..."
160*e670fd5cSchristos$LDAPSEARCH -b "$BASEDN" -s base -H $URI1 >> $TESTOUT 2>&1
161*e670fd5cSchristosRC=$?
162*e670fd5cSchristosif test $RC != 52 ; then
163*e670fd5cSchristos    echo "ldapsearch should have failed ($RC != 52)!"
164*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
165*e670fd5cSchristos    exit $RC
166*e670fd5cSchristosfi
167*e670fd5cSchristos
168*e670fd5cSchristosecho "Retrieving data from cn=monitor..."
169*e670fd5cSchristosecho "# Retrieving data from an empty lload's cn=monitor..." >>$SEARCHOUT
170*e670fd5cSchristosecho "# Operations received:" >>$SEARCHOUT
171*e670fd5cSchristosecho "#     Bind: 1 (0 forwarded)" >>$SEARCHOUT
172*e670fd5cSchristosecho "#     Search: 0" >>$SEARCHOUT
173*e670fd5cSchristosecho "#     Unbind: 1" >>$SEARCHOUT
174*e670fd5cSchristos$LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \
175*e670fd5cSchristos    olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1
176*e670fd5cSchristosRC=$?
177*e670fd5cSchristosif test $RC != 0 ; then
178*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
179*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
180*e670fd5cSchristos    exit $RC
181*e670fd5cSchristosfi
182*e670fd5cSchristos
183*e670fd5cSchristosecho "Adding first backend server..."
184*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
185*e670fd5cSchristosdn: cn=first,olcBackend={0}lload,cn=config
186*e670fd5cSchristoschangetype: add
187*e670fd5cSchristosobjectClass: olcBkLloadBackendConfig
188*e670fd5cSchristosolcBkLloadBackendUri: $URI2
189*e670fd5cSchristosolcBkLloadMaxPendingConns: 3
190*e670fd5cSchristosolcBkLloadMaxPendingOps: 5
191*e670fd5cSchristosolcBkLloadRetry: 1000
192*e670fd5cSchristosolcBkLloadNumconns: 2
193*e670fd5cSchristosolcBkLloadBindconns: 2
194*e670fd5cSchristosEOF
195*e670fd5cSchristosRC=$?
196*e670fd5cSchristosif test $RC != 0 ; then
197*e670fd5cSchristos    echo "ldapadd failed for backend ($RC)!"
198*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
199*e670fd5cSchristos    exit $RC
200*e670fd5cSchristosfi
201*e670fd5cSchristos
202*e670fd5cSchristos# At the moment, the global counters are updated by a recurring job,
203*e670fd5cSchristos# wait for it to settle
204*e670fd5cSchristosecho "Waiting until connections are established..."
205*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
206*e670fd5cSchristos    $LDAPCOMPARE "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \
207*e670fd5cSchristos        'olmOutgoingConnections:4' > /dev/null 2>&1
208*e670fd5cSchristos    RC=$?
209*e670fd5cSchristos    if test $RC = 6 ; then
210*e670fd5cSchristos        break
211*e670fd5cSchristos    fi
212*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds until connections are established..."
213*e670fd5cSchristos    sleep $SLEEP1
214*e670fd5cSchristosdone
215*e670fd5cSchristosif test $RC != 6 ; then
216*e670fd5cSchristos    echo "ldapcompare failed ($RC)!"
217*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
218*e670fd5cSchristos    exit $RC
219*e670fd5cSchristosfi
220*e670fd5cSchristos
221*e670fd5cSchristosecho "Retrieving data from cn=monitor again..."
222*e670fd5cSchristosecho >>$SEARCHOUT
223*e670fd5cSchristosecho "# Retrieving data from lload's cn=monitor..." >>$SEARCHOUT
224*e670fd5cSchristos$LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \
225*e670fd5cSchristos    olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1
226*e670fd5cSchristosRC=$?
227*e670fd5cSchristosif test $RC != 0 ; then
228*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
229*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
230*e670fd5cSchristos    exit $RC
231*e670fd5cSchristosfi
232*e670fd5cSchristos
233*e670fd5cSchristosecho "Adding another backend server..."
234*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
235*e670fd5cSchristosdn: cn=server 2,olcBackend={0}lload,cn=config
236*e670fd5cSchristoschangetype: add
237*e670fd5cSchristosobjectClass: olcBkLloadBackendConfig
238*e670fd5cSchristosolcBkLloadBackendUri: $URI3
239*e670fd5cSchristosolcBkLloadMaxPendingConns: 3
240*e670fd5cSchristosolcBkLloadMaxPendingOps: 5
241*e670fd5cSchristosolcBkLloadRetry: 1000
242*e670fd5cSchristosolcBkLloadNumconns: 4
243*e670fd5cSchristosolcBkLloadBindconns: 5
244*e670fd5cSchristosEOF
245*e670fd5cSchristosRC=$?
246*e670fd5cSchristosif test $RC != 0 ; then
247*e670fd5cSchristos    echo "ldapadd failed for backend ($RC)!"
248*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
249*e670fd5cSchristos    exit $RC
250*e670fd5cSchristosfi
251*e670fd5cSchristos
252*e670fd5cSchristos# At the moment, the global counters are updated by a recurring job,
253*e670fd5cSchristos# wait for it to settle
254*e670fd5cSchristosecho "Waiting until connections are established..."
255*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
256*e670fd5cSchristos    $LDAPCOMPARE "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \
257*e670fd5cSchristos        'olmOutgoingConnections:13' > /dev/null 2>&1
258*e670fd5cSchristos    RC=$?
259*e670fd5cSchristos    if test $RC = 6 ; then
260*e670fd5cSchristos        break
261*e670fd5cSchristos    fi
262*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds until connections are established..."
263*e670fd5cSchristos    sleep $SLEEP1
264*e670fd5cSchristosdone
265*e670fd5cSchristosif test $RC != 6 ; then
266*e670fd5cSchristos    echo "ldapcompare failed ($RC)!"
267*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
268*e670fd5cSchristos    exit $RC
269*e670fd5cSchristosfi
270*e670fd5cSchristos
271*e670fd5cSchristosecho "Sending another search request..."
272*e670fd5cSchristos$LDAPSEARCH -b "$BASEDN" -s base -H $URI1 >> $TESTOUT 2>&1
273*e670fd5cSchristosRC=$?
274*e670fd5cSchristosif test $RC != 0 ; then
275*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
276*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
277*e670fd5cSchristos    exit $RC
278*e670fd5cSchristosfi
279*e670fd5cSchristos
280*e670fd5cSchristosecho "Sending a WhoAmI? request..."
281*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -w bjensen -H $URI1 >> $TESTOUT 2>&1
282*e670fd5cSchristosRC=$?
283*e670fd5cSchristosif test $RC != 0 ; then
284*e670fd5cSchristos    echo "ldapwhoami failed ($RC)!"
285*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
286*e670fd5cSchristos    exit $RC
287*e670fd5cSchristosfi
288*e670fd5cSchristos
289*e670fd5cSchristos# At the moment, the global counters are updated by a recurring job,
290*e670fd5cSchristos# wait for it to settle
291*e670fd5cSchristosecho "Waiting until global counters are updated..."
292*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
293*e670fd5cSchristos    $LDAPCOMPARE "cn=Other,cn=Operations,cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \
294*e670fd5cSchristos        'olmCompletedOps:2' > /dev/null 2>&1
295*e670fd5cSchristos    RC=$?
296*e670fd5cSchristos    if test $RC = 6 ; then
297*e670fd5cSchristos        break
298*e670fd5cSchristos    fi
299*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds until connections are established..."
300*e670fd5cSchristos    sleep $SLEEP1
301*e670fd5cSchristosdone
302*e670fd5cSchristosif test $RC != 6 ; then
303*e670fd5cSchristos    echo "ldapcompare failed ($RC)!"
304*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
305*e670fd5cSchristos    exit $RC
306*e670fd5cSchristosfi
307*e670fd5cSchristos
308*e670fd5cSchristosecho "Retrieving data from cn=monitor again..."
309*e670fd5cSchristosecho >>$SEARCHOUT
310*e670fd5cSchristosecho "# Retrieving data after a search+WhoAmI?..." >>$SEARCHOUT
311*e670fd5cSchristosecho "# Operations received:" >>$SEARCHOUT
312*e670fd5cSchristosecho "#     Bind: 3 (2 forwarded)" >>$SEARCHOUT
313*e670fd5cSchristosecho "#     Search: 1" >>$SEARCHOUT
314*e670fd5cSchristosecho "#     Extended: 1 (WhoAmI?)" >>$SEARCHOUT
315*e670fd5cSchristosecho "#     Unbind: 3" >>$SEARCHOUT
316*e670fd5cSchristos$LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \
317*e670fd5cSchristos    olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1
318*e670fd5cSchristosRC=$?
319*e670fd5cSchristosif test $RC != 0 ; then
320*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
321*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
322*e670fd5cSchristos    exit $RC
323*e670fd5cSchristosfi
324*e670fd5cSchristos
325*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
326*e670fd5cSchristos
327*e670fd5cSchristosLDIF=$DATADIR/lloadd/monitor.ldif
328*e670fd5cSchristos
329*e670fd5cSchristosecho "Filtering ldapsearch results..."
330*e670fd5cSchristos$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
331*e670fd5cSchristosecho "Filtering original ldif used to create database..."
332*e670fd5cSchristos$LDIFFILTER < $LDIF > $LDIFFLT
333*e670fd5cSchristosecho "Comparing filter output..."
334*e670fd5cSchristos$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
335*e670fd5cSchristos
336*e670fd5cSchristosif test $? != 0 ; then
337*e670fd5cSchristos    echo "Comparison failed"
338*e670fd5cSchristos    exit 1
339*e670fd5cSchristosfi
340*e670fd5cSchristos
341*e670fd5cSchristosecho ">>>>> Test succeeded"
342*e670fd5cSchristos
343*e670fd5cSchristostest $KILLSERVERS != no && wait
344*e670fd5cSchristos
345*e670fd5cSchristosexit 0
346