Skip to content

Commit 9b68adf

Browse files
committed
fix conditional issue and check all possible substring locations to detect serial console enabled
1 parent 2951df2 commit 9b68adf

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

microsoft/testsuites/core/azure_image_standard.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -798,68 +798,69 @@ def verify_repository_installed(self, node: Node) -> None: # noqa: C901
798798

799799
@TestCaseMetadata(
800800
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.
803802
804803
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.
807806
2. Check expected setting from kernel command line.
808807
2.1. Expected to see 'console=ttyAMA0' for aarch64.
809808
2.2. Expected to see 'console=ttyS0' for x86_64.
809+
2.3. Expected to see 'uart0: console 115200,n,8,1 for FreeBSD.
810810
""",
811811
priority=1,
812812
requirement=simple_requirement(supported_platform_type=[AZURE, READY]),
813813
)
814814
def verify_serial_console_is_enabled(self, node: Node) -> None:
815-
console_device = {
816-
CpuArchitecture.X64: "ttyS0",
817-
CpuArchitecture.ARM64: "ttyAMA0",
818-
}
819815
if isinstance(node.os, CBLMariner):
820816
if node.os.information.version < "2.0.0":
821817
raise SkippedException(
822818
"CBLMariner 1.0 has a known 'wont fix' issue with this test"
823819
)
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+
}
847824
lscpu = node.tools[Lscpu]
848825
arch = lscpu.get_architecture()
849826
current_console_device = console_device[arch]
850827
console_enabled_pattern = re.compile(
851828
rf"^(.*console \[{current_console_device}\] enabled.*)$", re.M
852829
)
853830
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+
pattern_found = False
833+
834+
if isinstance(node.os, CBLMariner) or (
835+
isinstance(node.os, Ubuntu) and node.os.information.version >= "22.10.0"
836+
):
837+
log_output = node.tools[Dmesg].get_output()
838+
if any(find_patterns_in_lines(log_output, patterns)):
839+
pattern_found = True
840+
else:
841+
log_sources = [
842+
("/var/log/syslog", node.tools[Cat]),
843+
("/var/log/messages", node.tools[Cat]),
844+
]
845+
journalctl_tool = node.tools[Journalctl]
846+
for log_file, tool in log_sources:
847+
if node.shell.exists(node.get_pure_path(log_file)):
848+
current_log_output = tool.read(log_file, force_run=True, sudo=True)
849+
if current_log_output:
850+
if any(find_patterns_in_lines(current_log_output, patterns)):
851+
pattern_found = True
852+
break
853+
if not pattern_found and journalctl_tool._check_exists():
854+
current_log_output = journalctl_tool.first_n_logs_from_boot()
855+
if current_log_output:
856+
if any(find_patterns_in_lines(current_log_output, patterns)):
857+
pattern_found = True
858+
if not pattern_found:
858859
raise LisaException(
859860
"Fail to find console enabled line "
860861
f"'console [{current_console_device}] enabled' "
861862
"or 'uart0: console (115200,n,8,1)' "
862-
f"from {log_file} output",
863+
"from any log output"
863864
)
864865

865866
@TestCaseMetadata(

0 commit comments

Comments
 (0)