From 79fda5c99cd33e89ad1f218c7afa1628fbb9c716 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 29 Jan 2025 17:19:49 +0100 Subject: [PATCH] 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 --- tests/nvme_test.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/nvme_test.py b/tests/nvme_test.py index 6b231e43ae..2fea4ec016 100644 --- a/tests/nvme_test.py +++ b/tests/nvme_test.py @@ -31,6 +31,7 @@ import subprocess import sys import unittest +import time from nvme_test_logger import TestNVMeLogger @@ -407,12 +408,18 @@ def attach_ns(self, ctrl_id, nsid): err = subprocess.call(attach_ns_cmd, shell=True, stdout=subprocess.DEVNULL) - if err == 0: - # enumerate new namespace block device - self.nvme_reset_ctrl() - # check if new namespace block device exists - err = 0 if stat.S_ISBLK(os.stat(self.ctrl + "n" + str(nsid)).st_mode) else 1 - return err + if err != 0: + return err + + # Try to find block device for 5 seconds + device_path = f"{self.ctrl}n{str(nsid)}" + stop_time = time.time() + 5 + while time.time() < stop_time: + if os.path.exists(device_path) and stat.S_ISBLK(os.stat(device_path).st_mode): + return 0 + time.sleep(0.1) + + return 1 def detach_ns(self, ctrl_id, nsid): """ Wrapper for detaching the namespace.