1212import time
1313
1414import six
15+ from aexpect import ops_linux as ops
1516from aexpect import remote
1617from avocado .core import exceptions
1718from avocado .utils import archive
@@ -667,6 +668,60 @@ 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+ errors = []
685+ if params .get_boolean (f"verify_vm_extra_dump_{ i } " ):
686+ if vm .params ["os_type" ] == "windows" :
687+ LOG .warning (
688+ "Extra dump file validation is not supported on Windows"
689+ )
690+ LOG .info (f"Checking for expected messages in { dump_path } " )
691+ for message in params .get_list (
692+ f"expected_vm_extra_dump_{ i } " , delimiter = ";"
693+ ):
694+ if not ops .grep (
695+ session , message , dump_path , check = True , flags = "-aP"
696+ ):
697+ errors .append (
698+ f"Missing expected message '{ message } ' "
699+ f"in { vm .name } extra dump { dump_path } "
700+ )
701+ for message in params .get_list (
702+ f"unexpected_vm_extra_dump_{ i } " , delimiter = ";"
703+ ):
704+ if ops .grep (
705+ session , message , dump_path , check = True , flags = "-aP"
706+ ):
707+ errors .append (
708+ f"Redundant unexpected message '{ message } ' "
709+ f"in { vm .name } extra dump { dump_path } "
710+ )
711+ try :
712+ vm .copy_files_from (dump_path , vm_extra_dumps )
713+ except :
714+ LOG .error (
715+ "Could not copy the extra dump '%s' from the vm '%s'" ,
716+ dump_path ,
717+ vm .name ,
718+ )
719+ if errors :
720+ raise exceptions .TestFail (
721+ f"Errors during validation of log messages dumped "
722+ f"from { vm .name } :\n " + "\n " .join (errors )
723+ )
724+
670725 # Close all SSH sessions that might be active to this VM
671726 for s in vm .remote_sessions [:]:
672727 try :
@@ -677,20 +732,6 @@ def postprocess_vm(test, params, env, name):
677732
678733 utils_logfile .close_log_file ()
679734
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-
694735 if params .get ("kill_vm" ) == "yes" :
695736 kill_vm_timeout = float (params .get ("kill_vm_timeout" , 0 ))
696737 if kill_vm_timeout :
0 commit comments