Skip to content

Commit

Permalink
test: fix python tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tiagolobocastro committed Jul 19, 2023
1 parent 663facd commit 2ae4865
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions test/python/common/nvme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions test/python/tests/nexus/test_multi_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
import asyncio
import uuid as guid
import pytest_asyncio

NEXUS_COUNT = 15
DESTROY_COUNT = 7
Expand Down Expand Up @@ -114,18 +115,19 @@ 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}")

yield

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
Expand Down
2 changes: 1 addition & 1 deletion test/python/tests/nexus/test_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions test/python/tests/nexus_fault/test_nexus_fault.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions test/python/v1/nexus/test_multi_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
import asyncio
import uuid as guid
import pytest_asyncio

NEXUS_COUNT = 15
DESTROY_COUNT = 7
Expand Down Expand Up @@ -139,18 +140,19 @@ 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}")

yield

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
Expand Down
2 changes: 1 addition & 1 deletion test/python/v1/nexus/test_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2ae4865

Please sign in to comment.