From 2ae48652a74bdb549840a4cd5bcd6721c849244e Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Wed, 19 Jul 2023 00:29:53 +0100 Subject: [PATCH] test: fix python tests Now that the nexus stays shutdown on all children failure, dd might not complete with error. To address this, add smaller delay and ctrl loss timeout. Also add missing sudo for xfs_info. Signed-off-by: Tiago Castro --- test/python/common/nvme.py | 6 ++++-- test/python/tests/nexus/test_multi_nexus.py | 6 ++++-- test/python/tests/nexus/test_nexus.py | 2 +- test/python/tests/nexus_fault/test_nexus_fault.py | 6 +++--- test/python/v1/nexus/test_multi_nexus.py | 6 ++++-- test/python/v1/nexus/test_nexus.py | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/test/python/common/nvme.py b/test/python/common/nvme.py index 9adae29359..957af3f9b8 100644 --- a/test/python/common/nvme.py +++ b/test/python/common/nvme.py @@ -57,13 +57,15 @@ async def nvme_remote_discover(remote, uri): raise ValueError("uri {} is not discovered".format(u.path[1:])) -def nvme_connect(uri): +def nvme_connect(uri, delay=10, tmo=600): u = urlparse(uri) port = u.port host = u.hostname nqn = u.path[1:] - command = "sudo nvme connect -t tcp -s {0} -a {1} -n {2}".format(port, host, nqn) + command = ( + f"sudo nvme connect -t tcp -s {port} -a {host} -n {nqn} -c {delay} -l {tmo}" + ) subprocess.run(command, check=True, shell=True, capture_output=False) time.sleep(1) command = "sudo nvme list -v -o json" diff --git a/test/python/tests/nexus/test_multi_nexus.py b/test/python/tests/nexus/test_multi_nexus.py index d82e0656e5..d057a26f3b 100644 --- a/test/python/tests/nexus/test_multi_nexus.py +++ b/test/python/tests/nexus/test_multi_nexus.py @@ -7,6 +7,7 @@ import pytest import asyncio import uuid as guid +import pytest_asyncio NEXUS_COUNT = 15 DESTROY_COUNT = 7 @@ -114,11 +115,11 @@ def connect_devices(create_nexuses): nvme_disconnect(nexus) -@pytest.fixture +@pytest_asyncio.fixture async def mount_devices(connect_devices): "Create and mount a filesystem on each nvmf connected device." for dev in connect_devices: - await run_cmd_async(f"sudo mkfs.xfs {dev}") + await run_cmd_async(f"sudo mkfs.ext4 {dev}") await run_cmd_async(f"sudo mkdir -p /mnt{dev}") await run_cmd_async(f"sudo mount {dev} /mnt{dev}") @@ -126,6 +127,7 @@ async def mount_devices(connect_devices): for dev in connect_devices: await run_cmd_async(f"sudo umount /mnt{dev}") + await run_cmd_async(f"sudo rm -rf /mnt/dev") @pytest.mark.asyncio diff --git a/test/python/tests/nexus/test_nexus.py b/test/python/tests/nexus/test_nexus.py index 20dcf13110..84785dd1da 100644 --- a/test/python/tests/nexus/test_nexus.py +++ b/test/python/tests/nexus/test_nexus.py @@ -448,7 +448,7 @@ def test_nexus_preempt_key( # verify write error with nexus on ms3 uri = create_nexus_v2 - dev = nvme_connect(uri) + dev = nvme_connect(uri, 1, 1) job = "sudo dd if=/dev/urandom of={0} bs=512 count=1".format(dev) try: diff --git a/test/python/tests/nexus_fault/test_nexus_fault.py b/test/python/tests/nexus_fault/test_nexus_fault.py index c75dba212f..d3fd31534c 100644 --- a/test/python/tests/nexus_fault/test_nexus_fault.py +++ b/test/python/tests/nexus_fault/test_nexus_fault.py @@ -143,9 +143,9 @@ def _(mounted_nexus): """the initiator filesystem should not be shutdown.""" try: # xfs_info should still be working as the fs is not shutdown - run_cmd(f"xfs_info {mounted_nexus}") - except: - pytest.fail(f"Filesystem on {mounted_nexus} should not be shutdown") + run_cmd(f"sudo xfs_info {mounted_nexus}") + except Exception as e: + pytest.fail(f"Filesystem on {mounted_nexus} should not be shutdown: {e}") @pytest.fixture(scope="module") diff --git a/test/python/v1/nexus/test_multi_nexus.py b/test/python/v1/nexus/test_multi_nexus.py index 8da11200ac..94fc02ad47 100644 --- a/test/python/v1/nexus/test_multi_nexus.py +++ b/test/python/v1/nexus/test_multi_nexus.py @@ -7,6 +7,7 @@ import pytest import asyncio import uuid as guid +import pytest_asyncio NEXUS_COUNT = 15 DESTROY_COUNT = 7 @@ -139,11 +140,11 @@ def connect_devices(create_nexuses): nvme_disconnect(nexus) -@pytest.fixture +@pytest_asyncio.fixture async def mount_devices(connect_devices): "Create and mount a filesystem on each nvmf connected device." for dev in connect_devices: - await run_cmd_async(f"sudo mkfs.xfs {dev}") + await run_cmd_async(f"sudo mkfs.ext4 {dev}") await run_cmd_async(f"sudo mkdir -p /mnt{dev}") await run_cmd_async(f"sudo mount {dev} /mnt{dev}") @@ -151,6 +152,7 @@ async def mount_devices(connect_devices): for dev in connect_devices: await run_cmd_async(f"sudo umount /mnt{dev}") + await run_cmd_async(f"sudo rm -rf /mnt/dev") @pytest.mark.asyncio diff --git a/test/python/v1/nexus/test_nexus.py b/test/python/v1/nexus/test_nexus.py index de7b9ce1af..9a2fa2061f 100644 --- a/test/python/v1/nexus/test_nexus.py +++ b/test/python/v1/nexus/test_nexus.py @@ -436,7 +436,7 @@ def test_nexus_preempt_key( # verify write error with nexus on ms3 uri = create_nexus - dev = nvme_connect(uri) + dev = nvme_connect(uri, 1, 1) job = "sudo dd if=/dev/urandom of={0} bs=512 count=1".format(dev) try: