Blame tests/p_mtr/mtr_test.sh

Christoph Galuschka fe4cd3
#!/bin/sh
Christoph Galuschka fe4cd3
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
Christoph Galuschka fe4cd3
40b4c8
if [ "$CONTAINERTEST" -eq "1" ]; then
40b4c8
    t_Log "Running in container -> SKIP"
40b4c8
    exit 0
40b4c8
fi
40b4c8
Christoph Galuschka fe4cd3
TEST=mtr
Christoph Galuschka fe4cd3
Christoph Galuschka fe4cd3
# Testing availability of network
Christoph Galuschka fe4cd3
if [ $SKIP_QA_HARNESS -eq 1 ]; then
3d0f9a
  HOST="www.centos.org"
Christoph Galuschka fe4cd3
else
3d0f9a
  HOST="www.centos.org"
Christoph Galuschka fe4cd3
fi
Christoph Galuschka fe4cd3
Christoph Galuschka 67e17b
t_Log "Running $0 - running ${TEST} to ${HOST}"
Christoph Galuschka 67e17b
ret_val=1
7b1f46
FILE=/var/tmp/mtr_result
Christoph Galuschka fe4cd3
7b1f46
IP=$(dig +short ${HOST} A ${HOST} AAAA)
Christoph Galuschka 67e17b
104e20
# getting IP-address of default gateway as a fall back
104e20
defgw=$(ip route list | grep default | cut -d' ' -f3)
104e20
7b1f46
if [[ ! -z "$IP" ]]
Christoph Galuschka fe4cd3
then
7b1f46
  mtr -nr -c1 ${HOST} > ${FILE}
7b1f46
  COUNT=$(echo "$IP" | grep -cf - ${FILE})
104e20
  GW=$(grep -c ${defgw} ${FILE})
Christoph Galuschka 67e17b
  if [ $COUNT = 1 ]
Christoph Galuschka fe4cd3
  then
Christoph Galuschka 67e17b
    t_Log "${TEST} reached ${HOST}"
Christoph Galuschka 67e17b
    ret_val=0
104e20
  elif ([ $COUNT = 0 ] && [ $GW -gt 0 ])
104e20
  then
104e20
    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."
104e20
    ret_val=0
Christoph Galuschka 67e17b
  else
Christoph Galuschka 67e17b
    t_Log "${TEST} didn't reach ${HOST}"
Christoph Galuschka 67e17b
    ret_val=1
Christoph Galuschka fe4cd3
  fi
Christoph Galuschka fe4cd3
fi
Christoph Galuschka fe4cd3
7b1f46
/bin/rm ${FILE}
Christoph Galuschka dea7b2
t_CheckExitStatus $ret_val