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 $CONF1.d $DBDIR1 $DBDIR2 $CFDIR
     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 echo "Starting the first slapd on TCP/IP port $PORT2..."
     30 . $CONFFILTER $BACKEND < $CONF > $CONF2
     31 $SLAPADD -f $CONF2 -l $LDIFORDERED
     32 RC=$?
     33 if test $RC != 0 ; then
     34     echo "slapadd failed ($RC)!"
     35     exit $RC
     36 fi
     37 
     38 echo "Running slapindex to index slapd database..."
     39 $SLAPINDEX -f $CONF2
     40 RC=$?
     41 if test $RC != 0 ; then
     42     echo "warning: slapindex failed ($RC)"
     43     echo "  assuming no indexing support"
     44 fi
     45 
     46 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
     47 PID=$!
     48 if test $WAIT != 0 ; then
     49     echo PID $PID
     50     read foo
     51 fi
     52 PID2="$PID"
     53 KILLPIDS="$PID"
     54 
     55 echo "Testing slapd searching..."
     56 for i in 0 1 2 3 4 5; do
     57     $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
     58         '(objectclass=*)' > /dev/null 2>&1
     59     RC=$?
     60     if test $RC = 0 ; then
     61         break
     62     fi
     63     echo "Waiting $SLEEP1 seconds for slapd to start..."
     64     sleep $SLEEP1
     65 done
     66 if test $RC != 0 ; then
     67     echo "ldapsearch failed ($RC)!"
     68     test $KILLSERVERS != no && kill -HUP $KILLPIDS
     69     exit $RC
     70 fi
     71 
     72 echo "Running slapadd to build slapd database..."
     73 . $CONFFILTER $BACKEND < $CONFTWO > $CONF3
     74 $SLAPADD -f $CONF3 -l $LDIFORDERED
     75 RC=$?
     76 if test $RC != 0 ; then
     77     echo "slapadd failed ($RC)!"
     78     test $KILLSERVERS != no && kill -HUP $KILLPIDS
     79     exit $RC
     80 fi
     81 
     82 echo "Running slapindex to index slapd database..."
     83 $SLAPINDEX -f $CONF3
     84 RC=$?
     85 if test $RC != 0 ; then
     86     echo "warning: slapindex failed ($RC)"
     87     echo "  assuming no indexing support"
     88 fi
     89 
     90 echo "Starting second slapd on TCP/IP port $PORT3..."
     91 $SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
     92 PID=$!
     93 if test $WAIT != 0 ; then
     94     echo PID $PID
     95     read foo
     96 fi
     97 PID3="$PID"
     98 KILLPIDS="$KILLPIDS $PID"
     99 
    100 sleep $SLEEP0
    101 
    102 echo "Testing slapd searching..."
    103 for i in 0 1 2 3 4 5; do
    104     $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
    105         '(objectclass=*)' > /dev/null 2>&1
    106     RC=$?
    107     if test $RC = 0 ; then
    108         break
    109     fi
    110     echo "Waiting $SLEEP1 seconds for slapd to start..."
    111     sleep $SLEEP1
    112 done
    113 if test $RC != 0 ; then
    114     echo "ldapsearch failed ($RC)!"
    115     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    116     exit $RC
    117 fi
    118 
    119 echo "Starting lloadd on TCP/IP port $PORT1..."
    120 . $CONFFILTER $BACKEND < $LLOADDUNREACHABLECONF > $CONF1.lloadd
    121 . $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
    122 $SLAPD -Tt -f $CONF1.slapd -F $CONF1.d -d $LVL > $LOG1 2>&1
    123 $SLAPD -F $CONF1.d -h $URI6 -d $LVL >> $LOG1 2>&1 &
    124 PID=$!
    125 if test $WAIT != 0 ; then
    126     echo PID $PID
    127     read foo
    128 fi
    129 KILLPIDS="$KILLPIDS $PID"
    130 
    131 echo "Testing lloadd searching..."
    132 for i in 0 1 2 3 4 5; do
    133     $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
    134         '(objectclass=*)' > /dev/null 2>&1
    135     RC=$?
    136     if test $RC = 0 ; then
    137         break
    138     fi
    139     echo "Waiting $SLEEP1 seconds for lloadd to start..."
    140     sleep $SLEEP1
    141 done
    142 
    143 if test $RC != 0 ; then
    144     echo "ldapsearch failed ($RC)!"
    145     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    146     exit $RC
    147 fi
    148 
    149 
    150 echo "Testing cn=config searching..."
    151 $LDAPSEARCH -H $URI6 -D cn=config -y $CONFIGPWF \
    152         -s sub -b "olcBackend={0}lload,cn=config" '(objectclass=*)'  > /dev/null 2>&1
    153 RC=$?
    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 "Deleting backends"
    161 
    162 # weighted backends are sorted before we get to _cfadd to create their entries
    163 for i in 3 2 4 1 ; do
    164     echo "cn={0}server $i,cn={1}tier 2,olcBackend={0}lload,cn=config"
    165     $LDAPDELETE -H $URI6 -D cn=config -y $CONFIGPWF \
    166     "cn={0}server $i,cn={1}tier 2,olcBackend={0}lload,cn=config" > /dev/null 2>&1
    167     RC=$?
    168     if test $RC != 0 ; then
    169            echo "deleting server failed ($RC)!"
    170            test $KILLSERVERS != no && kill -HUP $KILLPIDS
    171            exit $RC
    172     fi
    173 done
    174 
    175 echo "Testing cn=config searching..."
    176 $LDAPSEARCH -H $URI6 -D cn=config -y $CONFIGPWF \
    177         -s sub -b "olcBackend={0}lload,cn=config" '(objectclass=*)' > /dev/null 2>&1
    178 
    179 echo "Deleting tiers"
    180 
    181 for i in 1 2; do
    182     echo "cn={0}tier $i,olcBackend={0}lload,cn=config"
    183     $LDAPDELETE -H $URI6 -D cn=config -y $CONFIGPWF \
    184     "cn={0}tier $i,olcBackend={0}lload,cn=config" > /dev/null 2>&1
    185     RC=$?
    186     if test $RC != 0 ; then
    187            echo "deleting server failed ($RC)!"
    188            test $KILLSERVERS != no && kill -HUP $KILLPIDS
    189            exit $RC
    190     fi
    191 done
    192 
    193 echo "Testing cn=config searching..."
    194 $LDAPSEARCH -H $URI6 -D cn=config -y $CONFIGPWF \
    195         -s sub -b "olcBackend={0}lload,cn=config" '(objectclass=*)' > /dev/null 2>&1
    196 
    197 
    198 echo "# Testing exact searching..."
    199 
    200 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    201     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    202 RC=$?
    203 if test $RC != 52 ; then
    204     echo "ldapsearch failed ($RC)!"
    205     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    206     exit $RC
    207 fi
    208 
    209 echo "Testing adding a tier"
    210 $LDAPADD -D cn=config -H $URI6 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
    211 dn: cn=roundrobin tier,olcBackend={0}lload,cn=config
    212 objectClass: olcBkLloadTierConfig
    213 olcBkLloadTierType: roundrobin
    214 EOF
    215 RC=$?
    216 if test $RC != 0 ; then
    217     echo "ldapadd failed for cn=roundrobin tier ($RC)!"
    218     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    219     exit $RC
    220 fi
    221 
    222 echo "Testing adding a weighted tier"
    223 $LDAPADD -D cn=config -H $URI6 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
    224 dn: cn=weighted tier,olcBackend={0}lload,cn=config
    225 objectClass: olcBkLloadTierConfig
    226 olcBkLloadTierType: weighted
    227 EOF
    228 RC=$?
    229 if test $RC != 0 ; then
    230     echo "ldapadd failed for cn=weighted tier ($RC)!"
    231     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    232     exit $RC
    233 fi
    234 
    235 echo "Testing adding a backend server"
    236 $LDAPADD -D cn=config -H $URI6 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
    237 dn: cn=server 7,cn={1}weighted tier,olcBackend={0}lload,cn=config
    238 objectClass: olcBkLloadBackendConfig
    239 cn: server 7
    240 olcBkLloadBackendUri: $URI3
    241 olcBkLloadBindconns: 2
    242 olcBkLloadMaxPendingConns: 3
    243 olcBkLloadMaxPendingOps: 5
    244 olcBkLloadNumconns: 3
    245 olcBkLloadRetry: 5000
    246 olcBkLloadWeight: 10
    247 EOF
    248 RC=$?
    249 if test $RC != 0 ; then
    250     echo "ldapadd failed for cn=server 7 ($RC)!"
    251     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    252     exit $RC
    253 fi
    254 
    255 echo "Verifying balancer operation..."
    256 for i in 0 1 2 3 4 5; do
    257     $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    258     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    259     RC=$?
    260     if test $RC = 0 ; then
    261         break
    262     fi
    263     echo "Waiting $SLEEP1 seconds for backend to start..."
    264     sleep $SLEEP1
    265 done
    266 
    267 echo "Testing bindconf modify"
    268 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    269 dn: olcBackend={0}lload,cn=config
    270 changetype: modify
    271 replace: olcBkLloadBindconf
    272 olcBkLloadBindconf: bindmethod=simple timeout=0 network-timeout=0 binddn="cn=wrongmanager,dc=example,dc=com" credentials="secret"
    273 EOF
    274 
    275 RC=$?
    276 if test $RC != 0 ; then
    277     echo "modify failed for bindconf ($RC)!"
    278     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    279     exit $RC
    280 fi
    281 
    282 echo "# Sending a search request..."
    283 
    284 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    285     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    286 RC=$?
    287 if test $RC != 52 ; then
    288     echo "ldapsearch failed ($RC)!"
    289     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    290     exit $RC
    291 fi
    292 
    293 echo "Restoring bindconf value"
    294 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    295 dn: olcBackend={0}lload,cn=config
    296 changetype: modify
    297 replace: olcBkLloadBindconf
    298 olcBkLloadBindconf: bindmethod=simple timeout=0 network-timeout=0 binddn="cn=Manager,dc=example,dc=com" credentials="secret"
    299 EOF
    300 
    301 RC=$?
    302 if test $RC != 0 ; then
    303     echo "modify failed for bindconf ($RC)!"
    304     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    305     exit $RC
    306 fi
    307 
    308 
    309 echo "Verifying balancer operation..."
    310 for i in 0 1 2 3 4 5; do
    311     $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    312     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    313     RC=$?
    314     if test $RC = 0 ; then
    315         break
    316     fi
    317     echo "Waiting $SLEEP1 seconds for backend to start..."
    318     sleep $SLEEP1
    319 done
    320 
    321 echo "Testing global attributes"
    322 echo "Testing olcBkLloadMaxPDUPerCycle modify"
    323 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    324 dn: olcBackend={0}lload,cn=config
    325 changetype: modify
    326 replace: olcBkLloadMaxPDUPerCycle
    327 olcBkLloadMaxPDUPerCycle: 0
    328 EOF
    329 
    330 RC=$?
    331 if test $RC != 0 ; then
    332     echo "modify failed for olcBkLloadMaxPDUPerCycle($RC)!"
    333     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    334     exit $RC
    335 fi
    336 
    337 echo "Sending a search request..."
    338 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    339     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    340 RC=$?
    341 if test $RC != 0 ; then
    342     echo "ldapsearch failed ($RC)!"
    343     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    344     exit $RC
    345 fi
    346 
    347 echo "Testing olcBkLloadSockbufMaxClient modify"
    348 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    349 dn: olcBackend={0}lload,cn=config
    350 changetype: modify
    351 replace: olcBkLloadSockbufMaxClient
    352 olcBkLloadSockbufMaxClient: 20000
    353 EOF
    354 
    355 RC=$?
    356 if test $RC != 0 ; then
    357     echo "modify failed for olcBkLloadSockbufMaxClient($RC)!"
    358     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    359     exit $RC
    360 fi
    361 
    362 echo "Sending a search request..."
    363 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    364     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    365 RC=$?
    366 if test $RC != 0 ; then
    367     echo "ldapsearch failed ($RC)!"
    368     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    369     exit $RC
    370 fi
    371 
    372 echo "Testing olcBkLloadSockbufMaxUpstream modify"
    373 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    374 dn: olcBackend={0}lload,cn=config
    375 changetype: modify
    376 replace: olcBkLloadSockbufMaxUpstream
    377 olcBkLloadSockbufMaxUpstream: 200000
    378 EOF
    379 
    380 RC=$?
    381 if test $RC != 0 ; then
    382     echo "modify failed for olcBkLloadSockbufMaxUpstream($RC)!"
    383     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    384     exit $RC
    385 fi
    386 
    387 echo "Sending a search request..."
    388 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    389     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    390 RC=$?
    391 if test $RC != 0 ; then
    392     echo "ldapsearch failed ($RC)!"
    393     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    394     exit $RC
    395 fi
    396 
    397 echo "Testing olcBkLloadIOTimeout modify"
    398 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    399 dn: olcBackend={0}lload,cn=config
    400 changetype: modify
    401 replace: olcBkLloadIOTimeout
    402 olcBkLloadIOTimeout: 20000
    403 EOF
    404 
    405 RC=$?
    406 if test $RC != 0 ; then
    407     echo "modify failed for olcBkLloadWriteTimeout($RC)!"
    408     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    409     exit $RC
    410 fi
    411 
    412 echo "Sending a search request..."
    413 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    414     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    415 RC=$?
    416 if test $RC != 0 ; then
    417     echo "ldapsearch failed ($RC)!"
    418     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    419     exit $RC
    420 fi
    421 
    422 echo "Testing backend attributes"
    423 echo "Testing olcBkLloadBindconns modify"
    424 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    425 dn: cn={0}server 7,cn={1}weighted tier,olcBackend={0}lload,cn=config
    426 changetype: modify
    427 replace: olcBkLloadBindconns
    428 olcBkLloadBindconns: 20
    429 EOF
    430 
    431 RC=$?
    432 if test $RC != 0 ; then
    433     echo "modify failed for olcBkLloadBindconns($RC)!"
    434     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    435     exit $RC
    436 fi
    437 
    438 echo "Testing exact searching..."
    439 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    440     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    441 RC=$?
    442 if test $RC != 0 ; then
    443     echo "ldapsearch failed ($RC)!"
    444     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    445     exit $RC
    446 fi
    447 
    448 
    449 echo "Testing olcBkLloadMaxPendingConns modify"
    450 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    451 dn: cn={0}server 7,cn={1}weighted tier,olcBackend={0}lload,cn=config
    452 changetype: modify
    453 replace: olcBkLloadMaxPendingConns
    454 olcBkLloadMaxPendingConns: 30
    455 EOF
    456 
    457 RC=$?
    458 if test $RC != 0 ; then
    459     echo "modify failed for olcBkLloadMaxPendingConns($RC)!"
    460     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    461     exit $RC
    462 fi
    463 
    464 echo "Testing exact searching..."
    465 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    466     '(sn=jENSEN)' >> $SEARCHOUT 2>&1
    467 RC=$?
    468 if test $RC != 0 ; then
    469     echo "ldapsearch failed ($RC)!"
    470     test $KILLSERVERS != no && kill -HUP $KILLPIDS
    471     exit $RC
    472 fi
    473 
    474 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    475 
    476 
    477 echo ">>>>> Test succeeded"
    478 
    479 test $KILLSERVERS != no && wait
    480 
    481 exit 0
    482