1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#!/bin/bash
ARG="$1"
ARG2="$2"
NFTBIN="nft"
NFTLBIN="../src/nftlb"
NFTLB_ARGS=""
APISERVER=0
APISRV_PORT=5555
APISRV_KEY="hola"
CURL=`which curl`
TESTS=""
APPLY_REPORTS=0
if [ "${ARG}" == "-s" -a -e "$CURL" ]; then
APISERVER=1
elif [ "${ARG}" == "-apply-reports" ]; then
APPLY_REPORTS=1
TESTS="${ARG2}"
elif [[ -d ${ARG} ]]; then
TESTS="${ARG}"
elif [ "${ARG}" == "" ]; then
TESTS="*/"
fi
if [ "$TESTS" == "" -a "${ARG2}" == "" ]; then
TESTS="*/"
fi
echo "" > /var/log/syslog
if [ $APISERVER -eq 1 ]; then
$NFTLBIN $NFTLB_ARGS -d -k "$APISRV_KEY" -l 7 > /dev/null
fi
echo "-- Executing configuration tests"
for test in `ls -d ${TESTS}`; do
if [[ ! ${test} =~ ^..._ ]]; then
continue;
fi
echo -n "Executing test: ${test}... "
inputfile="${test}/input.json"
outputfile="${test}/output.nft"
reportfile="${test}/report-output.nft"
if [ $APISERVER -eq 1 ]; then
$CURL -H "Expect:" -H "Key: $APISRV_KEY" -X DELETE http://localhost:$APISRV_PORT/farms
$CURL -H "Expect:" -H "Key: $APISRV_KEY" -X POST http://localhost:$APISRV_PORT/farms -d "@${inputfile}"
statusexec=$?
else
$NFTLBIN $NFTLB_ARGS -e -l 7 -c ${inputfile}
statusexec=$?
fi
if [ $statusexec -ne 0 ]; then
echo -e "\e[31mNFT EXEC ERROR\e[0m"
continue;
fi
$NFTBIN list ruleset > ${reportfile}
if [ ! -f ${outputfile} ]; then
echo "Dump file doesn't exist"
continue;
fi
diff -Nru ${outputfile} ${reportfile}
statusnft=$?
if [ $statusnft -eq 0 ]; then
echo -e "\e[32mOK\e[0m"
rm -f ${reportfile}
else
echo -e "\e[31mNFT DUMP ERROR\e[0m"
if [ $APPLY_REPORTS -eq 1 ]; then
cat ${reportfile} > ${outputfile}
echo -e "APPLIED"
fi
fi
done
if [ $APISERVER -eq 1 ]; then
kill `pidof nftlb`
fi
if [ "`grep 'nft command error' /var/log/syslog`" != "" ]; then
echo -e "\e[33m* command errors found, please check syslog\e[0m"
fi
|