Skip to content

Commit ddb7167

Browse files
committed
OpTestPstore.py:This patch checks for new files creation under /sys/fs/pstore
After triggering crash with kdump, it checks for new files creation under /sys/fs/pstore Signed-off-by: shirisha Ganta <[email protected]>
1 parent 7f03ffa commit ddb7167

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

testcases/OpTestPstore.py

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
1. Trigger crash.
33+
2. Check new files are created or not under /sys/fs/pstore
34+
'''
35+
36+
import time
37+
import subprocess
38+
import re
39+
import sys
40+
import pexpect
41+
import os
42+
import time
43+
44+
45+
from common.OpTestConstants import OpTestConstants as BMC_CONST
46+
from common.OpTestError import OpTestError
47+
from common.OpTestSOL import OpSOLMonitorThread
48+
from common import OpTestHMC, OpTestFSP
49+
50+
import unittest
51+
import OpTestConfiguration
52+
from common.OpTestSystem import OpSystemState
53+
from common.OpTestSSH import ConsoleState as SSHConnectionState
54+
from common.Exceptions import KernelOOPS, KernelKdump, KernelPanic, KernelFADUMP
55+
56+
import logging
57+
import OpTestLogger
58+
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
59+
60+
class OpTestPstore(unittest.TestCase):
61+
def setUp(self):
62+
conf = OpTestConfiguration.conf
63+
self.cv_SYSTEM = conf.system()
64+
self.cv_HOST = conf.host()
65+
self.platform = conf.platform()
66+
self.bmc_type = conf.args.bmc_type
67+
self.util = self.cv_SYSTEM.util
68+
self.con = self.cv_SYSTEM.console
69+
self.c = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
70+
71+
def kernel_crash(self):
72+
try:
73+
self.con.run_command( "echo c > /proc/sysrq-trigger")
74+
except (KernelOOPS, KernelKdump, KernelPanic, KernelFADUMP):
75+
self.cv_SYSTEM.goto_state(OpSystemState.OFF)
76+
self.cv_SYSTEM.goto_state(OpSystemState.OS)
77+
78+
def pstore_file_check(self):
79+
#This function will validate new files are created
80+
#or not under /sys/fs/pstore after crash
81+
time_init = self.con.run_command( "date +%s")
82+
result = self.con.run_command( 'ls -1 /sys/fs/pstore')
83+
l = []
84+
for line in result:
85+
files_list = "".join(re.findall("[a-zA-Z]",line))
86+
l.append(files_list)
87+
for i in result:
88+
self.con.run_command( "cd /sys/fs/pstore")
89+
time_created = self.con.run_command( "stat -c%%Z %s" % i)
90+
if (time_init > time_created):
91+
print("New file %s is created" % i)
92+
else:
93+
print("New file %s is not created" % i)
94+
95+
96+
class Pstore(OpTestPstore):
97+
98+
def setup_test(self):
99+
self.con.run_command( "which stty && stty cols 300; which stty && stty rows 30")
100+
self.con.run_command( "uname -a")
101+
res = self.con.run_command( "cat /etc/os-release | grep NAME | head -1")
102+
if 'SLES' in res[0].strip():
103+
self.distro = 'SLES'
104+
self.con.run_command( "sed -i -e 's/crashkernel=.* / /' -e 's/crashkernel=.*/\"/' /etc/default/grub")
105+
self.con.run_command( "grub2-mkconfig -o /boot/grub2/grub.cfg")
106+
self.con.run_command( "sync; sync; sleep 5")
107+
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")
108+
self.con.run_command( "grub2-mkconfig -o /boot/grub2/grub.cfg")
109+
self.con.run_command( "sync; sync; sleep 5")
110+
self.cv_SYSTEM.goto_state(OpSystemState.OFF)
111+
self.cv_SYSTEM.goto_state(OpSystemState.OS)
112+
elif 'Red Hat Enterprise Linux' in res[0].strip():
113+
self.distro = 'RHEL'
114+
else:
115+
self.skipTest("Currently test is supported only on sles and rhel")
116+
res = self.con.run_command( "systemctl status kdump.service | grep active")
117+
if 'exited' not in res[0].strip():
118+
print("Kdump service is not configured properly")
119+
120+
def runTest(self):
121+
self.setup_test()
122+
print("=================== Testing Kdump=======================")
123+
self.kernel_crash()
124+
self.pstore_file_check()
125+
print("=================Kdump Disable==========================")
126+
self.con.run_command("service kdump stop")
127+
self.con.run_command("echo 10 > /proc/sys/kernel/panic")
128+
self.kernel_crash()
129+
self.pstore_file_check()

0 commit comments

Comments
 (0)