Skip to content

Commit 85b517b

Browse files
committed
Moved the necessary functions to ipmi library OpTestIPMI.py, and also
added @param for missed input arguments.
1 parent d6bcb2d commit 85b517b

8 files changed

+808
-1
lines changed

bvt/op-opal-fvt.xml

+37
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,43 @@
3636
</testcase>
3737
</test>
3838

39+
<test>
40+
<testcase>
41+
<cmd>op-ci-bmc-run "op_opal_fvt.test_hmi_proc_recv_done()"</cmd>
42+
<exitonerror>yes</exitonerror>
43+
</testcase>
44+
</test>
45+
<test>
46+
<testcase>
47+
<cmd>op-ci-bmc-run "op_opal_fvt.test_hmi_proc_recv_error_masked()"</cmd>
48+
<exitonerror>yes</exitonerror>
49+
</testcase>
50+
</test>
51+
<test>
52+
<testcase>
53+
<cmd>op-ci-bmc-run "op_opal_fvt.test_hmi_malfunction_alert()"</cmd>
54+
<exitonerror>yes</exitonerror>
55+
</testcase>
56+
</test>
57+
<test>
58+
<testcase>
59+
<cmd>op-ci-bmc-run "op_opal_fvt.clear_gard_entries()"</cmd>
60+
<exitonerror>yes</exitonerror>
61+
</testcase>
62+
</test>
63+
<test>
64+
<testcase>
65+
<cmd>op-ci-bmc-run "op_opal_fvt.test_hmi_hypervisor_resource_error()"</cmd>
66+
<exitonerror>yes</exitonerror>
67+
</testcase>
68+
</test>
69+
<test>
70+
<testcase>
71+
<cmd>op-ci-bmc-run "op_opal_fvt.clear_gard_entries()"</cmd>
72+
<exitonerror>yes</exitonerror>
73+
</testcase>
74+
</test>
75+
3976
<test>
4077
<testcase>
4178
<cmd>op-ci-bmc-run "op_opal_fvt.test_i2c_driver()"</cmd>

ci/source/op_opal_fvt.py

+43
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
sys.path.append(full_path)
4545
import ConfigParser
4646

47+
from common.OpTestConstants import OpTestConstants as BMC_CONST
4748
from testcases.OpTestSensors import OpTestSensors
4849
from testcases.OpTestSwitchEndianSyscall import OpTestSwitchEndianSyscall
4950
from testcases.OpTestHeartbeat import OpTestHeartbeat
@@ -52,6 +53,7 @@
5253
from testcases.OpTestI2Cdriver import OpTestI2Cdriver
5354
from testcases.OpTestMtdPnorDriver import OpTestMtdPnorDriver
5455
from testcases.OpTestInbandIPMI import OpTestInbandIPMI
56+
from testcases.OpTestHMIHandling import OpTestHMIHandling
5557

5658

5759
def _config_read():
@@ -128,6 +130,12 @@ def _config_read():
128130
testCfg['ffdcdir'], lparCfg['lparip'],
129131
lparCfg['lparuser'], lparCfg['lparpasswd'])
130132

133+
opTestHMIHandling = OpTestHMIHandling(bmcCfg['ip'], bmcCfg['username'],
134+
bmcCfg['password'],
135+
bmcCfg['usernameipmi'],
136+
bmcCfg['passwordipmi'],
137+
testCfg['ffdcdir'], lparCfg['lparip'],
138+
lparCfg['lparuser'], lparCfg['lparpasswd'])
131139

132140
def test_init():
133141
"""This function validates the test config before running other functions
@@ -192,9 +200,44 @@ def test_mtd_pnor_driver():
192200
"""
193201
return opTestMtdPnorDriver.testMtdPnorDriver()
194202

203+
195204
def test_ipmi_inband_functionality():
196205
"""This function tests whether the kopald service is running in platform OS
197206
returns: int 0-success, raises exception-error
198207
"""
199208
return opTestInbandIPMI.test_ipmi_inband_functionality()
200209

