Skip to content

Commit c476a2e

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 c476a2e

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

testcases/OpTestPstore.py

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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.con = self.cv_SYSTEM.console
65+
self.c = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
66+
67+
def kernel_crash(self):
68+
try:
69+
self.con.run_command( "echo c > /proc/sysrq-trigger")
70+
except (KernelOOPS, KernelKdump, KernelPanic, KernelFADUMP):
71+
self.cv_SYSTEM.goto_state(OpSystemState.OFF)
72+
self.cv_SYSTEM.goto_state(OpSystemState.OS)
73+
74+
def pstore_file_check(self):
75+
#This function will validate new files are created
76+
#or not under /sys/fs/pstore after crash
77+
time_init = self.con.run_command( "date +%s")
78+
result = self.con.run_command( 'ls -1 /sys/fs/pstore')
79+
l = []
80+
for line in result:
81+
files_list = "".join(re.findall("[a-zA-Z]",line))
82+
l.append(files_list)
83+
for i in result:
84+
self.con.run_command( "cd /sys/fs/pstore")
85+
time_created = self.con.run_command( "stat -c%%Z %s" % i)
86+
if (time_init > time_created):
87+
print("New file %s is created" % i)
88+
else:
89+
print("New file %s is not created" % i)
90+
91+
92+
class Pstore(OpTestPstore):
93+
94+
def setup_test(self):
95+
self.con.run_command( "which stty && stty cols 300; which stty && stty rows 30")
96+
self.con.run_command( "uname -a")
97+
res = self.con.run_command( "cat /etc/os-release | grep NAME | head -1")
98+
if 'SLES' in res[0].strip():
99+
self.distro = 'SLES'
100+
self.con.run_command( "sed -i -e 's/crashkernel=.* / /' -e 's/crashkernel=.*/\"/' /etc/default/grub")
101+
self.con.run_command( "grub2-mkconfig -o /boot/grub2/grub.cfg")
102+
self.con.run_command( "sync; sync; sleep 5")
103+
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")
104+
self.con.run_command( "grub2-mkconfig -o /boot/grub2/grub.cfg")
105+
self.con.run_command( "sync; sync; sleep 5")
106+
self.cv_SYSTEM.goto_state(OpSystemState.OFF)
107+
self.cv_SYSTEM.goto_state(OpSystemState.OS)
108+
elif 'Red Hat Enterprise Linux' in res[0].strip():
109+
self.distro = 'RHEL'
110+
else:
111+
self.skipTest("Currently test is supported only on sles and rhel")
112+
res = self.con.run_command( "systemctl status kdump.service | grep active")
113+
if 'exited' not in res[0].strip():
114+
print("Kdump service is not configured properly")
115+
116+
def runTest(self):
117+
self.setup_test()
118+
print("=================== Testing Kdump=======================")
119+
self.kernel_crash()
120+
self.pstore_file_check()
121+
print("=================Kdump Disable==========================")
122+
self.con.run_command("service kdump stop")
123+
self.con.run_command("echo 10 > /proc/sys/kernel/panic")
124+
self.kernel_crash()
125+
self.pstore_file_check()

0 commit comments

Comments
 (0)