diff options
author | Po-Hsu Lin <po-hsu.lin@canonical.com> | 2021-04-01 16:19:25 +0800 |
---|---|---|
committer | Po-Hsu Lin <po-hsu.lin@canonical.com> | 2021-04-01 16:19:25 +0800 |
commit | 0f213e2ab9068c939ac0f7c8a462fbd6f5604bdb (patch) | |
tree | 76dc37a8fec1578acf6c52a992f0521b089149b9 | |
parent | c013e2c9ae8526127e1a13bed7a32f0e09541ff3 (diff) |
Add kernel log check testphlin/add-dmesg-check
Add a test to check various error messages in dmesg. Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
-rwxr-xr-x | bin/kernel_log_check.py | 55 | ||||
-rw-r--r-- | units/miscellanea/jobs.pxu | 9 | ||||
-rw-r--r-- | units/miscellanea/test-plan.pxu | 7 |
3 files changed, 71 insertions, 0 deletions
diff --git a/bin/kernel_log_check.py b/bin/kernel_log_check.py new file mode 100755 index 0000000..22e88b1 --- /dev/null +++ b/bin/kernel_log_check.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +""" +Test to check if the kernel dmesg is free with error messages. + +Copyright (C) 2021 Canonical Ltd. + +Authors: + Po-Hsu Lin <po-hsu.lin@canonical.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +""" +import re +import os +import sys + +def main(): + '''Test for checking error patterns in log files''' + logfile = '/var/log/dmesg' + patterns = { + 'BUG': '\[ *\d+\.\d+\] kernel: BUG:.*', + 'Oops': '\[ *\d+\.\d+\] kernel: Oops:.*', + 'kernel BUG': '\[ *\d+\.\d+\] kernel: kernel BUG at.*', + 'WARNING': '\[ *\d+\.\d+\] kernel: WARNING:.*' + } + error = 0 + print('Checking error message in {}:'.format(logfile)) + if os.path.exists(logfile): + with open(logfile) as _file: + content = _file.read() + for pat in patterns: + print('Scanning for pattern "{}"'.format(pat)) + if re.search(patterns[pat], content): + print('Pattern found. Matching lines as follows:') + for item in re.finditer(patterns[pat], content): + print(item.group(0)) + error = 1 + else: + print('PASSED, log clean.') + else: + print('Log file was not found.') + error = 1 + return error + +if __name__ == '__main__': + sys.exit(main()) diff --git a/units/miscellanea/jobs.pxu b/units/miscellanea/jobs.pxu index 4772507..5e81f7b 100644 --- a/units/miscellanea/jobs.pxu +++ b/units/miscellanea/jobs.pxu @@ -199,6 +199,15 @@ command: kernel_taint_test.py plugin: shell category_id: com.canonical.plainbox::miscellanea +estimated_duration: 0.5 +id: miscellanea/kernel_log_check +_summary: Scan dmesg for errors +_description: + Check for BUG / Oops / kernel BUG / WARNING pattern in dmesg. +command: kernel_log_check.py + +plugin: shell +category_id: com.canonical.plainbox::miscellanea id: miscellanea/bmc_info requires: executable.name == 'ipmitool' diff --git a/units/miscellanea/test-plan.pxu b/units/miscellanea/test-plan.pxu index 60741b6..6abd628 100644 --- a/units/miscellanea/test-plan.pxu +++ b/units/miscellanea/test-plan.pxu @@ -94,3 +94,10 @@ mandatory_include: miscellanea/dmitest_server miscellanea/maas_user_check include: + +id: kernel-log-check +unit: test plan +_name: Kernel dmesg log check +_description: Kernel dmesg log check +include: + miscellanea/kernel_log_check |