From 3ad96cbf1daf7e54354c5c686e74ef38b5bd766e Mon Sep 17 00:00:00 2001 From: ggediminass Date: Mon, 16 Dec 2024 16:14:22 +0200 Subject: [PATCH 1/4] Check if internet is available --- test/qa/test_update.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/qa/test_update.py b/test/qa/test_update.py index 568ae894..776e76aa 100644 --- a/test/qa/test_update.py +++ b/test/qa/test_update.py @@ -93,6 +93,8 @@ def test_meshnet_available_after_update(): output = sh.nordvpn.disconnect() assert lib.is_disconnect_successful(output) + assert network.is_available() + def test_fileshare_available_after_update(): fileshare_help_page = sh.nordvpn.fileshare("--help", _tty_out=False) From 4b4fab826cddbca78c7aa22ee3f561da098de3f8 Mon Sep 17 00:00:00 2001 From: ggediminass Date: Mon, 16 Dec 2024 17:06:17 +0200 Subject: [PATCH 2/4] Prase peer list once --- test/qa/test_update.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/qa/test_update.py b/test/qa/test_update.py index 776e76aa..9c5913c2 100644 --- a/test/qa/test_update.py +++ b/test/qa/test_update.py @@ -81,10 +81,12 @@ def test_meshnet_available_after_update(): meshnet_help_page = sh.nordvpn.meshnet("--help", _tty_out=False) assert "Learn more: https://meshnet.nordvpn.com/" in meshnet_help_page - local_hostname = meshnet.PeerList.from_str(sh.nordvpn.mesh.peer.list()).get_this_device().hostname + parsed_peer_list = meshnet.PeerList.from_str(sh.nordvpn.mesh.peer.list()) + + local_hostname = parsed_peer_list.get_this_device().hostname ssh_client.exec_command(f"nordvpn mesh peer routing allow {local_hostname}") - peer_hostname = meshnet.PeerList.from_str(sh.nordvpn.mesh.peer.list()).get_internal_peer().hostname + peer_hostname = parsed_peer_list.get_internal_peer().hostname output = sh.nordvpn.mesh.peer.connect(peer_hostname) assert meshnet.is_connect_successful(output, peer_hostname) From 16394f86f0bf8aa64227eb5f66de0279fc6a5f9a Mon Sep 17 00:00:00 2001 From: ggediminass Date: Tue, 17 Dec 2024 18:15:52 +0200 Subject: [PATCH 3/4] Check if peers are connected --- test/qa/lib/meshnet.py | 27 +++++++++++++++++++++++++++ test/qa/test_update.py | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/qa/lib/meshnet.py b/test/qa/lib/meshnet.py index 385118f3..68fd9e37 100644 --- a/test/qa/lib/meshnet.py +++ b/test/qa/lib/meshnet.py @@ -5,6 +5,7 @@ import time from enum import Enum +import pytest import sh from . import daemon, info, logging, login, ssh @@ -666,3 +667,29 @@ def is_connect_successful(output:str, peer_hostname: str): def get_lines_with_keywords(lines: list[str], keywords: list[str]) -> list: """Returns list with elements, that contain specified `keywords`.""" return [line.strip() for line in lines if all(keyword in line for keyword in keywords)] + +def are_peers_connected(ssh_client: ssh.Ssh = None, retry: int = 3) -> None: + """ + Verifies if local and remote NordVPN mesh peers see each other as connected in peer list. + + Args: + ssh_client (ssh.Ssh): SSH client to execute commands on the remote system. + + Raises: + pytest.fail: If peers are not connected after `retry` attempts. + """ + + for refresh_count in range(retry): + local_peer_list = sh.nordvpn.mesh.peer.list(_tty_out=False) + remote_peer_list = ssh_client.exec_command("nordvpn mesh peer list") + + if "Status: connected" in local_peer_list and \ + "Status: connected" in remote_peer_list: + logging.log(f"peer list refresh count: {refresh_count}") + return + + time.sleep(2) + + logging.log(f"=== local_peer_list ===\n{local_peer_list}\n") + logging.log(f"=== remote_peer_list ===\n{remote_peer_list}\n") + pytest.fail("Peers do not see each other as connected.") diff --git a/test/qa/test_update.py b/test/qa/test_update.py index 9c5913c2..fd9f5847 100644 --- a/test/qa/test_update.py +++ b/test/qa/test_update.py @@ -55,8 +55,7 @@ def setup_function(function): # noqa: ARG001 ssh_client.exec_command("nordvpn set notify off") ssh_client.exec_command("nordvpn set mesh on") - sh.nordvpn.mesh.peer.list() - ssh_client.exec_command("nordvpn mesh peer list") + meshnet.are_peers_connected(ssh_client) def teardown_function(function): # noqa: ARG001 From 542fc015588fb40364393477881d75fc73770bb5 Mon Sep 17 00:00:00 2001 From: ggediminass Date: Thu, 19 Dec 2024 13:35:13 +0200 Subject: [PATCH 4/4] Check if status is correct --- test/qa/test_update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/qa/test_update.py b/test/qa/test_update.py index fd9f5847..429d51e7 100644 --- a/test/qa/test_update.py +++ b/test/qa/test_update.py @@ -88,12 +88,12 @@ def test_meshnet_available_after_update(): peer_hostname = parsed_peer_list.get_internal_peer().hostname output = sh.nordvpn.mesh.peer.connect(peer_hostname) assert meshnet.is_connect_successful(output, peer_hostname) - + assert daemon.is_connected() assert network.is_available() output = sh.nordvpn.disconnect() assert lib.is_disconnect_successful(output) - + assert not daemon.is_connected() assert network.is_available()