Skip to content

Commit

Permalink
Fix virt-admin check log failure
Browse files Browse the repository at this point in the history
Use utils_misc.wait_for to wait for expected message log

Signed-off-by: chunfuwen <[email protected]>
  • Loading branch information
chunfuwen committed Nov 25, 2024
1 parent 73969d9 commit 2a37fc7
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from avocado.utils import process

from virttest import utils_libvirtd
from virttest import virt_vm
from virttest import virt_vm, utils_misc
from virttest import virt_admin

from virttest.libvirt_xml import vm_xml
Expand Down Expand Up @@ -117,8 +117,7 @@ def check_msg_in_var_log_message(params, test):
log_config_path = params.get("log_file_path")
str_to_grep = params.get("str_to_grep")
cmd = "grep -E -l '%s' %s" % (str_to_grep, log_config_path)
if process.run(cmd, shell=True, ignore_status=True).exit_status != 0:
test.fail("Check message log:%s failed in log file:%s" % (str_to_grep, log_config_path))
return process.run(cmd, shell=True, ignore_status=True).exit_status == 0


def run(test, params, env):
Expand All @@ -144,7 +143,11 @@ def run(test, params, env):
except virt_vm.VMStartError as e:
LOG.debug("VM failed to start as expected."
"Error: %s", str(e))
check_msg_in_var_log_message(params, test)
result = utils_misc.wait_for(lambda: check_msg_in_var_log_message(params, test), timeout=20)
if not result:
log_config_path = params.get("log_file_path")
str_to_grep = params.get("str_to_grep")
test.fail("Check message log:%s failed in log file:%s" % (str_to_grep, log_config_path))
finally:
# Recover VM
LOG.info("Restoring vm...")
Expand Down

0 comments on commit 2a37fc7

Please sign in to comment.