Skip to content

Commit

Permalink
Add internet monitoring
Browse files Browse the repository at this point in the history
Signed-off-by: Marius Sincovici <[email protected]>
  • Loading branch information
mariusSincovici authored and keliramu committed Oct 8, 2024
1 parent 158157f commit 9315b44
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/qa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ source .venv/bin/activate # this should modify your shell prompt
```
3. How to install Python dependencies from file.
```bash
python3 -m pip install -r <path-to-requirements-txt> # requirements.txt is found in `ci/docker/requirements.txt`
python3 -m pip install -r <path-to-requirements-txt> # requirements.txt is found in `ci/docker/tester/requirements.txt`
```
4. How to install new packages.
```bash
Expand Down
56 changes: 56 additions & 0 deletions test/qa/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import datetime
import socket
import threading
import time

import pytest
import sh

from lib import network

_CHECK_FREQUENCY=5

_original_print = print
def _print_with_timestamp(*args, **kwargs):
# Get the current time and format it
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# Prepend the timestamp to the original print arguments
_original_print(timestamp, *args, **kwargs)

# Replace the built-in print with our custom version
print = _print_with_timestamp

Check failure on line 21 in test/qa/conftest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (A001)

test/qa/conftest.py:21:1: A001 Variable `print` is shadowing a Python builtin

@pytest.fixture(scope="function", autouse=True)
def setup_check_internet_connection():
print("Check internet connection before starting tests")
assert network.is_available()

Check failure on line 27 in test/qa/conftest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

test/qa/conftest.py:27:1: W293 Blank line contains whitespace

@pytest.fixture(scope="session", autouse=True)
def start_system_monitoring():
print("Start system monitoring")

Check failure on line 32 in test/qa/conftest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

test/qa/conftest.py:32:1: W293 Blank line contains whitespace
connection_check_thread = threading.Thread(target=_check_connection_to_ip, args=("1.1.1.1",), daemon=True)
dns_resolver_thread = threading.Thread(target=_check_dns_resolution, args=("nordvpn.com",), daemon=True)
connection_check_thread.start()
dns_resolver_thread.start()

Check failure on line 37 in test/qa/conftest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

test/qa/conftest.py:37:1: W293 Blank line contains whitespace
yield


def _check_connection_to_ip(ip_address):
while True:
try:
"icmp_seq=" in sh.ping("-c", "1", "-w", "1", ip_address) # noqa: B015
except sh.ErrorReturnCode as e:
print(f"Failed to connect to {ip_address}: {e}.")
time.sleep(_CHECK_FREQUENCY)


Check failure on line 49 in test/qa/conftest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

test/qa/conftest.py:49:1: W293 Blank line contains whitespace
def _check_dns_resolution(domain):
while True:
try:
socket.gethostbyname(domain)
except socket.gaierror:
print(f"DNS resolution for {domain} failed.")
time.sleep(_CHECK_FREQUENCY)

Check failure on line 56 in test/qa/conftest.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

test/qa/conftest.py:56:37: W292 No newline at end of file
2 changes: 1 addition & 1 deletion test/qa/lib/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def collect():
network_interface_info = os.popen("sudo ip addr").read() #sh.sudo.ip.addr()
routing_info = os.popen("sudo ip route").read() #sh.sudo.ip.route()
firewall_info = os.popen("sudo iptables -S").read() #sh.sudo.iptables("-S")
nameserver_info = os.popen("sudo cat /etc/resolve.conf").read() #sh.sudo.cat("/etc/resolv.conf")
nameserver_info = os.popen("sudo cat /etc/resolv.conf").read() #sh.sudo.cat("/etc/resolv.conf")

# without `ww` we cannot see full process lines, as it is cut off early
processes = sh.ps("-ef", "ww")
Expand Down

0 comments on commit 9315b44

Please sign in to comment.