From c054354d386b38b73f494b531aa4b67350f29038 Mon Sep 17 00:00:00 2001 From: keliramu Date: Fri, 20 Dec 2024 14:21:13 +0200 Subject: [PATCH] Improve inside tunnel connectivity check for tests Signed-off-by: keliramu --- test/qa/lib/network.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/qa/lib/network.py b/test/qa/lib/network.py index 13e59933..3ba476c4 100644 --- a/test/qa/lib/network.py +++ b/test/qa/lib/network.py @@ -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 @@ -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 @@ -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