From b11b9f638f7ed7b5b9193b8e1e5e4d3f4d98b5b5 Mon Sep 17 00:00:00 2001 From: Fabian Pfitzner Date: Fri, 5 Jul 2024 09:44:51 +0200 Subject: [PATCH 1/2] tests: nfs io extension extend nfs test case by checking whether simple io operations are possible and move it into the the network tests section. this move makes more sense as nfs is more related to network than to userspace. --- tests/test_network.py | 26 ++++++++++++++++++++++++++ tests/test_userspace.py | 16 ---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/test_network.py b/tests/test_network.py index bf7739f..2302809 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -124,3 +124,29 @@ def test_network_interfaces(shell): found_interfaces.add(line.split(":")[1].strip()) assert expected_interfaces == found_interfaces + +@pytest.mark.lg_feature("ptx-flavor") +def test_network_nfs_io(shell): + """Test nfs share io""" + ptx_works = shell.target.env.config.get_target_option(shell.target.name, "ptx-works-available") + assert len(ptx_works) > 0 + + mount = shell.run_check("mount") + mount = "\n".join(mount) + + # Iterate over all available shares and check whether io operation is possible + for ptx_work in ptx_works: + assert ptx_work in mount + + dir_contents = shell.run_check(f"ls -1 {ptx_work}") + # make sure the directories contain something + assert len(dir_contents) > 0 + + shell.run_check(f"cd {ptx_work}") + + # Create a file on the share + file, _, returncode = shell.run("mktemp -p .") + assert returncode == 0 + assert len(file) > 0 + + shell.run_check(f"rm {file[0]}") diff --git a/tests/test_userspace.py b/tests/test_userspace.py index aec1181..328af81 100644 --- a/tests/test_userspace.py +++ b/tests/test_userspace.py @@ -24,22 +24,6 @@ def test_system_running_1(system1_shell): system_running(system1_shell) -@pytest.mark.lg_feature("ptx-flavor") -def test_nfs_mounts(env, target, shell): - """Test that the NFS mounts listed in the environment config are available.""" - ptx_works = env.config.get_target_option(target.name, "ptx-works-available") - - mount = shell.run_check("mount") - mount = "\n".join(mount) - - for ptx_work in ptx_works: - assert ptx_work in mount - - dir_contents = shell.run_check(f"ls -1 {ptx_work}") - # make sure the directories contain something - assert len(dir_contents) > 0 - - def test_chrony(shell): """Test that chronyd is running and synchronized.""" [chronyc] = shell.run_check("chronyc -c tracking") From fa50be065278fa89c632cbb8963b83ece7178354 Mon Sep 17 00:00:00 2001 From: Fabian Pfitzner Date: Fri, 5 Jul 2024 14:27:58 +0200 Subject: [PATCH 2/2] tests: http io --- tests/test_network.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_network.py b/tests/test_network.py index 2302809..f76255a 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -1,7 +1,9 @@ +import hashlib import json from time import sleep import pytest +import requests @pytest.fixture(scope="function") @@ -125,6 +127,7 @@ def test_network_interfaces(shell): assert expected_interfaces == found_interfaces + @pytest.mark.lg_feature("ptx-flavor") def test_network_nfs_io(shell): """Test nfs share io""" @@ -150,3 +153,27 @@ def test_network_nfs_io(shell): assert len(file) > 0 shell.run_check(f"rm {file[0]}") + + +def test_network_http_io(strategy, shell): + """Test http server file io""" + + # Create test file + shell.run_check("dd if=/dev/random of=/srv/www/test_file bs=1M count=15") + output, _, returncode = shell.run("md5sum /srv/www/test_file") + assert returncode == 0 + assert len(output) > 0 + + # Cut out hash from output + checksum1 = output[0].split(" ")[0] + + # Download test file + r = requests.get(f"http://{strategy.network.address}/srv/test_file") + assert r.status_code == 200 + + checksum2 = hashlib.md5(r.content).hexdigest() + + assert checksum1 == checksum2, f"checksums are different: {checksum1} != {checksum2}" + + # Delete test file + shell.run_check("rm /srv/www/test_file")