|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# IBM_PROLOG_BEGIN_TAG |
| 3 | +# This is an automatically generated prolog. |
| 4 | +# |
| 5 | +# $Source: op-test-framework/testcases/OpTestPstore.py $ |
| 6 | +# |
| 7 | +# OpenPOWER Automated Test Project |
| 8 | +# |
| 9 | +# Contributors Listed Below - COPYRIGHT 2020 |
| 10 | +# [+] International Business Machines Corp. |
| 11 | +# |
| 12 | +# |
| 13 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | +# you may not use this file except in compliance with the License. |
| 15 | +# You may obtain a copy of the License at |
| 16 | +# |
| 17 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | +# |
| 19 | +# Unless required by applicable law or agreed to in writing, software |
| 20 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 22 | +# implied. See the License for the specific language governing |
| 23 | +# permissions and limitations under the License. |
| 24 | +# |
| 25 | +# IBM_PROLOG_END_TAG |
| 26 | + |
| 27 | +''' |
| 28 | +OpTestPstore |
| 29 | +------------ |
| 30 | +
|
| 31 | +This module can contain testcases related to Pstore. |
| 32 | +
|
| 33 | +1. Check Pstore is configured properly or not |
| 34 | +2. Trigger crash. |
| 35 | +3. Check new files are created or not under /sys/fs/pstore |
| 36 | +4. Enable FADUMP |
| 37 | +''' |
| 38 | + |
| 39 | +import time |
| 40 | +import subprocess |
| 41 | +import re |
| 42 | +import sys |
| 43 | +import pexpect |
| 44 | +import os |
| 45 | +import time |
| 46 | + |
| 47 | + |
| 48 | +from common.OpTestConstants import OpTestConstants as BMC_CONST |
| 49 | +from common.OpTestError import OpTestError |
| 50 | +from common.OpTestSOL import OpSOLMonitorThread |
| 51 | +from common import OpTestHMC, OpTestFSP |
| 52 | + |
| 53 | +import unittest |
| 54 | +import OpTestConfiguration |
| 55 | +from common.OpTestSystem import OpSystemState |
| 56 | +from common.OpTestSSH import ConsoleState as SSHConnectionState |
| 57 | +from common.Exceptions import KernelOOPS, KernelKdump, KernelPanic, KernelFADUMP |
| 58 | + |
| 59 | +import logging |
| 60 | +import OpTestLogger |
| 61 | +log = OpTestLogger.optest_logger_glob.get_logger(__name__) |
| 62 | + |
| 63 | +class OpTestKernelBase(unittest.TestCase): |
| 64 | + def setUp(self): |
| 65 | + conf = OpTestConfiguration.conf |
| 66 | + self.cv_SYSTEM = conf.system() |
| 67 | + self.cv_HOST = conf.host() |
| 68 | + self.platform = conf.platform() |
| 69 | + self.bmc_type = conf.args.bmc_type |
| 70 | + self.util = self.cv_SYSTEM.util |
| 71 | + self.con = self.cv_SYSTEM.console |
| 72 | + self.c = self.cv_SYSTEM.cv_HOST.get_ssh_connection() |
| 73 | + |
| 74 | + def pstore_check(self): |
| 75 | + #This function will check pstore is configured properly or not |
| 76 | + res = self.con.run_command( "cat /boot/config-`uname -r` | grep -i --color=never 'CONFIG_PSTORE=y'") |
| 77 | + print(res) |
| 78 | + if(res[0]!='CONFIG_PSTORE=y'): |
| 79 | + self.fail("PSTORE is not configured") |
| 80 | + |
| 81 | + def kernel_crash(self): |
| 82 | + #1. This function will trigger a Crash |
| 83 | + #2. Check for lpar or baremetal |
| 84 | + try: |
| 85 | + self.con.run_command( "echo c > /proc/sysrq-trigger") |
| 86 | + except (KernelOOPS, KernelKdump, KernelPanic, KernelFADUMP): |
| 87 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 88 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 89 | + res = self.con.run_command("tail /proc/cpuinfo | grep platform| awk -F : '{print $2}'") |
| 90 | + if 'pSeries' in res[0].strip(): |
| 91 | + self.pstore_file_check(['dmesgnvram', 'rtasnvram', 'powerpcofwnvram', 'powerpccommonnvram']) |
| 92 | + elif 'PowerNV' in res[0].strip(): |
| 93 | + self.pstore_file_check(['dmesgnvram', 'powerpcopalnvram', 'powerpccommonnvram']) |
| 94 | + |
| 95 | + def pstore_file_check(self, param): |
| 96 | + #This function will validate new files are created |
| 97 | + #or not under /sys/fs/pstore after crash |
| 98 | + time_init = self.con.run_command( "date +%s") |
| 99 | + result = self.con.run_command( 'ls -1 /sys/fs/pstore') |
| 100 | + l = [] |
| 101 | + for line in result: |
| 102 | + files_list = "".join(re.findall("[a-zA-Z]",line)) |
| 103 | + l.append(files_list) |
| 104 | + for files in param: |
| 105 | + if files not in l: |
| 106 | + self.fail("New %s is not created" % files) |
| 107 | + for i in result: |
| 108 | + self.con.run_command( "cd /sys/fs/pstore") |
| 109 | + time_created = self.con.run_command( "stat -c%%Z %s" % i) |
| 110 | + if (time_init > time_created): |
| 111 | + print("New file %s is created" % i) |
| 112 | + else: |
| 113 | + print("New file %s is not created" % i) |
| 114 | + |
| 115 | + def setup_fadump(self): |
| 116 | + if self.distro == 'SLES': |
| 117 | + self.con.run_command( 'sed -i \'/^KDUMP_SAVEDIR=/c\KDUMP_SAVEDIR=\/var\/crash\' /etc/sysconfig/kdump;') |
| 118 | + self.con.run_command( "sed -i 's/KDUMP_FADUMP=\"no\"/KDUMP_FADUMP=\"yes\"/' /etc/sysconfig/kdump;") |
| 119 | + self.con.run_command( "touch /etc/sysconfig/kdump; systemctl restart kdump.service; sync", timeout=600) |
| 120 | + elif self.distro == 'RHEL': |
| 121 | + self.con.run_command( "which stty && stty cols 300; which stty && stty rows 30") |
| 122 | + self.con.run_command( "grubby --args=\"fadump=on crashkernel=2G-128G:2048M,128G-:8192M\" --update-kernel=/boot/vmlinuz-`uname -r`") |
| 123 | + self.con.run_command( "sync; sync;") |
| 124 | + time.sleep(5) |
| 125 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 126 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 127 | + res = self.con.run_command( "systemctl status kdump.service | grep active") |
| 128 | + if 'exited' not in res[0].strip(): |
| 129 | + print("Fadump service is not configured properly") |
| 130 | + |
| 131 | +class KernelCrash_Kdump(OpTestKernelBase): |
| 132 | + |
| 133 | + def setup_test(self): |
| 134 | + self.con.run_command( "which stty && stty cols 300; which stty && stty rows 30") |
| 135 | + self.con.run_command( "uname -a") |
| 136 | + res = self.con.run_command( "cat /etc/os-release | grep NAME | head -1") |
| 137 | + if 'SLES' in res[0].strip(): |
| 138 | + self.distro = 'SLES' |
| 139 | + self.con.run_command( "sed -i -e 's/crashkernel=.* / /' -e 's/crashkernel=.*/\"/' /etc/default/grub") |
| 140 | + self.con.run_command( "grub2-mkconfig -o /boot/grub2/grub.cfg") |
| 141 | + self.con.run_command( "sync; sync; sleep 5") |
| 142 | + self.con.run_command( "sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/s/\"$/ crashkernel=2G-4G:512M,4G-64G:1024M,64G-128G:2048M,128G-:4096M\"/' /etc/default/grub") |
| 143 | + self.con.run_command( "grub2-mkconfig -o /boot/grub2/grub.cfg") |
| 144 | + self.con.run_command( "sync; sync; sleep 5") |
| 145 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 146 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 147 | + elif 'Red Hat Enterprise Linux' in res[0].strip(): |
| 148 | + self.distro = 'RHEL' |
| 149 | + else: |
| 150 | + self.skipTest("Currently test is supported only on sles and rhel") |
| 151 | + res = self.con.run_command( "systemctl status kdump.service | grep active") |
| 152 | + if 'exited' not in res[0].strip(): |
| 153 | + print("Kdump service is not configured properly") |
| 154 | + |
| 155 | + def runTest(self): |
| 156 | + self.setup_test() |
| 157 | + self.pstore_check() |
| 158 | + print("=================== Testing Kdump=======================") |
| 159 | + self.kernel_crash() |
| 160 | + print("=================Kdump Disable==========================") |
| 161 | + self.con.run_command("service kdump stop") |
| 162 | + self.con.run_command("echo 10 > /proc/sys/kernel/panic") |
| 163 | + self.kernel_crash() |
| 164 | + print("=================Enable fadump====================") |
| 165 | + self.setup_fadump() |
| 166 | + self.kernel_crash() |
| 167 | + print("===============Disable fadump=====================") |
| 168 | + self.con.run_command("service kdump stop") |
| 169 | + self.con.run_command("echo 10 > /proc/sys/kernel/panic") |
| 170 | + self.kernel_crash() |
| 171 | + |
| 172 | + |
| 173 | +def crash_suite(): |
| 174 | + s = unittest.TestSuite() |
| 175 | + s.addTest(KernelCrash_Kdump()) |
| 176 | + return s |
0 commit comments