210+
211+
def test_hmi_proc_recv_done():
212+
"""This function tests HMI recoverable error: processor recovery done
213+
returns: int 0-success, raises exception-error
214+
"""
215+
return opTestHMIHandling.testHMIHandling(BMC_CONST.HMI_PROC_RECV_DONE)
216+
217+
def test_hmi_proc_recv_error_masked():
218+
"""This function tests HMI recoverable error: proc_recv_error_masked
219+
returns: int 0-success, raises exception-error
220+
"""
221+
return opTestHMIHandling.testHMIHandling(BMC_CONST.HMI_PROC_RECV_ERROR_MASKED)
222+
223+
224+
def clear_gard_entries():
225+
"""This function reboots the system and then clears any hardware gards through gard utility.
226+
And finally reboots the system again to stable point.
227+
returns: int 0-success, raises exception-error
228+
"""
229+
return opTestHMIHandling.clearGardEntries()
230+
231+
232+
def test_hmi_malfunction_alert():
233+
"""This function tests HMI Malfunction alert: Core checkstop functionality
234+
returns: int 0-success, raises exception-error
235+
"""
236+
return opTestHMIHandling.testHMIHandling(BMC_CONST.HMI_MALFUNCTION_ALERT)
237+
238+
239+
def test_hmi_hypervisor_resource_error():
240+
"""This function tests HMI: Hypervisor resource error functionality
241+
returns: int 0-success, raises exception-error
242+
"""
243+
return opTestHMIHandling.testHMIHandling(BMC_CONST.HMI_HYPERVISOR_RESOURCE_ERROR)

ci/source/test_opal_fvt.py

+15
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,18 @@ def test_mtdpnor_driver():
5555
def test_ipmi_inband_functionality():
5656
assert op_opal_fvt.test_ipmi_inband_functionality() == 0
5757

58+
def test_hmi_proc_recv_done():
59+
assert op_opal_fvt.test_hmi_proc_recv_done() == 0
60+
61+
def test_hmi_proc_recv_error_masked():
62+
assert op_opal_fvt.test_hmi_proc_recv_error_masked() == 0
63+
64+
def test_hmi_malfunction_alert():
65+
assert op_opal_fvt.test_hmi_malfunction_alert() == 0
66+
67+
def test_hmi_hypervisor_resource_error():
68+
assert op_opal_fvt.test_hmi_hypervisor_resource_error() == 0
69+
70+
def test_clearing_gard_entries():
71+
assert op_opal_fvt.clear_gard_entries() == 0
72+

common/OpTestConstants.py

+34
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
# This class encapsulates commands and constants which deals with the BMC in OpenPower
3131
# systems
3232

33+
import pexpect
34+
3335
class OpTestConstants():
3436

3537
# Platforms
@@ -135,3 +137,35 @@ class OpTestConstants():
135137
SCP_TO_REMOTE = 1
136138
SCP_TO_LOCAL = 2
137139

