34
34
import subprocess
35
35
import os
36
36
import pexpect
37
+ import sys
37
38
#from subprocess import check_output
38
39
from OpTestConstants import OpTestConstants as BMC_CONST
39
40
from OpTestError import OpTestError
@@ -50,7 +51,13 @@ class OpTestIPMI():
50
51
# @param i_bmcPwd @type string: Password of the userid to log into the BMC
51
52
# @param i_ffdcDir @type string: Optional param to indicate where to write FFDC
52
53
#
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 ):
54
61
55
62
self .cv_bmcIP = i_bmcIP
56
63
self .cv_bmcUser = i_bmcUser
@@ -59,6 +66,9 @@ def __init__(self, i_bmcIP, i_bmcUser, i_bmcPwd, i_ffdcDir):
59
66
self .cv_baseIpmiCmd = 'ipmitool -H %s -I lanplus -U %s -P %s ' \
60
67
% (self .cv_bmcIP , self .cv_bmcUser , self .cv_bmcPwd )
61
68
self .util = OpTestUtil ()
69
+ self .lpar_ip = i_lparip
70
+ self .lpar_user = i_lparuser
71
+ self .lpar_passwd = i_lparPasswd
62
72
63
73
64
74
##
@@ -554,3 +564,172 @@ def ipmi_get_occ_status(self):
554
564
raise OpTestError (l_msg )
555
565
556
566
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