Skip to content

Commit f309cd2

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 9fdc6b0 commit f309cd2

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

virttest/env_process.py

Lines changed: 36 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 sub-session, 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,35 @@ 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(
693+
session, message, dump_path, check=True, flags="-aP"
694+
):
695+
raise exceptions.TestFail(
696+
f"Missing expected message '{message}' in {vm.name} extra dump {dump_path}"
697+
)
698+
for message in params.get_list(
699+
f"unexpected_vm_extra_dump_{i}", delimiter=";"
700+
):
701+
LOG.info(f"Checking for unexpected message in {dump_path}")
702+
if ops.grep(session, message, dump_path, check=True, flags="-aP"):
703+
raise exceptions.TestFail(
704+
f"Redundant unexpected message '{message}' in {vm.name} extra dump {dump_path}"
705+
)
706+
707+
# Close all SSH sessions that might be active to this VM
708+
for s in vm.remote_sessions[:]:
709+
try:
710+
s.close()
711+
vm.remote_sessions.remove(s)
712+
except Exception:
713+
pass
714+
715+
utils_logfile.close_log_file()
691716

692717
if params.get("kill_vm") == "yes":
693718
kill_vm_timeout = float(params.get("kill_vm_timeout", 0))

0 commit comments

Comments
 (0)