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