From b63da25ad9ad3649631dcf3b491545e3de9ad77c Mon Sep 17 00:00:00 2001 From: Umang Francis Date: Thu, 13 Feb 2025 14:57:44 +0530 Subject: [PATCH] changes to check kernel errors using function call --- lisa/node.py | 16 +++++++++++++++- lisa/platform_.py | 1 + lisa/schema.py | 2 ++ lisa/testsuite.py | 9 +++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lisa/node.py b/lisa/node.py index 1c89825eea..4d19b3c562 100644 --- a/lisa/node.py +++ b/lisa/node.py @@ -24,7 +24,7 @@ from lisa.nic import Nics, NicsBSD from lisa.operating_system import OperatingSystem from lisa.secret import add_secret -from lisa.tools import Chmod, Df, Echo, Lsblk, Mkfs, Mount, Reboot, Uname, Wsl +from lisa.tools import Chmod, Df, Dmesg, Echo, Lsblk, Mkfs, Mount, Reboot, Uname, Wsl from lisa.tools.mkfs import FileSystem from lisa.util import ( ContextMixin, @@ -110,6 +110,7 @@ def __init__( self._support_sudo: Optional[bool] = None self._is_dirty: bool = False self.capture_boot_time: bool = False + self.assert_kernel_error: bool = False self.capture_azure_information: bool = False self.capture_kernel_config: bool = False self.has_checked_bash_prompt: bool = False @@ -501,6 +502,19 @@ def get_information(self) -> Dict[str, str]: return final_information + def exec_check_dmesg_oops(self) -> bool: + try: + dmesg = self.tools[Dmesg] + results = dmesg.check_kernel_errors(force_run=True, throw_error=False) + if results: + # If there are any results obtained from the Kernel Error Check, then return True + return True + else: + return False + except LisaException as ex: + self.log.error(f"Error: {ex}") + return True + def expand_env_path(self, raw_path: str) -> str: echo = self.tools[Echo] result = echo.run(raw_path, shell=True) diff --git a/lisa/platform_.py b/lisa/platform_.py index 65547a0e2e..89943fccba 100644 --- a/lisa/platform_.py +++ b/lisa/platform_.py @@ -195,6 +195,7 @@ def deploy_environment(self, environment: Environment) -> None: node.features = Features(node, self) node.capture_azure_information = platform_runbook.capture_azure_information node.capture_boot_time = platform_runbook.capture_boot_time + node.assert_kernel_error = platform_runbook.assert_kernel_error node.capture_kernel_config = ( platform_runbook.capture_kernel_config_information ) diff --git a/lisa/schema.py b/lisa/schema.py index 6f9c592d5f..ba9db234d6 100644 --- a/lisa/schema.py +++ b/lisa/schema.py @@ -1444,6 +1444,8 @@ class Platform(TypedSchema, ExtendableSchemaMixin): capture_azure_information: bool = False # capture boot time info or not capture_boot_time: bool = False + # to check if dmesg logs need to be analyzed after each test case + assert_kernel_error: bool # capture kernel config info or not capture_kernel_config_information: bool = False capture_vm_information: bool = True diff --git a/lisa/testsuite.py b/lisa/testsuite.py index 092ca5ea74..d223f926a0 100644 --- a/lisa/testsuite.py +++ b/lisa/testsuite.py @@ -857,10 +857,19 @@ def __run_case( test_kwargs=test_kwargs, ) case_result.set_status(TestStatus.PASSED, "") + if node.assert_kernel_error: + nodes = case_result.environment.nodes + for node in nodes.list(): + self.__node_kernel_error_check(node, log) except Exception as identifier: case_result.handle_exception(exception=identifier, log=log) log.debug(f"case end in {timer}") + def __node_kernel_error_check(self, node: schema.NodeSpace, log: Logger) -> None: + dmesg_check_result = node.exec_check_dmesg_oops()[0] + if dmesg_check_result: + raise LisaException(f"failed. Kernel Errors found in the DMesg logs after test case execution. Please check the same!") + def get_suites_metadata() -> Dict[str, TestSuiteMetadata]: return _all_suites