Skip to content

Commit fc0bb78

Browse files
committed
Allow for configurable extra vm dump checks for present/absent messages
The typical use for this is when dumping extra logs and wanting to make sure certain information is always present (e.g. startup, etc.) and certain information is always absent (e.g. segfaults, etc.). It makes use of aexpect's linux ops as well as pattern matrching for grepping the expected or unexpected messages. Signed-off-by: Plamen Dimitrov <plamen.dimitrov@intra2net.com>
1 parent 71ee9a6 commit fc0bb78

1 file changed

Lines changed: 44 additions & 14 deletions

File tree

virttest/env_process.py

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import time
1313

1414
import six
15+
from aexpect import ops_linux as ops
1516
from aexpect import remote
1617
from avocado.core import exceptions
1718
from avocado.utils import archive
@@ -667,6 +668,49 @@ def postprocess_vm(test, params, env, name):
667668
serial_login=serial_login,
668669
)
669670

671+
if params.get("vm_extra_dump_paths") is not None:
672+
# even if there is previously existing session we cannot guarantee its state
673+
# is viable, e.g. it may be in python .env or SMTP sub-session, etc.
674+
if not vm.is_alive():
675+
LOG.warning("VM is not alive so we cannot download extra dump paths")
676+
else:
677+
session = vm.wait_for_login(timeout=vm.LOGIN_WAIT_TIMEOUT)
678+
vm_extra_dumps = os.path.join(test.outputdir, "vm_extra_dumps", vm.name)
679+
if not os.path.exists(vm_extra_dumps):
680+
os.makedirs(vm_extra_dumps)
681+
for i, dump_path in enumerate(
682+
params.get_list("vm_extra_dump_paths", delimiter=";")
683+
):
684+
try:
685+
vm.copy_files_from(dump_path, vm_extra_dumps)
686+
except:
687+
LOG.error(
688+
"Could not copy the extra dump '%s' from the vm '%s'",
689+
dump_path,
690+
vm.name,
691+
)
692+
if params.get_boolean(f"verify_vm_extra_dump_{i}"):
693+
for message in params.get_list(
694+
f"expected_vm_extra_dump_{i}", delimiter=";"
695+
):
696+
LOG.info(f"Checking for expected message in {dump_path}")
697+
if not ops.grep(
698+
session, message, dump_path, check=True, flags="-aP"
699+
):
700+
raise exceptions.TestFail(
701+
f"Missing expected message '{message}' in {vm.name} extra dump {dump_path}"
702+
)
703+
for message in params.get_list(
704+
f"unexpected_vm_extra_dump_{i}", delimiter=";"
705+
):
706+
LOG.info(f"Checking for unexpected message in {dump_path}")
707+
if ops.grep(
708+
session, message, dump_path, check=True, flags="-aP"
709+
):
710+
raise exceptions.TestFail(
711+
f"Redundant unexpected message '{message}' in {vm.name} extra dump {dump_path}"
712+
)
713+
670714
# Close all SSH sessions that might be active to this VM
671715
for s in vm.remote_sessions[:]:
672716
try:
@@ -677,20 +721,6 @@ def postprocess_vm(test, params, env, name):
677721

678722
utils_logfile.close_log_file()
679723

680-
if params.get("vm_extra_dump_paths") is not None:
681-
vm_extra_dumps = os.path.join(test.outputdir, "vm_extra_dumps")
682-
if not os.path.exists(vm_extra_dumps):
683-
os.makedirs(vm_extra_dumps)
684-
for dump_path in params.get("vm_extra_dump_paths").split(";"):
685-
try:
686-
vm.copy_files_from(dump_path, vm_extra_dumps)
687-
except:
688-
LOG.error(
689-
"Could not copy the extra dump '%s' from the vm '%s'",
690-
dump_path,
691-
vm.name,
692-
)
693-
694724
if params.get("kill_vm") == "yes":
695725
kill_vm_timeout = float(params.get("kill_vm_timeout", 0))
696726
if kill_vm_timeout:

0 commit comments

Comments
 (0)