Skip to content

Commit 7dba010

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.). Signed-off-by: Plamen Dimitrov <plamen.dimitrov@intra2net.com>
1 parent de845c0 commit 7dba010

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

virttest/env_process.py

Lines changed: 34 additions & 11 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
@@ -665,21 +666,16 @@ def postprocess_vm(test, params, env, name):
665666
serial_login=serial_login,
666667
)
667668

668-
# Close all SSH sessions that might be active to this VM
669-
for s in vm.remote_sessions[:]:
670-
try:
671-
s.close()
672-
vm.remote_sessions.remove(s)
673-
except Exception:
674-
pass
675-
676-
utils_logfile.close_log_file()
677-
678669
if params.get("vm_extra_dump_paths") is not None:
670+
# even if there is previously existing session we cannot guarantee its state
671+
# is viable, e.g. it may be in python .env or SMTP subsession, etc.
672+
session = vm.wait_for_login(timeout=vm.LOGIN_WAIT_TIMEOUT)
679673
vm_extra_dumps = os.path.join(test.outputdir, "vm_extra_dumps")
680674
if not os.path.exists(vm_extra_dumps):
681675
os.makedirs(vm_extra_dumps)
682-
for dump_path in params.get("vm_extra_dump_paths").split(";"):
676+
for i, dump_path in enumerate(
677+
params.get_list("vm_extra_dump_paths", delimiter=";")
678+
):
683679
try:
684680
vm.copy_files_from(dump_path, vm_extra_dumps)
685681
except:
@@ -688,6 +684,33 @@ def postprocess_vm(test, params, env, name):
688684
dump_path,
689685
vm.name,
690686
)
687+
if params.get_boolean(f"verify_vm_extra_dump_{i}"):
688+
for message in params.get_list(
689+
f"expected_vm_extra_dump_{i}", delimiter=";"
690+
):
691+
LOG.info(f"Checking for expected message in {dump_path}")
692+
if not ops.grep(session, message, dump_path, check=True, flags="-aP"):
693+
raise exceptions.TestFail(
694+
f"Missing expected message '{message}' in {vm.name} extra dump {dump_path}"
695+
)
696+
for message in params.get_list(
697+
f"unexpected_vm_extra_dump_{i}", delimiter=";"
698+
):
699+
LOG.info(f"Checking for unexpected message in {dump_path}")
700+
if ops.grep(session, message, dump_path, check=True, flags="-aP"):
701+
raise exceptions.TestFail(
702+
f"Redundant unexpected message '{message}' in {vm.name} extra dump {dump_path}"
703+
)
704+
705+
# Close all SSH sessions that might be active to this VM
706+
for s in vm.remote_sessions[:]:
707+
try:
708+
s.close()
709+
vm.remote_sessions.remove(s)
710+
except Exception:
711+
pass
712+
713+
utils_logfile.close_log_file()
691714

692715
if params.get("kill_vm") == "yes":
693716
kill_vm_timeout = float(params.get("kill_vm_timeout", 0))

0 commit comments

Comments
 (0)