From 4ead5398d07b39ba4358b3facb4af0a1eab3d022 Mon Sep 17 00:00:00 2001 From: chunfuwen Date: Thu, 3 Aug 2023 23:47:36 -0400 Subject: [PATCH] Add wait in create_scsi_disk method In some extreme situation, although loading scsi_debug module is returned smoothly, but still it leads to failure in finding scsi device Signed-off-by: chunfuwen --- virttest/utils_test/libvirt.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/virttest/utils_test/libvirt.py b/virttest/utils_test/libvirt.py index 235cebc5d12..7ffd6e68abb 100644 --- a/virttest/utils_test/libvirt.py +++ b/virttest/utils_test/libvirt.py @@ -2876,8 +2876,18 @@ def create_scsi_disk(scsi_option, scsi_size="2048"): # Unload it first if it's already loaded. if linux_modules.module_is_loaded("scsi_debug"): linux_modules.unload_module("scsi_debug") + linux_modules.load_module("scsi_debug dev_size_mb=%s %s" % (scsi_size, scsi_option)) + + def _get_scsi_disk(): + """attempt to get scsi disk multiple times until getting real one""" + scsi_disk = process.run("lsscsi|grep scsi_debug|awk '{print $6}'", + shell=True).stdout_text.strip() + return scsi_disk is not None + + utils_misc.wait_for(lambda: _get_scsi_disk(), + timeout=10, ignore_errors=True) # Get the scsi device name result = process.run("lsscsi|grep scsi_debug|awk '{print $6}'", shell=True)