Skip to content

Commit

Permalink
Check if peers are connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ggediminass committed Dec 19, 2024
1 parent 4b4fab8 commit 16394f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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):
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.")
3 changes: 1 addition & 2 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 Down

0 comments on commit 16394f8

Please sign in to comment.