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