Skip to content

Commit 0686d38

Browse files
authored
adding new option for network check in persist_firewall test (#3257)
* fixing network check * addressing comment * addressed comment
1 parent 5a94b1e commit 0686d38

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

tests_e2e/tests/scripts/agent_persist_firewall-access_wireserver

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,34 @@ function check_online
3131
{
3232
echo "Checking network connectivity..."
3333

34-
echo "Running ping to 8.8.8.8 option"
35-
checks=0
36-
while true; do
37-
if ping 8.8.8.8 -c 1 -i .2 -t 30; then
38-
echo "Network is accessible"
39-
return 0
40-
fi
41-
checks=$((checks + 1))
42-
if [ $checks -gt 10 ]; then
43-
break
44-
fi
34+
echo "Connecting to ifconfig.io to check network connection"
35+
if command -v curl >/dev/null 2>&1; then
36+
curl --retry 5 --retry-delay 5 --connect-timeout 5 -4 ifconfig.io/ip
37+
elif command -v wget >/dev/null 2>&1; then
38+
wget --tries=5 --timeout=5 --wait=5 -4 ifconfig.io/ip
39+
else
40+
http_get.py "http://ifconfig.io/ip" --timeout 5 --delay 5 --tries 5
41+
fi
4542

43+
if [[ $? -eq 0 ]]; then
44+
echo "Network is accessible"
45+
return 0
46+
else
4647
echo "$(date --utc +%FT%T.%3NZ): Network still not accessible"
47-
# We're offline. Sleep for a bit, then check again
48-
sleep 1;
49-
done
48+
fi
49+
50+
echo "Running ping to 8.8.8.8 option"
51+
52+
if ping 8.8.8.8 -c 1 -i .2 -t 30; then
53+
echo "Network is accessible"
54+
return 0
55+
fi
56+
57+
echo "$(date --utc +%FT%T.%3NZ): Network still not accessible"
58+
echo "Unable to connect to network, giving up"
59+
return 1
60+
61+
# Will remove other options if we determine first option is stable
5062

5163
echo "Checking other options to see if network is accessible..."
5264

@@ -77,10 +89,12 @@ fi
7789
echo "Finally online, Time: $(date --utc +%FT%T.%3NZ)"
7890
echo "Trying to contact Wireserver as $USER to see if accessible"
7991
echo ""
92+
93+
# This script is run by a cron job on reboot, so it runs in a limited environment. Some distros may be missing the iptables path,
94+
# so adding common iptables paths to the environment.
95+
export PATH=$PATH:/usr/sbin:/sbin
8096
echo "Firewall configuration before accessing Wireserver:"
81-
if sudo which iptables > /dev/null ; then
82-
sudo iptables -t security -L -nxv -w
83-
else
97+
if ! sudo iptables -t security -L -nxv -w; then
8498
sudo nft list table walinuxagent
8599
fi
86100
echo ""
@@ -89,7 +103,7 @@ WIRE_IP=$(cat /var/lib/waagent/WireServerEndpoint 2>/dev/null || echo '168.63.12
89103
if command -v curl >/dev/null 2>&1; then
90104
curl --retry 3 --retry-delay 5 --connect-timeout 5 "http://$WIRE_IP/?comp=versions" -o "/tmp/wire-versions-$USER.xml"
91105
elif command -v wget >/dev/null 2>&1; then
92-
wget --tries=3 "http://$WIRE_IP/?comp=versions" --timeout=5 -O "/tmp/wire-versions-$USER.xml"else
106+
wget --tries=3 "http://$WIRE_IP/?comp=versions" --timeout=5 --wait=5 -O "/tmp/wire-versions-$USER.xml"
93107
else
94108
http_get.py "http://168.63.129.16/?comp=versions" --timeout 5 --delay 5 --tries 3
95109
fi

0 commit comments

Comments
 (0)