From e32d85059c0edbce66040c721ff0d54a7a5f0d59 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Mon, 3 Jul 2023 12:21:44 +0100 Subject: [PATCH 1/2] ci: remove unnecessary cleanup on exit after error Signed-off-by: Tiago Castro --- scripts/cargo-test.sh | 9 +++++---- scripts/grpc-test.sh | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/cargo-test.sh b/scripts/cargo-test.sh index cf33aef93..cdfbd4b8c 100755 --- a/scripts/cargo-test.sh +++ b/scripts/cargo-test.sh @@ -1,18 +1,19 @@ #!/usr/bin/env bash -SCRIPTDIR=$(dirname "$0") +SCRIPTDIR="$(realpath "$(dirname "$0")")" cleanup_handler() { - $SCRIPTDIR/clean-cargo-tests.sh || true + ERROR=$? + "$SCRIPTDIR"/clean-cargo-tests.sh || true + if [ $ERROR != 0 ]; then exit $ERROR; fi } -trap cleanup_handler ERR INT QUIT TERM HUP EXIT - echo "running cargo-test..." echo "rustc version:" rustc --version cleanup_handler +trap cleanup_handler INT QUIT TERM HUP EXIT set -euxo pipefail export PATH=$PATH:${HOME}/.cargo/bin diff --git a/scripts/grpc-test.sh b/scripts/grpc-test.sh index a865e9031..1f07c1013 100755 --- a/scripts/grpc-test.sh +++ b/scripts/grpc-test.sh @@ -1,19 +1,21 @@ #!/usr/bin/env bash -SCRIPTDIR=$(dirname "$0") -trap cleanup_handler ERR INT QUIT TERM HUP EXIT +SCRIPTDIR="$(realpath "$(dirname "$0")")" cleanup_handler() { - $SCRIPTDIR/clean-cargo-tests.sh || true + ERROR=$? + "$SCRIPTDIR"/clean-cargo-tests.sh || true + if [ $ERROR != 0 ]; then exit $ERROR; fi } +cleanup_handler +trap cleanup_handler INT QUIT TERM HUP EXIT + set -euxo pipefail export PATH="$PATH:${HOME}/.cargo/bin" export npm_config_jobs=$(nproc) -cleanup_handler - cargo build --all cd "$(dirname "$0")/../test/grpc" npm install --legacy-peer-deps From 9dbf2891bfc846e68ab6d870f80e25f8ca8664cb Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Wed, 19 Jul 2023 00:29:53 +0100 Subject: [PATCH 2/2] 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 9adae2935..957af3f9b 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 d82e0656e..d057a26f3 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 20dcf1311..84785dd1d 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 c75dba212..d3fd31534 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 8da11200a..94fc02ad4 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 de7b9ce1a..9a2fa2061 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: