Skip to content

Commit 56cf51b

Browse files
committed
tests: monitor /dev for new nvme block device
The attach operation takes a bit of time and is asynchronous, thus we should monitor if the block device appears for a period, before returning an error. Signed-off-by: Daniel Wagner <[email protected]>
1 parent c1fbf74 commit 56cf51b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/nvme_test.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import subprocess
3232
import sys
3333
import unittest
34+
import time
3435

3536
from nvme_test_logger import TestNVMeLogger
3637

@@ -407,12 +408,18 @@ def attach_ns(self, ctrl_id, nsid):
407408
err = subprocess.call(attach_ns_cmd,
408409
shell=True,
409410
stdout=subprocess.DEVNULL)
410-
if err == 0:
411-
# enumerate new namespace block device
412-
self.nvme_reset_ctrl()
413-
# check if new namespace block device exists
414-
err = 0 if stat.S_ISBLK(os.stat(self.ctrl + "n" + str(nsid)).st_mode) else 1
415-
return err
411+
if err != 0:
412+
return err
413+
414+
# Try to find block device for 5 seconds
415+
device_path = f"{self.ctrl}n{str(nsid)}"
416+
stop_time = time.time() + 5
417+
while time.time() < stop_time:
418+
if os.path.exists(device_path) and stat.S_ISBLK(os.stat(device_path).st_mode):
419+
return 0
420+
time.sleep(0.1)
421+
422+
return 1
416423

417424
def detach_ns(self, ctrl_id, nsid):
418425
""" Wrapper for detaching the namespace.

0 commit comments

Comments
 (0)