140+
# Constants related to ipmi console interfaces
141+
IPMI_SOL_ACTIVATE_TIME = 5
142+
IPMI_SOL_DEACTIVATE_TIME = 10
143+
IPMI_WAIT_FOR_TERMINATING_SESSION = 10
144+
IPMI_CON_DELAY_BEFORE_SEND = 0.9
145+
146+
IPMI_SOL_CONSOLE_ACTIVATE_OUTPUT = ["[SOL Session operational. Use ~? for help]\r\n", \
147+
"Error: Unable to establish IPMI v2 / RMCP+ session", \
148+
pexpect.TIMEOUT, pexpect.EOF]
149+
IPMI_CONSOLE_EXPECT_ENTER_OUTPUT = ["login: ", "#", "/ #", "Petitboot", pexpect.TIMEOUT, pexpect.EOF]
150+
IPMI_CONSOLE_EXPECT_LOGIN = 0
151+
IPMI_CONSOLE_EXPECT_PASSWORD = 0
152+
IPMI_CONSOLE_EXPECT_PETITBOOT = [2,3]
153+
IPMI_CONSOLE_EXPECT_RANDOM_STATE = [4,5]
154+
IPMI_LPAR_UNIQUE_PROMPT = "PS1=[pexpect]#"
155+
IPMI_LPAR_EXPECT_PEXPECT_PROMPT = "[pexpect]#"
156+
IPMI_LPAR_EXPECT_PEXPECT_PROMPT_LIST = [r"\[pexpect\]#$", pexpect.TIMEOUT]
157+
158+
# HMI Test case constants
159+
HMI_PROC_RECV_DONE = 1
160+
HMI_PROC_RECV_ERROR_MASKED = 2
161+
HMI_MALFUNCTION_ALERT = 3
162+
HMI_HYPERVISOR_RESOURCE_ERROR = 4
163+
HMI_TEST_CASE_SLEEP_TIME = 30
164+
165+
# CPU sleep states constants
166+
GET_CPU_SLEEP_STATE2 = "cat /sys/devices/system/cpu/cpu*/cpuidle/state2/disable"
167+
GET_CPU_SLEEP_STATE1 = "cat /sys/devices/system/cpu/cpu*/cpuidle/state1/disable"
168+
GET_CPU_SLEEP_STATE0 = "cat /sys/devices/system/cpu/cpu*/cpuidle/state0/disable"
169+
170+
DISABLE_CPU_SLEEP_STATE1 = "for i in /sys/devices/system/cpu/cpu*/cpuidle/state1/disable; do echo 1 > $i; done"
171+
DISABLE_CPU_SLEEP_STATE2 = "for i in /sys/devices/system/cpu/cpu*/cpuidle/state2/disable; do echo 1 > $i; done"

common/OpTestIPMI.py

+180-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import subprocess
3535
import os
3636
import pexpect
37+
import sys
3738
#from subprocess import check_output
3839
from OpTestConstants import OpTestConstants as BMC_CONST
3940
from OpTestError import OpTestError
@@ -50,7 +51,13 @@ class OpTestIPMI():
5051
# @param i_bmcPwd @type string: Password of the userid to log into the BMC
5152
# @param i_ffdcDir @type string: Optional param to indicate where to write FFDC
5253
#
53-
def __init__(self, i_bmcIP, i_bmcUser, i_bmcPwd, i_ffdcDir):
54+
# "Only required for inband tests" else Default = None
55+
# @param i_lparIP The IP address of the LPAR
56+
# @param i_lparuser The userid to log into the LPAR
57+
# @param i_lparPasswd The password of the userid to log into the LPAR with
58+
#
59+
def __init__(self, i_bmcIP, i_bmcUser, i_bmcPwd, i_ffdcDir, i_lparip=None,
60+
i_lparuser=None, i_lparPasswd=None):
5461

5562
self.cv_bmcIP = i_bmcIP
5663
self.cv_bmcUser = i_bmcUser
@@ -59,6 +66,9 @@ def __init__(self, i_bmcIP, i_bmcUser, i_bmcPwd, i_ffdcDir):
5966
self.cv_baseIpmiCmd = 'ipmitool -H %s -I lanplus -U %s -P %s ' \
6067
% (self.cv_bmcIP, self.cv_bmcUser, self.cv_bmcPwd)
6168
self.util = OpTestUtil()
69+
self.lpar_ip = i_lparip
70+
self.lpar_user = i_lparuser
71+
self.lpar_passwd = i_lparPasswd
6272

6373

6474
##
@@ -554,3 +564,172 @@ def ipmi_get_occ_status(self):
554564
raise OpTestError(l_msg)
555565

