1#! /bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2021 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 16echo "running defines.sh" 17. $SRCDIR/scripts/defines.sh 18 19mkdir -p $TESTDIR $DBDIR1 $DBDIR2 20 21$SLAPPASSWD -g -n >$CONFIGPWF 22echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf 23 24if test $AC_lloadd = lloaddyes ; then 25 echo "Load balancer module not available, skipping..." 26 exit 0 27fi 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 41echo "Starting the first slapd on TCP/IP port $PORT2..." 42. $CONFFILTER $BACKEND < $CONF > $CONF2 43$SLAPADD -f $CONF2 -l $LDIFORDERED 44RC=$? 45if test $RC != 0 ; then 46 echo "slapadd failed ($RC)!" 47 exit $RC 48fi 49 50echo "Running slapindex to index slapd database..." 51$SLAPINDEX -f $CONF2 52RC=$? 53if test $RC != 0 ; then 54 echo "warning: slapindex failed ($RC)" 55 echo " assuming no indexing support" 56fi 57 58$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 & 59PID=$! 60if test $WAIT != 0 ; then 61 echo PID $PID 62 read foo 63fi 64PID2="$PID" 65KILLPIDS="$PID" 66 67echo "Testing slapd searching..." 68for 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 77done 78if test $RC != 0 ; then 79 echo "ldapsearch failed ($RC)!" 80 test $KILLSERVERS != no && kill -HUP $KILLPIDS 81 exit $RC 82fi 83 84echo "Running slapadd to build slapd database..." 85. $CONFFILTER $BACKEND < $CONFTWO > $CONF3 86$SLAPADD -f $CONF3 -l $LDIFORDERED 87RC=$? 88if test $RC != 0 ; then 89 echo "slapadd failed ($RC)!" 90 exit $RC 91fi 92 93echo "Running slapindex to index slapd database..." 94$SLAPINDEX -f $CONF3 95RC=$? 96if test $RC != 0 ; then 97 echo "warning: slapindex failed ($RC)" 98 echo " assuming no indexing support" 99fi 100 101echo "Starting second slapd on TCP/IP port $PORT3..." 102$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 & 103PID=$! 104if test $WAIT != 0 ; then 105 echo PID $PID 106 read foo 107fi 108PID3="$PID" 109KILLPIDS="$KILLPIDS $PID" 110 111sleep $SLEEP0 112 113echo "Testing slapd searching..." 114for i in 0 1 2 3 4 5; do 115 $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \ 116 '(objectclass=*)' > /dev/null 2>&1 117 RC=$? 118 if test $RC = 0 ; then 119 break 120 fi 121 echo "Waiting $SLEEP1 seconds for slapd to start..." 122 sleep $SLEEP1 123done 124if test $RC != 0 ; then 125 echo "ldapsearch failed ($RC)!" 126 test $KILLSERVERS != no && kill -HUP $KILLPIDS 127 exit $RC 128fi 129 130echo "Starting lloadd on TCP/IP port $PORT1..." 131. $CONFFILTER $BACKEND < $LLOADDEMPTYCONF > $CONF1.lloadd 132. $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd 133$SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 & 134PID=$! 135if test $WAIT != 0 ; then 136 echo PID $PID 137 read foo 138fi 139KILLPIDS="$KILLPIDS $PID" 140 141echo "Testing slapd searching..." 142for i in 0 1 2 3 4 5; do 143 $LDAPSEARCH -s base -b "$MONITOR" -H $URI6 \ 144 '(objectclass=*)' > /dev/null 2>&1 145 RC=$? 146 if test $RC = 0 ; then 147 break 148 fi 149 echo "Waiting $SLEEP1 seconds for lloadd to start..." 150 sleep $SLEEP1 151done 152 153if test $RC != 0 ; then 154 echo "ldapsearch failed ($RC)!" 155 test $KILLSERVERS != no && kill -HUP $KILLPIDS 156 exit $RC 157fi 158 159echo "Sending a search request to prime the counters..." 160$LDAPSEARCH -b "$BASEDN" -s base -H $URI1 >> $TESTOUT 2>&1 161RC=$? 162if test $RC != 52 ; then 163 echo "ldapsearch should have failed ($RC != 52)!" 164 test $KILLSERVERS != no && kill -HUP $KILLPIDS 165 exit $RC 166fi 167 168echo "Retrieving data from cn=monitor..." 169echo "# Retrieving data from an empty lload's cn=monitor..." >>$SEARCHOUT 170echo "# Operations received:" >>$SEARCHOUT 171echo "# Bind: 1 (0 forwarded)" >>$SEARCHOUT 172echo "# Search: 0" >>$SEARCHOUT 173echo "# Unbind: 1" >>$SEARCHOUT 174$LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ 175 olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1 176RC=$? 177if test $RC != 0 ; then 178 echo "ldapsearch failed ($RC)!" 179 test $KILLSERVERS != no && kill -HUP $KILLPIDS 180 exit $RC 181fi 182 183echo "Adding first backend server..." 184$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 185dn: cn=first,olcBackend={0}lload,cn=config 186changetype: add 187objectClass: olcBkLloadBackendConfig 188olcBkLloadBackendUri: $URI2 189olcBkLloadMaxPendingConns: 3 190olcBkLloadMaxPendingOps: 5 191olcBkLloadRetry: 1000 192olcBkLloadNumconns: 2 193olcBkLloadBindconns: 2 194EOF 195RC=$? 196if test $RC != 0 ; then 197 echo "ldapadd failed for backend ($RC)!" 198 test $KILLSERVERS != no && kill -HUP $KILLPIDS 199 exit $RC 200fi 201 202# At the moment, the global counters are updated by a recurring job, 203# wait for it to settle 204echo "Waiting until connections are established..." 205for i in 0 1 2 3 4 5; do 206 $LDAPCOMPARE "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ 207 'olmOutgoingConnections:4' > /dev/null 2>&1 208 RC=$? 209 if test $RC = 6 ; then 210 break 211 fi 212 echo "Waiting $SLEEP1 seconds until connections are established..." 213 sleep $SLEEP1 214done 215if test $RC != 6 ; then 216 echo "ldapcompare failed ($RC)!" 217 test $KILLSERVERS != no && kill -HUP $KILLPIDS 218 exit $RC 219fi 220 221echo "Retrieving data from cn=monitor again..." 222echo >>$SEARCHOUT 223echo "# Retrieving data from lload's cn=monitor..." >>$SEARCHOUT 224$LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ 225 olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1 226RC=$? 227if test $RC != 0 ; then 228 echo "ldapsearch failed ($RC)!" 229 test $KILLSERVERS != no && kill -HUP $KILLPIDS 230 exit $RC 231fi 232 233echo "Adding another backend server..." 234$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 235dn: cn=server 2,olcBackend={0}lload,cn=config 236changetype: add 237objectClass: olcBkLloadBackendConfig 238olcBkLloadBackendUri: $URI3 239olcBkLloadMaxPendingConns: 3 240olcBkLloadMaxPendingOps: 5 241olcBkLloadRetry: 1000 242olcBkLloadNumconns: 4 243olcBkLloadBindconns: 5 244EOF 245RC=$? 246if test $RC != 0 ; then 247 echo "ldapadd failed for backend ($RC)!" 248 test $KILLSERVERS != no && kill -HUP $KILLPIDS 249 exit $RC 250fi 251 252# At the moment, the global counters are updated by a recurring job, 253# wait for it to settle 254echo "Waiting until connections are established..." 255for i in 0 1 2 3 4 5; do 256 $LDAPCOMPARE "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ 257 'olmOutgoingConnections:13' > /dev/null 2>&1 258 RC=$? 259 if test $RC = 6 ; then 260 break 261 fi 262 echo "Waiting $SLEEP1 seconds until connections are established..." 263 sleep $SLEEP1 264done 265if test $RC != 6 ; then 266 echo "ldapcompare failed ($RC)!" 267 test $KILLSERVERS != no && kill -HUP $KILLPIDS 268 exit $RC 269fi 270 271echo "Sending another search request..." 272$LDAPSEARCH -b "$BASEDN" -s base -H $URI1 >> $TESTOUT 2>&1 273RC=$? 274if test $RC != 0 ; then 275 echo "ldapsearch failed ($RC)!" 276 test $KILLSERVERS != no && kill -HUP $KILLPIDS 277 exit $RC 278fi 279 280echo "Sending a WhoAmI? request..." 281$LDAPWHOAMI -D "$BABSDN" -w bjensen -H $URI1 >> $TESTOUT 2>&1 282RC=$? 283if test $RC != 0 ; then 284 echo "ldapwhoami failed ($RC)!" 285 test $KILLSERVERS != no && kill -HUP $KILLPIDS 286 exit $RC 287fi 288 289# At the moment, the global counters are updated by a recurring job, 290# wait for it to settle 291echo "Waiting until global counters are updated..." 292for i in 0 1 2 3 4 5; do 293 $LDAPCOMPARE "cn=Other,cn=Operations,cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ 294 'olmCompletedOps:2' > /dev/null 2>&1 295 RC=$? 296 if test $RC = 6 ; then 297 break 298 fi 299 echo "Waiting $SLEEP1 seconds until connections are established..." 300 sleep $SLEEP1 301done 302if test $RC != 6 ; then 303 echo "ldapcompare failed ($RC)!" 304 test $KILLSERVERS != no && kill -HUP $KILLPIDS 305 exit $RC 306fi 307 308echo "Retrieving data from cn=monitor again..." 309echo >>$SEARCHOUT 310echo "# Retrieving data after a search+WhoAmI?..." >>$SEARCHOUT 311echo "# Operations received:" >>$SEARCHOUT 312echo "# Bind: 3 (2 forwarded)" >>$SEARCHOUT 313echo "# Search: 1" >>$SEARCHOUT 314echo "# Extended: 1 (WhoAmI?)" >>$SEARCHOUT 315echo "# Unbind: 3" >>$SEARCHOUT 316$LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ 317 olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1 318RC=$? 319if test $RC != 0 ; then 320 echo "ldapsearch failed ($RC)!" 321 test $KILLSERVERS != no && kill -HUP $KILLPIDS 322 exit $RC 323fi 324 325test $KILLSERVERS != no && kill -HUP $KILLPIDS 326 327LDIF=$DATADIR/lloadd/monitor.ldif 328 329echo "Filtering ldapsearch results..." 330$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 331echo "Filtering original ldif used to create database..." 332$LDIFFILTER < $LDIF > $LDIFFLT 333echo "Comparing filter output..." 334$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 335 336if test $? != 0 ; then 337 echo "Comparison failed" 338 exit 1 339fi 340 341echo ">>>>> Test succeeded" 342 343test $KILLSERVERS != no && wait 344 345exit 0 346