From 34c6315bb489652ec11b7ea3258ee91e7b38ce07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gediminas=20Al=C5=A1auskas?= Date: Fri, 20 Dec 2024 18:21:28 +0200 Subject: [PATCH] Address flaky update tests (#724) --- test/qa/lib/meshnet.py | 27 +++++++++++++++++++++++++++ test/qa/test_update.py | 13 ++++++++----- 2 files changed, 35 insertions(+), 5 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 568ae894..429d51e7 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 @@ -81,17 +80,21 @@ 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) - + 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() def test_fileshare_available_after_update():