556566
return l_result
567+
568+
##
569+
# @brief This function will deactivates ipmi sol console
570+
#
571+
# @return l_con @type Object: it is a object of pexpect.spawn class or raise OpTestError
572+
#
573+
def ipmi_sol_deactivate(self):
574+
print "running:%s sol deactivate" % self.cv_baseIpmiCmd
575+
try:
576+
l_con = pexpect.spawn('%s sol deactivate' % self.cv_baseIpmiCmd)
577+
except pexpect.ExceptionPexpect:
578+
l_msg = "IPMI: sol deactivate failed"
579+
raise OpTestError(l_msg)
580+
return l_con
581+
582+
##
583+
# @brief This function will activates ipmi sol console
584+
#
585+
# @return l_con @type Object: it is a object of pexpect.spawn class or raise OpTestError
586+
#
587+
def ipmi_sol_activate(self):
588+
print "running:%s sol activate" % self.cv_baseIpmiCmd
589+
try:
590+
l_con = pexpect.spawn('%s sol activate' % self.cv_baseIpmiCmd)
591+
except pexpect.ExceptionPexpect:
592+
l_msg = "IPMI: sol activate failed"
593+
raise OpTestError(l_msg)
594+
return l_con
595+
596+
##
597+
# @brief This function waits for getting ipmi sol console activated.
598+
#
599+
# @return l_con @type Object: it is a object of pexpect.spawn class
600+
# or raise OpTestError in case of not connecting up to 10mins.
601+
#
602+
def ipmi_get_console(self):
603+
self.ipmi_sol_deactivate()
604+
# Waiting for a small time interval as latter versions of ipmi takes a bit of time to deactivate.
605+
time.sleep(BMC_CONST.IPMI_SOL_DEACTIVATE_TIME)
606+
l_con = self.ipmi_sol_activate()
607+
time.sleep(BMC_CONST.IPMI_SOL_ACTIVATE_TIME)
608+
count = 0
609+
while (not l_con.isalive()):
610+
l_con = self.ipmi_sol_activate()
611+
time.sleep(BMC_CONST.IPMI_SOL_ACTIVATE_TIME)
612+
count += 1
613+
if count > 120:
614+
l_msg = "IPMI: not able to get sol console"
615+
raise OpTestError(l_msg)
616+
l_con.logfile = sys.stdout
617+
l_con.delaybeforesend = BMC_CONST.IPMI_CON_DELAY_BEFORE_SEND
618+
return l_con
619+
620+
##
621+
# @brief This function make sure, ipmi console is activated and then login to the lpar if host is already up.
622+
#
623+
# @param i_con @type Object: it is a object of pexpect.spawn class
624+
# and this is the console object used for ipmi sol console access and for lpar login.
625+
#
626+
# @return BMC_CONST.FW_SUCCESS or raise OpTestError
627+
#
628+
def ipmi_lpar_login(self, i_con):
629+
l_con = i_con
630+
l_host = self.lpar_ip
631+
l_user = self.lpar_user
632+
l_pwd = self.lpar_passwd
633+
l_rc = l_con.expect_exact(BMC_CONST.IPMI_SOL_CONSOLE_ACTIVATE_OUTPUT, timeout=120)
634+
if l_rc == 0:
635+
print "IPMI: sol console activated"
636+
else:
637+
l_msg = "Error: not able to get IPMI console"
638+
raise OpTestError(l_msg)
639+
640+
time.sleep(5)
641+
l_con.send("\r")
642+
time.sleep(3)
643+
l_rc = l_con.expect_exact(BMC_CONST.IPMI_CONSOLE_EXPECT_ENTER_OUTPUT, timeout=120)
644+
if l_rc == BMC_CONST.IPMI_CONSOLE_EXPECT_LOGIN:
645+
l_con.sendline(l_user)
646+
l_rc = l_con.expect([r"[Pp]assword:", pexpect.TIMEOUT, pexpect.EOF], timeout=120)
647+
time.sleep(5)
648+
if l_rc == BMC_CONST.IPMI_CONSOLE_EXPECT_PASSWORD:
649+
l_con.sendline(l_pwd)
650+
else:
651+
l_msg = "Error: lpar login failed"
652+
raise OpTestError(l_msg)
653+
elif l_rc in BMC_CONST.IPMI_CONSOLE_EXPECT_PETITBOOT:
654+
l_msg = "Error: system is at petitboot"
655+
raise OpTestError(l_msg)
656+
elif l_rc in BMC_CONST.IPMI_CONSOLE_EXPECT_RANDOM_STATE:
657+
l_msg = "Error: system is in random state"
658+
raise OpTestError(l_msg)
659+
else:
660+
l_con.expect(pexpect.TIMEOUT, timeout=30)
661+
print l_con.before
662+
return BMC_CONST.FW_SUCCESS
663+
664+
##
665+
# @brief This function will used for setting the shell prompt to [pexpect]#, so that it can be used for
666+
# running lpar os commands. Each time we can expect for this string [pexpect]#
667+
#
668+
# @param i_con @type Object: it is a object of pexpect.spawn class
669+
# this is the active ipmi sol console object
670+
#
671+
# @return BMC_CONST.FW_SUCCESS or raise OpTestError
672+
#
673+
def ipmi_lpar_set_unique_prompt(self, i_con):
674+
self.l_con = i_con
675+
self.l_con.sendline(BMC_CONST.IPMI_LPAR_UNIQUE_PROMPT)
676+
l_rc = self.l_con.expect_exact(BMC_CONST.IPMI_LPAR_EXPECT_PEXPECT_PROMPT)
677+
if l_rc == 0:
678+
print "Shell prompt changed"
679+
return BMC_CONST.FW_SUCCESS
680+
else:
681+
l_msg = "Failed during change of shell prompt"
682+
raise OpTestError(l_msg)
683+
684+
##
685+
# @brief This function will be used for running lpar OS commands through ipmi console and for monitoring ipmi
686+
# console for any system boots and kernel panic's etc. This function will be helpfull when ssh to host or
687+
# network is down. This function should be followed by below functions inorder to work properly.
688+
# sys_get_ipmi_console()--> For getting ipmi console
689+
# ipmi_lpar_login()---> For login to lpar
690+
# ipmi_lpar_set_unique_prompt()--> For setting the unique shell prompt [pexpect]#
691+
# run_lpar_cmd_on_ipmi_console()--> Run the lpar commands and for monitoring ipmi console
692+
#
693+
# @param i_cmd @type string: lpar linux command
694+
#
695+
# @return res @type list: command output-if successfull,
696+
# monitor and returns console output(up to 8 mins)- if fails or raise OpTestError
697+
#
698+
def run_lpar_cmd_on_ipmi_console(self, i_cmd):
699+
self.l_con.sendline(i_cmd)
700+
time.sleep(5)
701+
try:
702+
rc = self.l_con.expect(BMC_CONST.IPMI_LPAR_EXPECT_PEXPECT_PROMPT_LIST, timeout=500)
703+
if rc == 0:
704+
res = self.l_con.before
705+
# print self.l_con.before
706+
res = res.splitlines()
707+
return res
708+
else:
709+
res = self.l_con.before
710+
# print self.l_con.before
711+
res = res.split(i_cmd)
712+
return res[-1].splitlines()
713+
except pexpect.ExceptionPexpect, e:
714+
l_msg = "lpar command execution on ipmi sol console failed"
715+
print str(e)
716+
raise OpTestError(l_msg)
717+
718+
##
719+
# @brief This function will closes ipmi sol console
720+
#
721+
# @param i_con @type Object: it is a object of pexpect.spawn class
722+
# this is the active ipmi sol console object
723+
#
724+
# @return BMC_CONST.FW_SUCCESS or raise OpTestError
725+
#
726+
def ipmi_close_console(self, i_con):
727+
l_con = i_con
728+
try:
729+
l_con.send('~.')
730+
time.sleep(BMC_CONST.IPMI_WAIT_FOR_TERMINATING_SESSION)
731+
l_con.close()
732+
except pexpect.ExceptionPexpect:
733+
l_msg = "IPMI: failed to close ipmi console"
734+
raise OpTestError(l_msg)
735+
return BMC_CONST.FW_SUCCESS

0 commit comments

Comments
 (0)