Skip to content

Commit

Permalink
Improve inside tunnel connectivity check for tests
Browse files Browse the repository at this point in the history
Signed-off-by: keliramu <[email protected]>
  • Loading branch information
keliramu committed Dec 20, 2024
1 parent 35e1bdf commit c054354
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions test/qa/lib/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,25 @@ def capture_traffic(connection_settings) -> int:
return t_connect.packets_captured


def _check_connectivity(host, port=80, timeout=2) -> bool:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
result = sock.connect_ex((host, port))
sock.close()
return result == 0
finally:
sock.close()

return False

def _is_internet_reachable(retry=5) -> bool:
"""Returns True when remote host is reachable by its public IP."""
i = 0
while i < retry:
try:
return "icmp_seq=" in sh.ping("-c", "1", "-w", "1", "1.1.1.1")
#return "icmp_seq=" in sh.ping("-c", "1", "-w", "1", "1.1.1.1")
return _check_connectivity("1.1.1.1", 53)
except sh.ErrorReturnCode:
time.sleep(1)
i += 1
Expand Down Expand Up @@ -120,7 +133,8 @@ def _is_dns_resolvable(retry=5) -> bool:
while i < retry:
try:
# @TODO gitlab docker runner has public ipv6, but no connectivity. remove -4 once fixed
return "icmp_seq=" in sh.ping("-4", "-c", "1", "-w", "1", "nordvpn.com")
#return "icmp_seq=" in sh.ping("-4", "-c", "1", "-w", "1", "nordvpn.com")
return _check_connectivity("nordvpn.com", 80)
except sh.ErrorReturnCode:
time.sleep(1)
i += 1
Expand Down Expand Up @@ -172,7 +186,7 @@ def is_available(retry=5) -> bool:
"""Returns True when network access is available or throws AssertionError otherwise."""
assert _is_internet_reachable_outside_vpn(retry)
assert _is_internet_reachable(retry)
assert _is_dns_resolvable_outside_vpn(retry)
#assert _is_dns_resolvable_outside_vpn(retry)
assert _is_dns_resolvable(retry)
return True

Expand Down

0 comments on commit c054354

Please sign in to comment.