@@ -798,68 +798,79 @@ def verify_repository_installed(self, node: Node) -> None: # noqa: C901
798
798
799
799
@TestCaseMetadata (
800
800
description = """
801
- This test will check the serial console is enabled from kernel command line
802
- in dmesg.
801
+ This test will check the serial console is enabled from kernel command line.
803
802
804
803
Steps:
805
- 1. Get the kernel command line from /var/log/messages or
806
- /var/log/syslog output.
804
+ 1. Get the kernel command line from /var/log/messages, /var/log/syslog,
805
+ dmesg, or journalctl output.
807
806
2. Check expected setting from kernel command line.
808
807
2.1. Expected to see 'console=ttyAMA0' for aarch64.
809
808
2.2. Expected to see 'console=ttyS0' for x86_64.
809
+ 2.3. Expected to see 'uart0: console 115200,n,8,1 for FreeBSD.
810
810
""" ,
811
811
priority = 1 ,
812
812
requirement = simple_requirement (supported_platform_type = [AZURE , READY ]),
813
813
)
814
814
def verify_serial_console_is_enabled (self , node : Node ) -> None :
815
- console_device = {
816
- CpuArchitecture .X64 : "ttyS0" ,
817
- CpuArchitecture .ARM64 : "ttyAMA0" ,
818
- }
819
815
if isinstance (node .os , CBLMariner ):
820
816
if node .os .information .version < "2.0.0" :
821
817
raise SkippedException (
822
818
"CBLMariner 1.0 has a known 'wont fix' issue with this test"
823
819
)
824
- if isinstance (node .os , CBLMariner ) or (
825
- isinstance (node .os , Ubuntu ) and node .os .information .version >= "22.10.0"
826
- ):
827
- log_output = node .tools [Dmesg ].get_output ()
828
- log_file = "dmesg"
829
- else :
830
- cat = node .tools [Cat ]
831
- if node .shell .exists (node .get_pure_path ("/var/log/messages" )):
832
- log_file = "/var/log/messages"
833
- log_output = cat .read (log_file , force_run = True , sudo = True )
834
- elif node .shell .exists (node .get_pure_path ("/var/log/syslog" )):
835
- log_file = "/var/log/syslog"
836
- log_output = cat .read (log_file , force_run = True , sudo = True )
837
- else :
838
- log_file = "journalctl"
839
- journalctl = node .tools [Journalctl ]
840
- log_output = journalctl .first_n_logs_from_boot ()
841
- if not log_output :
842
- raise LisaException (
843
- "Neither /var/log/messages nor /var/log/syslog found."
844
- "and journal ctl log is empty."
845
- )
846
-
820
+ console_device = {
821
+ CpuArchitecture .X64 : "ttyS0" ,
822
+ CpuArchitecture .ARM64 : "ttyAMA0" ,
823
+ }
847
824
lscpu = node .tools [Lscpu ]
848
825
arch = lscpu .get_architecture ()
849
826
current_console_device = console_device [arch ]
850
827
console_enabled_pattern = re .compile (
851
828
rf"^(.*console \[{ current_console_device } \] enabled.*)$" , re .M
852
829
)
853
830
freebsd_pattern = re .compile (r"^(.*uart0: console \(115200,n,8,1\).*)$" , re .M )
854
- result = find_patterns_in_lines (
855
- log_output , [console_enabled_pattern , freebsd_pattern ]
856
- )
857
- if not (result [0 ] or result [1 ]):
831
+ patterns = [console_enabled_pattern , freebsd_pattern ]
832
+ logs_checked = []
833
+ pattern_found = False
834
+ # Check dmesg output for the patterns if certain OS detected
835
+ if isinstance (node .os , CBLMariner ) or (
836
+ isinstance (node .os , Ubuntu ) and node .os .information .version >= "22.10.0"
837
+ ):
838
+ dmesg_tool = node .tools [Dmesg ]
839
+ log_output = dmesg_tool .get_output ()
840
+ logs_checked .append (f"{ dmesg_tool .command } " )
841
+ if any (find_patterns_in_lines (log_output , patterns )):
842
+ pattern_found = True
843
+ else :
844
+ # Check each log source, if it is accessible, for the defined patterns
845
+ # If log files can be read, add to list of logs checked
846
+ # If pattern detected, break out of loop and pass test
847
+ log_sources = [
848
+ ("/var/log/syslog" , node .tools [Cat ]),
849
+ ("/var/log/messages" , node .tools [Cat ]),
850
+ ]
851
+ for log_file , tool in log_sources :
852
+ if node .shell .exists (node .get_pure_path (log_file )):
853
+ current_log_output = tool .read (log_file , force_run = True , sudo = True )
854
+ if current_log_output :
855
+ logs_checked .append (log_file )
856
+ if any (find_patterns_in_lines (current_log_output , patterns )):
857
+ pattern_found = True
858
+ break
859
+ # Check journalctl logs if patterns were not found in other log sources
860
+ journalctl_tool = node .tools [Journalctl ]
861
+ if not pattern_found and journalctl_tool .exists :
862
+ current_log_output = journalctl_tool .first_n_logs_from_boot ()
863
+ if current_log_output :
864
+ logs_checked .append (f"{ journalctl_tool .command } " )
865
+ if any (find_patterns_in_lines (current_log_output , patterns )):
866
+ pattern_found = True
867
+ # Raise an exception if the patterns were not found in any of the checked logs
868
+ if not pattern_found :
858
869
raise LisaException (
859
870
"Fail to find console enabled line "
860
871
f"'console [{ current_console_device } ] enabled' "
861
872
"or 'uart0: console (115200,n,8,1)' "
862
- f"from { log_file } output" ,
873
+ f"from { ', ' . join ( logs_checked ) } output"
863
874
)
864
875
865
876
@TestCaseMetadata (
0 commit comments