Blame tests/p_traceroute/traceroute_test.sh
Branch: 9c974f2f04b2abd1d3514da9463c786af8680687
Christoph Galuschka
08145a
#!/bin/sh
Christoph Galuschka
08145a
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
Christoph Galuschka
08145a
Christoph Galuschka
722da5
TEST=traceroute
Christoph Galuschka
08145a
Christoph Galuschka
372989
# Testing availability of network
Christoph Galuschka
372989
if [ $SKIP_QA_HARNESS -eq 1 ]; then
Athmane Madjoudj
b0e7f7
HOST="ci.centos.org"
Christoph Galuschka
372989
else
Christoph Galuschka
372989
HOST="repo.centos.qa"
Christoph Galuschka
372989
fi
Christoph Galuschka
372989
Christoph Galuschka
67e17b
t_Log "Running $0 - running ${TEST} to ${HOST}"
Christoph Galuschka
372989
Christoph Galuschka
67e17b
IP=$(host ${HOST})
Christoph Galuschka
6eff64
FILE=/var/tmp/traceroute_result
Christoph Galuschka
6eff64
ret_val=1
Christoph Galuschka
06f0c0
# getting IP-address of default gateway as a fall back
Christoph Galuschka
06f0c0
defgw=$(ip route list | grep default | cut -d' ' -f3)
Christoph Galuschka
67e17b
Christoph Galuschka
06f0c0
if [[ $IP =~ .*address\ ([0-9.]*) ]]
Christoph Galuschka
372989
then
Christoph Galuschka
6eff64
traceroute -n ${HOST} > ${FILE}
Christoph Galuschka
6eff64
COUNT=$(grep -c ${BASH_REMATCH[1]} ${FILE})
Christoph Galuschka
6eff64
TTL=$(egrep -c '30 \* \* \*' ${FILE})
Christoph Galuschka
06f0c0
GW=$(grep -c ${defgw} ${FILE})
Christoph Galuschka
67e17b
if [ $COUNT = 2 ]
Christoph Galuschka
8e8c03
then
Christoph Galuschka
67e17b
t_Log "${TEST} reached ${HOST}"
Christoph Galuschka
67e17b
ret_val=0
Christoph Galuschka
6eff64
elif ([ $COUNT != 2 ] && [ $TTL = 1 ])
Christoph Galuschka
6eff64
then
Christoph Galuschka
6eff64
t_Log "${TEST} didn't reach ${HOST} because of too many hops/blocked traceroute by ISP. This is treated as SUCCESS."
Christoph Galuschka
6eff64
ret_val=0
Christoph Galuschka
06f0c0
elif ([ $COUNT != 2 ] && [ $GW -gt 0 ])
Christoph Galuschka
06f0c0
then
Christoph Galuschka
06f0c0
t_Log "${TEST} didn't reach ${HOST} (maybe because of ACLs on the network), but at least the Default Gateway ${defgw} was reached. Treating as SUCCESS."
Christoph Galuschka
06f0c0
ret_val=0
Christoph Galuschka
67e17b
else
Christoph Galuschka
6eff64
t_Log "${TEST} didn't return anything we expect - FAILING"
Christoph Galuschka
06f0c0
ret_val=1
Christoph Galuschka
08145a
fi
Christoph Galuschka
08145a
fi
Christoph Galuschka
08145a
Christoph Galuschka
6eff64
/bin/rm ${FILE}
Christoph Galuschka
dea7b2
t_CheckExitStatus $ret_val