diff --git a/qemu/tests/cgroup.py b/qemu/tests/cgroup.py index 0557e17f9c25ee2247a91d4682ed5ea23386d95d..ef7fea666ad98eb973090e65a7ec6d22d26aa419 100644 --- a/qemu/tests/cgroup.py +++ b/qemu/tests/cgroup.py @@ -19,6 +19,7 @@ from aexpect import ShellTimeoutError from virttest.env_process import preprocess from virttest import qemu_monitor from virttest import error_context +from virttest import utils_misc from virttest.staging import utils_memory from virttest.staging.utils_cgroup import Cgroup @@ -1503,6 +1504,18 @@ def run(test, params, env): return True + def _get_scsi_debug_disk(): + cmd = ("ls -1 /sys/bus/pseudo/drivers/scsi_debug/adapter*/" + "host*/target*/*/block | grep ^sd | head -1") + name = process.system_output(cmd, shell=True, verbose=False, + ignore_status=True).decode() + if not name: + return None + node_path = "/dev/%s" % name + if not os.path.exists(node_path): + return None + return node_path + logging.info("Setup test") vm = env.get_all_vms()[0] # Try to find suitable monitor @@ -1549,8 +1562,9 @@ def run(test, params, env): process.system("modprobe scsi_debug dev_size_mb=8 add_host=0") process.system("echo 1 > /sys/bus/pseudo/drivers/scsi_debug/add_host", shell=True) - time.sleep(0.1) - disk = process.system_output("ls /dev/sd* | tail -n 1", shell=True) + disk = utils_misc.wait_for(_get_scsi_debug_disk, 5) + if not disk: + test.error("Could not get the device node generated by scsi_debug") dev = "%s:%s" % get_maj_min(disk) permissions = [ {'property': 'deny',