Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address flaky update tests #724

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/qa/lib/meshnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
from enum import Enum

import pytest
import sh

from . import daemon, info, logging, login, ssh
Expand Down Expand Up @@ -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):
ggediminass marked this conversation as resolved.
Show resolved Hide resolved
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.")
13 changes: 8 additions & 5 deletions test/qa/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down
Loading