Exemplo n.º 1
0
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP,
                                  i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

        self.opTestSensors = OpTestSensors(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                           i_bmcUserIpmi, i_bmcPasswdIpmi,
                                           i_ffdcDir, i_hostip, i_hostuser,
                                           i_hostPasswd)
class OpTestHeartbeat():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will check for os level and get kernel version
    #        2. It will check for existence of ps command
    #        3. It will check for kopald service is running 
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_kopald_service(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for ps command 
        self.cv_HOST.host_check_command("ps")

        l_cmd = "ps -ef | grep -i kopald"
        print l_cmd
        l_res = self.cv_HOST.host_run_command(l_cmd)
        print l_res
        if (l_res.__contains__('[kopald]')):
            return BMC_CONST.FW_SUCCESS 
        else:
            l_msg = "kopald service is not running"
            print l_msg
            raise OpTestError(l_msg)
class OpTestDropbearSafety():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function will tests Dropbear running functionality in skiroot
    #         1. Power Off the system
    #         2. Power on the system
    #         3. Exit to the petitboot shell
    #         4. Execute ps command
    #         5. test will fail incase dropbear is running and listed out by ps
    #         6. At the end of test reboot the system to OS.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_dropbear_running(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Test Dropbear running in Petitboot"
        print "Performing IPMI Power Off Operation"
        self.console = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_SYSTEM.sys_ipmi_boot_system_to_petitboot(self.console)
        self.cv_IPMI.ipmi_host_set_unique_prompt(self.console)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        # we don't grep for 'dropbear' so that our naive line.count
        # below doesn't hit a false positive.
        res = self.cv_IPMI.run_host_cmd_on_ipmi_console("ps|grep drop")
        print res
        self.cv_IPMI.ipmi_set_boot_to_disk()
        for line in res:
            if line.count('dropbear'):
                raise OpTestError("drobear is running in the skiroot")
        return BMC_CONST.FW_SUCCESS
Exemplo n.º 4
0
 def __init__(
     self,
     i_bmcIP,
     i_bmcUser,
     i_bmcPasswd,
     i_bmcUserIpmi,
     i_bmcPasswdIpmi,
     i_ffdcDir=None,
     i_hostip=None,
     i_hostuser=None,
     i_hostPasswd=None,
     i_hostLspci=None,
 ):
     self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
     self.cv_IPMI = OpTestIPMI(
         i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd
     )
     self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP, i_ffdcDir)
     self.cv_SYSTEM = OpTestSystem(
         i_bmcIP,
         i_bmcUser,
         i_bmcPasswd,
         i_bmcUserIpmi,
         i_bmcPasswdIpmi,
         i_ffdcDir,
         i_hostip,
         i_hostuser,
         i_hostPasswd,
     )
     self.util = OpTestUtil()
     self.lspci_file = i_hostLspci
 def __init__(
     self,
     i_bmcIP,
     i_bmcUser,
     i_bmcPasswd,
     i_bmcUserIpmi,
     i_bmcPasswdIpmi,
     i_ffdcDir=None,
     i_lparip=None,
     i_lparuser=None,
     i_lparPasswd=None,
 ):
     self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
     self.cv_IPMI = OpTestIPMI(
         i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_lparip, i_lparuser, i_lparPasswd
     )
     self.cv_LPAR = OpTestLpar(i_lparip, i_lparuser, i_lparPasswd, i_bmcIP)
     self.cv_SYSTEM = OpTestSystem(
         i_bmcIP,
         i_bmcUser,
         i_bmcPasswd,
         i_bmcUserIpmi,
         i_bmcPasswdIpmi,
         i_ffdcDir,
         i_lparip,
         i_lparuser,
         i_lparPasswd,
     )
     self.util = OpTestUtil()
Exemplo n.º 6
0
 def setUp(self):
     bmcCfg, testCfg, hostCfg = _config_read()
     opTestSys = OpTestSystem(bmcCfg['ip'],bmcCfg['username'],
                      bmcCfg['password'],
                      bmcCfg.get('usernameipmi'),
                      bmcCfg.get('passwordipmi'),
                      testCfg['ffdcdir'],
                      hostCfg['hostip'],
                      hostCfg['hostuser'],
                      hostCfg['hostpasswd'])
 def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
              i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostIP=None,
              i_hostUser=None, i_hostPasswd=None):
     self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
     self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                               i_ffdcDir)
     self.cv_HOST = OpTestHost(i_hostIP, i_hostUser, i_hostPasswd, i_bmcIP)
     self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
              i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostIP,
              i_hostUser, i_hostPasswd)
     self.util = OpTestUtil()
Exemplo n.º 8
0
 def __init__(self,
              i_bmcIP,
              i_bmcUser,
              i_bmcPasswd,
              i_bmcUserIpmi,
              i_bmcPasswdIpmi,
              i_ffdcDir=None,
              i_platName=None,
              i_hostip=None,
              i_hostuser=None,
              i_hostPasswd=None):
     self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
     self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                               i_ffdcDir, i_hostip, i_hostuser,
                               i_hostPasswd)
     self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
     self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                   i_bmcUserIpmi, i_bmcPasswdIpmi,
                                   i_ffdcDir, i_hostip, i_hostuser,
                                   i_hostPasswd)
     self.cv_PLATFORM = i_platName
     self.util = OpTestUtil()
class OpTestIPMILockMode():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS level installed on power platform
    #        2. It will check for kernel version installed on the Open Power Machine
    #        3. It will check for ipmitool command existence and ipmitool package
    #        4. Load the necessary ipmi modules based on config values
    #        5. Issue a ipmi lock command through out-of-band authenticated interface
    #        6. Now BMC IPMI is in locked mode, at this point only white listed
    #           in-band ipmi commands sholud work(No other in-band ipmi command should work)
    #        7. Execute and test the functionality of whitelisted in-band ipmi
    #           commands in locked mode
    #        8. At the end of test issue a ipmi unlock command to revert the availablity of all
    #           in-band ipmi commands in unlocked mode.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_ipmi_lock_mode(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for ipmitool command and lm_sensors package
        self.cv_HOST.host_check_command("ipmitool")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "ipmitool")
        print "Installed package: %s" % l_pkg

        # loading below ipmi modules based on config option
        # ipmi_devintf, ipmi_powernv and ipmi_masghandler
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_DEVICE_INTERFACE,
            BMC_CONST.IPMI_DEV_INTF)
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_POWERNV, BMC_CONST.IPMI_POWERNV)
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_HANDLER,
            BMC_CONST.IPMI_MSG_HANDLER)

        # Issue a ipmi lock command through authenticated interface
        print "Issuing ipmi lock command through authenticated interface"
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_LOCK_CMD)
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI:Lock command failed, There may be two reasons here.\n\
                a. check the corresponding parches available in AMI driver code,\n\
                b. if patches available then command is failing"

            print l_msg
            raise OpTestError(l_msg)
        print "IPMI:Lock command executed successfully"

        try:
            self.run_inband_ipmi_whitelisted_cmds()
        except:
            l_msg = "One of white listed in-band ipmi command execution failed"
            print sys.exc_info()
        finally:
            # Issue a ipmi unlock command at the end of test.
            print "Issuing ipmi unlock command through authenticated interface"
            self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_UNLOCK_CMD)

    ##
    # @brief This function will execute whitelisted in-band ipmi commands
    #        and test the functionality in locked mode.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def run_inband_ipmi_whitelisted_cmds(self):
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_host_login(l_con)
        self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")

        # Test IPMI white listed commands those should be allowed through un-authenticated
        # in-band interface
        # 1.[App] Get Device ID
        print "Testing Get Device ID command"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_DEVICE_ID)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Device ID command failed"
            raise OpTestError(l_msg)

        # 2.[App] Get Device GUID
        print "Testing Get Device GUID"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_DEVICE_GUID)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Device GUID command failed"
            raise OpTestError(l_msg)

        # 3.[App] Get System GUID
        print "Testing Get system GUID"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SYSTEM_GUID)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System GUID command failed"
            raise OpTestError(l_msg)

        # 4.[Storage] Get SEL info
        print "Testing Get SEL info"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SEL_INFO)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get SEL info command failed"
            raise OpTestError(l_msg)

        # 5.[Storage] Get SEL time
        print "Testing Get SEL time"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SEL_TIME_RAW)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get SEL time command failed"
            raise OpTestError(l_msg)

        # 6. [Storage] Reserve SEL
        print "Testing Reserve SEL"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_RESERVE_SEL)
        if l_res[-1] != "0":
            l_msg = "IPMI: Reserve SEL command failed"
            raise OpTestError(l_msg)

        # 7. [Storage] Set SEL time (required for RTC)
        print "Testing Set SEL time"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SEL_TIME)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_SET_SEL_TIME + " \'" + l_res[-1] + "\'; echo $?")
        if l_res[-1] != "0":
            l_msg = "IPMI: Set SEL time command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_host_cmd_on_ipmi_console(BMC_CONST.HOST_GET_SEL_TIME)

        # 8. [Transport] Get LAN parameters
        print "Testing Get LAN parameters"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_LAN_PARAMETERS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get LAN parameters command failed"
            raise OpTestError(l_msg)

        # 9.[Chassis] Get System Boot Options
        print "Testing Get System Boot Options"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SYSTEM_BOOT_OPTIONS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System Boot Options command failed"
            raise OpTestError(l_msg)

        # 10.[Chassis] Set System Boot Options
        print "Testing Set System Boot Options"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_SET_SYTEM_BOOT_OPTIONS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set System Boot Options command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SYSTEM_BOOT_OPTIONS)

        # 11. [App] Get BMC Global Enables
        print "Testing Get BMC Global Enables"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_BMC_GLOBAL_ENABLES_RAW)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get BMC Global Enables command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_BMC_GLOBAL_ENABLES)

        # 12. [App] Set BMC Global Enables
        print "Testing Set BMC Global Enables"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_SET_BMC_GLOBAL_ENABLES_SEL_OFF)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set BMC Global Enables sel=off command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_BMC_GLOBAL_ENABLES)
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_SET_BMC_GLOBAL_ENABLES_SEL_ON)

        # 13.[App] Get System Interface Capabilities
        print "Testing Get System Interface Capabilities"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SYSTEM_INTERFACE_CAPABILITIES_SSIF)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System Interface Capabilities SSIF command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SYSTEM_INTERFACE_CAPABILITIES_KCS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System Interface Capabilities KCS command failed"
            raise OpTestError(l_msg)

        # 14.[App] Get Message Flags
        print "Testing Get Message Flags"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_MESSAGE_FLAGS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Message Flags command failed"
            raise OpTestError(l_msg)

        # 15. [App] Get BT Capabilities
        print "Testing Get BT Capabilities"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_BT_CAPABILITIES)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get BT Capabilities command failed"
            raise OpTestError(l_msg)

        # 16. [App] Clear Message Flags
        print "Testing Clear Message Flags"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_CLEAR_MESSAGE_FLAGS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Clear Message Flags command failed"
            raise OpTestError(l_msg)

        # 17. [OEM] PNOR Access Status
        print "Testing the PNOR Access Status"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PNOR_ACCESS_STATUS_DENY)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Status:deny command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PNOR_ACCESS_STATUS_GRANT)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Status:grant command failed"
            raise OpTestError(l_msg)

        # 18. [Storage] Add SEL Entry
        print "Testing Add SEL Entry"
        print "Clearing the SEL list"
        self.cv_IPMI.ipmi_sdr_clear()
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_ADD_SEL_ENTRY)
        if l_res[-1] != "0":
            l_msg = "IPMI: Add SEL Entry command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.ipmitool_execute_command(
            BMC_CONST.IPMI_LIST_LAST_SEL_EVENT)
        print "Checking for Reserved entry creation in SEL"
        if "Reserved" not in l_res:
            l_msg = "IPMI: Add SEL Entry command, doesn't create an SEL event"
            raise OpTestError(l_msg)

        # 19. [App] Set Power State
        print "Testing Set Power State"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_SET_ACPI_POWER_STATE)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set Power State command failed"
            raise OpTestError(l_msg)

        # 20. [App] Set watchdog
        print "Testing Set watchdog"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_SET_WATCHDOG)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set watchdog command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_MC_WATCHDOG_GET)

        # 21. [Sensor/Event] Get Sensor Type
        print "Testing Get Sensor Type"
        l_res = self.cv_IPMI.ipmitool_execute_command(
            BMC_CONST.IPMI_SDR_GET_WATCHDOG)
        matchObj = re.search("Watchdog \((0x\d{1,})\)", l_res)
        if matchObj:
            print "Got sensor Id for watchdog: %s" % matchObj.group(1)
        else:
            l_msg = "Failed to get sensor id for watchdog sensor"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SENSOR_TYPE_FOR_WATCHDOG + " " +
            matchObj.group(1) + " ;echo $?")
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Sensor Type command failed"
            raise OpTestError(l_msg)

        # 22.[Sensor/Event] Get Sensor Reading
        print "Testing Get Sensor Reading"
        l_res = self.cv_IPMI.ipmitool_execute_command(
            BMC_CONST.IPMI_SDR_GET_WATCHDOG)
        matchObj = re.search("Watchdog \((0x\d{1,})\)", l_res)
        if matchObj:
            print "Got sensor Id for watchdog: %s" % matchObj.group(1)
        else:
            l_msg = "Failed to get sensor id for watchdog sensor"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_SENSOR_READING + " " + matchObj.group(1) +
            " ;echo $?")
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Sensor Reading command failed"
            raise OpTestError(l_msg)

        # 23.[Sensor/Event] Platform Event (0x02)
        print "Testing Platform Event"
        self.cv_IPMI.ipmi_sdr_clear()
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PLATFORM_EVENT)
        if l_res[-1] != "0":
            l_msg = "IPMI: Platform Event command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.ipmitool_execute_command(
            BMC_CONST.IPMI_LIST_LAST_SEL_EVENT)
        if "Reserved" not in l_res:
            l_msg = "IPMI: Platform Event command failed to log SEL event"
            raise OpTestError(l_msg)

        # 24. [OEM] PNOR Access Response (0x08)
        print "Testing PNOR Access Response"
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PNOR_ACCESS_STATUS_GRANT)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PNOR_ACCESS_RESPONSE)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Response command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PNOR_ACCESS_STATUS_DENY)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_PNOR_ACCESS_RESPONSE)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Response command failed"
            raise OpTestError(l_msg)

        # 25.[Chassis] Chassis Control
        print "Testing chassis power on"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_CHASSIS_POWER_ON)
        if l_res[-1] != "0":
            l_msg = "IPMI: chassis power on command failed"
            raise OpTestError(l_msg)

        # 26.[App] 0x38 Get Channel Authentication Cap
        print "Testing Get Channel Authentication Capabilities"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_CHANNEL_AUTH_CAP)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Channel Authentication Capabilities command failed"
            raise OpTestError(l_msg)

        # 27.[App] Reset Watchdog (0x22)
        print "Testing reset watchdog"
        self.cv_IPMI.ipmi_sdr_clear()
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_RESET_WATCHDOG)
        if l_res[-1] != "0":
            l_msg = "IPMI: Reset Watchdog command failed"
            raise OpTestError(l_msg)

        time.sleep(10)
        # Reset watchdog should create a SEL event log
        l_res = self.cv_IPMI.ipmitool_execute_command(
            BMC_CONST.IPMI_LIST_LAST_SEL_EVENT)
        if "Watchdog" not in l_res:
            l_msg = "IPMI: Reset Watchdog command, doesn't create an SEL event"
            raise OpTestError(l_msg)

        # 28. [App] Get ACPI Power State (0x06)
        print "Testing Get ACPI Power State"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            BMC_CONST.HOST_GET_ACPI_POWER_STATE)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get ACPI Power State command failed"
            raise OpTestError(l_msg)
Exemplo n.º 10
0
class OpTestHMIHandling:
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_lparIP The IP address of the LPAR
    # @param i_lparuser The userid to log into the LPAR
    # @param i_lparPasswd The password of the userid to log into the LPAR with
    #
    def __init__(
        self,
        i_bmcIP,
        i_bmcUser,
        i_bmcPasswd,
        i_bmcUserIpmi,
        i_bmcPasswdIpmi,
        i_ffdcDir=None,
        i_lparip=None,
        i_lparuser=None,
        i_lparPasswd=None,
    ):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(
            i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_lparip, i_lparuser, i_lparPasswd
        )
        self.cv_LPAR = OpTestLpar(i_lparip, i_lparuser, i_lparPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(
            i_bmcIP,
            i_bmcUser,
            i_bmcPasswd,
            i_bmcUserIpmi,
            i_bmcPasswdIpmi,
            i_ffdcDir,
            i_lparip,
            i_lparuser,
            i_lparPasswd,
        )
        self.util = OpTestUtil()

    ##
    # @brief This is a common function for all the hmi test cases. This will be executed before
    #        any test case starts. Basically this provides below requirements.
    #        1. Validates all required lpar commands
    #        2. It will clone skiboot source repository
    #        3. Compile the necessary tools xscom-utils and gard utility to test HMI.
    #        4. Get the list Of Chips and cores in the form of dictionary.
    #           Ex: [['00000000', ['4', '5', '6', 'c', 'd', 'e']], ['00000001', ['4', '5', '6', 'c', 'd', 'e']], ['00000010', ['4', '5', '6', 'c', 'd', 'e']]]
    #        5. In-order to inject HMI errors on cpu's, cpu should be running,
    #           so disabling the sleep states 1 and 2 of all CPU's.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_init(self):
        # Get OS level
        self.cv_LPAR.lpar_get_OS_Level()

        # Check whether git and gcc commands are available on lpar
        self.cv_LPAR.lpar_check_command("git")
        self.cv_LPAR.lpar_check_command("gcc")

        # It will clone skiboot source repository
        l_dir = "/tmp/skiboot"
        self.cv_LPAR.lpar_clone_skiboot_source(l_dir)
        # Compile the necessary tools xscom-utils and gard utility
        self.cv_LPAR.lpar_compile_xscom_utilities(l_dir)
        self.cv_LPAR.lpar_compile_gard_utility(l_dir)

        # Getting list of processor chip Id's(executing getscom -l to get chip id's)
        l_res = self.cv_LPAR.lpar_run_command("cd %s/external/xscom-utils/; ./getscom -l" % l_dir)
        l_res = l_res.splitlines()
        l_chips = []
        for line in l_res:
            matchObj = re.search("(\d{8}).*processor", line)
            if matchObj:
                l_chips.append(matchObj.group(1))
        if not l_chips:
            l_msg = "Getscom failed to list processor chip id's"
            raise OpTestError(l_msg)
        l_chips.sort()
        print l_chips  # ['00000000', '00000001', '00000010']

        # Currently getting the list of active core id's with respect to each chip is by using opal msg log
        # TODO: Need to identify best way to get list of cores(If Opal msg log is empty)
        l_cmd = "cat /sys/firmware/opal/msglog | grep -i CHIP"
        l_res = self.cv_LPAR.lpar_run_command(l_cmd)
        l_cores = {}
        self.l_dic = []
        l_res = l_res.splitlines()
        for line in l_res:
            matchObj = re.search("Chip (\d{1,2}) Core ([a-z0-9])", line)
            if matchObj:
                if l_cores.has_key(int(matchObj.group(1))):
                    (l_cores[int(matchObj.group(1))]).append(matchObj.group(2))
                else:
                    l_cores[int(matchObj.group(1))] = list(matchObj.group(2))
        if not l_cores:
            l_msg = "Failed in getting core id's information from OPAL msg log"
            raise OpTestError(l_msg)

        print l_cores  # {0: ['4', '5', '6', 'c', 'd', 'e'], 1: ['4', '5', '6', 'c', 'd', 'e'], 10: ['4', '5', '6', 'c', 'd', 'e']}
        l_cores = sorted(l_cores.iteritems())
        print l_cores
        i = 0
        for tup in l_cores:
            new_list = [l_chips[i], tup[1]]
            self.l_dic.append(new_list)
            i += 1
        print self.l_dic
        # self.l_dic is a list of chip id's, core id's . and is of below format
        # [['00000000', ['4', '5', '6', 'c', 'd', 'e']], ['00000001', ['4', '5', '6', 'c', 'd', 'e']], ['00000010', ['4', '5', '6', 'c', 'd', 'e']]]

        self.l_dir = l_dir
        # In-order to inject HMI errors on cpu's, cpu should be running, so disabling the sleep states 1 and 2 of all CPU's
        self.cv_LPAR.lpar_run_command(BMC_CONST.GET_CPU_SLEEP_STATE2)
        self.cv_LPAR.lpar_run_command(BMC_CONST.GET_CPU_SLEEP_STATE1)
        self.cv_LPAR.lpar_run_command(BMC_CONST.GET_CPU_SLEEP_STATE0)
        self.cv_LPAR.lpar_run_command(BMC_CONST.DISABLE_CPU_SLEEP_STATE1)
        self.cv_LPAR.lpar_run_command(BMC_CONST.DISABLE_CPU_SLEEP_STATE2)
        self.cv_LPAR.lpar_run_command(BMC_CONST.GET_CPU_SLEEP_STATE2)
        self.cv_LPAR.lpar_run_command(BMC_CONST.GET_CPU_SLEEP_STATE1)
        self.cv_LPAR.lpar_run_command(BMC_CONST.GET_CPU_SLEEP_STATE0)

    ##
    # @brief This function is mainly used to clear hardware gard entries.
    #        It will perform below steps
    #           1. Reboot the system(Power off/on)
    #           2. Clear any Hardware gard entries
    #           3. Again reboot the system, to make use of garded Hardware.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def clearGardEntries(self):
        # Power off and on the system.
        self.cv_IPMI.ipmi_power_off()
        self.cv_IPMI.ipmi_power_on()
        if int(self.cv_SYSTEM.sys_ipl_wait_for_working_state()):
            l_msg = "System failed to boot host OS"
            raise OpTestError(l_msg)
        time.sleep(BMC_CONST.LPAR_BRINGUP_TIME)

        # Clearing gard entries after lpar comes up
        self.cv_LPAR.lpar_get_OS_Level()
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_lpar_login(l_con)
        self.cv_IPMI.ipmi_lpar_set_unique_prompt(l_con)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("uname -a")
        l_dir = "/tmp/skiboot"
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("cd %s/external/gard/;" % l_dir)
        l_cmd = "./gard list; echo $?"
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)
        l_cmd = "./gard clear all; echo $?"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)
        if int(l_res[-1]):
            l_msg = "Clearing gard entries through gard tool is failed"
            raise OpTestError(l_msg)
        l_cmd = "./gard list; echo $?"
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)

        # Rebooting the system again to make use of garded hardware
        self.cv_IPMI.ipmi_power_off()
        self.cv_IPMI.ipmi_power_on()
        if int(self.cv_SYSTEM.sys_ipl_wait_for_working_state()):
            l_msg = "System failed to boot host OS"
            raise OpTestError(l_msg)
        time.sleep(BMC_CONST.LPAR_BRINGUP_TIME)
        self.cv_LPAR.lpar_get_OS_Level()
        self.cv_SYSTEM.sys_ipmi_close_console(l_con)

    ##
    # @brief This function executes HMI test case based on the i_test value, Before test starts
    #        disabling kdump service to make sure system reboots, after injecting non-recoverable errors.
    #
    # @param i_test @type int: this is the type of test case want to execute
    #                          BMC_CONST.HMI_PROC_RECV_DONE: Processor recovery done
    #                          BMC_CONST.HMI_PROC_RECV_ERROR_MASKED: proc_recv_error_masked
    #                          BMC_CONST.HMI_MALFUNCTION_ALERT: malfunction_alert
    #                          BMC_CONST.HMI_HYPERVISOR_RESOURCE_ERROR: hypervisor resource error
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testHMIHandling(self, i_test):
        l_test = i_test
        self.test_init()
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_lpar_login(l_con)
        self.cv_IPMI.ipmi_lpar_set_unique_prompt(l_con)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("uname -a")
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("cat /etc/os-release")
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("service kdump status")
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("service kdump stop")
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("service kdump status")
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("cd %s/external/xscom-utils/;" % self.l_dir)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("lscpu")
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("dmesg -D")
        if l_test == BMC_CONST.HMI_PROC_RECV_DONE:
            self.test_proc_recv_done()
        elif l_test == BMC_CONST.HMI_PROC_RECV_ERROR_MASKED:
            self.test_proc_recv_error_masked()
        elif l_test == BMC_CONST.HMI_MALFUNCTION_ALERT:
            self.test_malfunction_allert()
        elif l_test == BMC_CONST.HMI_HYPERVISOR_RESOURCE_ERROR:
            self.test_hyp_resource_err()
        else:
            l_msg = "Please provide valid test case"
            raise OpTestError(l_msg)
        self.cv_SYSTEM.sys_ipmi_close_console(l_con)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test HMI: processor recovery done
    #        and also this function injecting error on all the cpus one by one and
    #        verify whether cpu is recovered or not.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_proc_recv_done(self):
        for l_pair in self.l_dic:
            l_chip = l_pair[0]
            for l_core in l_pair[1]:
                l_reg = "1%s013100" % l_core
                l_cmd = "./putscom -c %s %s 0000000000100000; echo $?" % (l_chip, l_reg)

                self.cv_IPMI.run_lpar_cmd_on_ipmi_console("dmesg -C")
                time.sleep(10)
                l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)
                time.sleep(10)
                if l_res[-1] == "0":
                    print "Injected thread hang recoverable error"
                else:
                    if any("Kernel panic - not syncing" in line for line in l_res):
                        l_msg = "Processor recovery failed: Kernel got panic"
                    elif any("Petitboot" in line for line in l_res):
                        l_msg = "System reached petitboot:Processor recovery failed"
                    elif any("ISTEP" in line for line in l_res):
                        l_msg = "System started booting: Processor recovery failed"
                    else:
                        l_msg = "Failed to inject thread hang recoverable error"
                    print l_msg
                    raise OpTestError(l_msg)

                l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console("dmesg")
                if any("Processor Recovery done" in line for line in l_res) and any(
                    "Harmless Hypervisor Maintenance interrupt [Recovered]" in line for line in l_res
                ):
                    print "Processor recovery done"
                else:
                    l_msg = "HMI handling failed to log message: for proc_recv_done"
                    raise OpTestError(l_msg)
                time.sleep(BMC_CONST.HMI_TEST_CASE_SLEEP_TIME)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test HMI: proc_recv_error_masked
    #        Processor went through recovery for an error which is actually masked for reporting
    #        this function also injecting the error on all the cpu's one-by-one.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_proc_recv_error_masked(self):
        for l_pair in self.l_dic:
            l_chip = l_pair[0]
            for l_core in l_pair[1]:
                l_reg = "1%s013100" % l_core
                l_cmd = "./putscom -c %s %s 0000000000080000; echo $?" % (l_chip, l_reg)
                self.cv_IPMI.run_lpar_cmd_on_ipmi_console("dmesg -C")
                time.sleep(10)
                l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)
                time.sleep(10)
                if l_res[-1] == "0":
                    print "Injected thread hang recoverable error"
                else:
                    if any("Kernel panic - not syncing" in line for line in l_res):
                        l_msg = "Processor recovery failed: Kernel got panic"
                    elif any("Petitboot" in line for line in l_res):
                        l_msg = "System reached petitboot:Processor recovery failed"
                    elif any("ISTEP" in line for line in l_res):
                        l_msg = "System started booting: Processor recovery failed"
                    else:
                        l_msg = "Failed to inject thread hang recoverable error"
                    print l_msg
                    raise OpTestError(l_msg)

                l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console("dmesg")
                if any("Processor Recovery done" in line for line in l_res) and any(
                    "Harmless Hypervisor Maintenance interrupt [Recovered]" in line for line in l_res
                ):
                    print "Processor recovery done"
                else:
                    l_msg = "HMI handling failed to log message"
                    raise OpTestError(l_msg)
                time.sleep(BMC_CONST.HMI_TEST_CASE_SLEEP_TIME)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test hmi malfunction alert:Core checkstop
    #        A processor core in the system has to be checkstopped (failed recovery).
    #        Injecting core checkstop on random core of random chip
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_malfunction_allert(self):
        # Get random pair of chip vs cores
        l_pair = random.choice(self.l_dic)
        # Get random chip id
        l_chip = l_pair[0]
        # Get random core number
        l_core = random.choice(l_pair[1])

        l_reg = "1%s013100" % l_core
        l_cmd = "./putscom -c %s %s 1000000000000000" % (l_chip, l_reg)

        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)
        if any("Kernel panic - not syncing" in line for line in l_res):
            print "Malfunction alert: kernel got panic"
        elif any("login:"******"System booted to host OS without any kernel panic message"
        elif any("Petitboot" in line for line in l_res):
            print "System reached petitboot without any kernel panic message"
        elif any("ISTEP" in line for line in l_res):
            print "System started booting without any kernel panic message"
        else:
            l_msg = "HMI: Malfunction alert failed"
            raise OpTestError(l_msg)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test HMI: Hypervisor resource error
    #        Injecting Hypervisor resource error on random core of random chip
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_hyp_resource_err(self):
        # Get random pair of chip vs cores
        l_pair = random.choice(self.l_dic)
        # Get random chip id
        l_chip = l_pair[0]
        # Get random core number
        l_core = random.choice(l_pair[1])

        l_reg = "1%s013100" % l_core
        l_cmd = "./putscom -c %s %s 0000000000008000" % (l_chip, l_reg)

        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(l_cmd)
        if any("Kernel panic - not syncing" in line for line in l_res) and any(
            "Hypervisor Resource error - core check stop" in line for line in l_res
        ):
            print "Hypervisor resource error: kernel got panic"
        elif any("login:"******"System booted to host OS without any kernel panic message"
        elif any("Petitboot" in line for line in l_res):
            print "System reached petitboot without any kernel panic message"
        elif any("ISTEP" in line for line in l_res):
            print "System started booting without any kernel panic message"
        else:
            l_msg = "HMI: Hypervisor resource error failed"
            raise OpTestError(l_msg)
        return BMC_CONST.FW_SUCCESS
class OpTestMtdPnorDriver():
    ## Initialize this object and also getting the host login credentials to use by scp utility
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()
        self.host_user = i_hostuser
        self.host_ip = i_hostip
        self.host_Passwd = i_hostPasswd

    ##
    # @brief  This function has following test steps
    #         1. Get host information(OS and Kernel information)
    #         2. Load the mtd module based on config value
    #         3. Check /dev/mtd0 character device file existence on host
    #         4. Copying the contents of the flash in a file /tmp/pnor
    #         5. Getting the /tmp/pnor file into local x86 machine using scp utility
    #         6. Remove existing /tmp/ffs directory and
    #            Clone latest ffs git repository in local x86 working machine
    #         7. Compile ffs repository to get fcp utility
    #         8. Check existence of fcp utility in ffs repository, after compiling
    #         9. Get the PNOR flash contents on an x86 machine using fcp utility
    #
    # @return BMC_CONST.FW_SUCCESS-success or raise OpTestError-fail
    #
    def testMtdPnorDriver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # loading mtd module based on config option
        l_config = "CONFIG_MTD_POWERNV_FLASH"
        l_module = "mtd"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config,
                                                      l_module)

        # Check /dev/mtd0 file existence on host
        l_cmd = "ls -l /dev/mtd0; echo $?"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            print "/dev/mtd0 character device file exists on host"
        else:
            l_msg = "/dev/mtd0 character device file doesn't exist on host"
            print l_msg
            raise OpTestError(l_msg)

        # Copying the contents of the PNOR flash in a file /tmp/pnor
        l_file = "/tmp/pnor"
        l_cmd = "cat /dev/mtd0 > %s; echo $?" % l_file
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            print "Fetched PNOR data from /dev/mtd0 into temp file /tmp/pnor"
        else:
            l_msg = "Fetching PNOR data is failed from /dev/mtd0 into temp file /tmp/pnor"
            print l_msg
            raise OpTestError(l_msg)

        # Getting the /tmp/pnor file into local x86 machine
        l_path = "/tmp/"
        self.util.copyFilesToDest(l_path, self.host_user, self.host_ip, l_file,
                                  self.host_Passwd, "2",
                                  BMC_CONST.SCP_TO_LOCAL)
        l_list = commands.getstatusoutput("ls -l %s; echo $?" % l_path)
        print l_list

        l_workdir = "/tmp/ffs"
        # Remove existing /tmp/ffs directory
        l_res = commands.getstatusoutput("rm -rf %s" % l_workdir)
        print l_res

        # Clone latest ffs git repository in local x86 working machine
        l_cmd = "git clone   https://github.com/open-power/ffs/ %s" % l_workdir
        l_res = commands.getstatusoutput(l_cmd)
        print l_res
        if int(l_res[0]) == 0:
            print "Cloning of ffs repository is successfull"
        else:
            l_msg = "Cloning ffs repository is failed"
            print l_msg
            raise OpTestError(l_msg)

        # Compile ffs repository to get fcp utility
        l_cmd = "cd %s/; make" % l_workdir
        l_res = commands.getstatusoutput(l_cmd)
        print l_res
        if int(l_res[0]) == 0:
            print "Compiling fcp utility is successfull"
        else:
            l_msg = "Compiling fcp utility is failed"
            print l_msg
            raise OpTestError(l_msg)

        # Check existence of fcp utility in ffs repository, after compiling.
        l_cmd = "test -f %s/fcp/x86/fcp" % l_workdir
        l_res = commands.getstatusoutput(l_cmd)
        print l_res
        if int(l_res[0]) == 0:
            print "Compiling fcp utility is successfull"
        else:
            l_msg = "Compiling fcp utility is failed"
            print l_msg
            raise OpTestError(l_msg)

        # Check the PNOR flash contents on an x86 machine using fcp utility
        l_cmd = "%s/fcp/x86/fcp -o 0x0 -L %s" % (l_workdir, l_file)
        l_res = commands.getstatusoutput(l_cmd)
        print l_res[1]
        if int(l_res[0]) == 0:
            print "Getting PNOR data successfull using fcp utility"
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Getting the PNOR data using fcp utility failed"
            print l_msg
            raise OpTestError(l_msg)
class OpTestEnergyScale():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_platName=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.cv_PLATFORM = i_platName
        self.util = OpTestUtil()

    ##
    # @brief This function will get and return platform power limits for supported machine
    #
    # @param i_platform type: str platform name to get the power limits
    #
    # @return l_power_limit_low lower platform power limit
    #         l_power_limit_high higher platform power limit
    #         or raise OpTestError if it is a new platform
    #
    def get_platform_power_limits(self, i_platform):
        l_platform = i_platform
        if BMC_CONST.HABANERO in l_platform:
            l_power_limit_high = BMC_CONST.HABANERO_POWER_LIMIT_HIGH
            l_power_limit_low = BMC_CONST.HABANERO_POWER_LIMIT_LOW
        elif BMC_CONST.FIRESTONE in l_platform:
            l_power_limit_high = BMC_CONST.FIRESTONE_POWER_LIMIT_HIGH
            l_power_limit_low = BMC_CONST.FIRESTONE_POWER_LIMIT_LOW
        elif BMC_CONST.GARRISON in l_platform:
            l_power_limit_high = BMC_CONST.GARRISON_POWER_LIMIT_HIGH
            l_power_limit_low = BMC_CONST.GARRISON_POWER_LIMIT_LOW
        else:
            l_msg = "New platform, add power limit support to this platform and retry"
            raise OpTestError(l_msg)
        return l_power_limit_low, l_power_limit_high

    ##
    # @brief  This function will test Energy scale features at standby state
    #         1. Power OFF the system.
    #         2. Validate below Energy scale features at standby state
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power set_limit limit <value>  :Power Limit Requested in Watts.
    #            ipmitool dcmi power activate                 :Activate the set power limit.
    #            ipmitool dcmi power deactivate               :Deactivate the set power limit.
    #         3. Once platform power limit activated execute below dcmi commands at standby state.
    #            ipmitool dcmi discover                       :This command is used to discover  
    #                                                           supported  capabilities in DCMI.
    #            ipmitool dcmi power reading                  :Get power related readings from the system.
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power sensors                  :Prints the available DCMI sensors.
    #            ipmitool dcmi get_temp_reading               :Get Temperature Sensor Readings.
    #         4. Power ON the system.
    #         5. Check after system booted to runtime, whether occ's are active or not.
    #         6. Again in runtime execute all dcmi commands to check the functionality.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_energy_scale_at_standby_state(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Energy Scale Test 1: Get, Set, activate and deactivate platform power limit at power off"
        l_power_limit_low, l_power_limit_high = self.get_platform_power_limits(self.cv_PLATFORM)

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_sdr_clear()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_high)
        self.cv_IPMI.ipmi_activate_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_low)
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_high)
        self.cv_IPMI.ipmi_get_power_limit()
        print "Get All dcmi readings at power off"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print self.cv_IPMI.ipmi_get_power_limit()
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)


    ##
    # @brief  This function will test Energy scale features at standby state
    #         1. Power OFF the system.
    #         2. Power On the system to boot to host OS
    #         2. Validate below Energy scale features at runtime state
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power set_limit limit <value>  :Power Limit Requested in Watts.
    #            ipmitool dcmi power activate                 :Activate the set power limit.
    #            ipmitool dcmi power deactivate               :Deactivate the set power limit.
    #         3. Once platform power limit activated execute below dcmi commands at runtime state.
    #            ipmitool dcmi discover                       :This command is used to discover  
    #                                                           supported  capabilities in DCMI.
    #            ipmitool dcmi power reading                  :Get power related readings from the system.
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power sensors                  :Prints the available DCMI sensors.
    #            ipmitool dcmi get_temp_reading               :Get Temperature Sensor Readings.
    #         4. Issue Power OFF/ON to check whether system boots after setting platform power limit at runtime.
    #         5. Again in runtime execute all dcmi commands to check the functionality.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_energy_scale_at_runtime_state(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Energy Scale Test 2: Get, Set, activate and deactivate platform power limit at runtime"
        l_power_limit_low, l_power_limit_high = self.get_platform_power_limits(self.cv_PLATFORM)

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at power off"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        self.cv_IPMI.ipmi_sdr_clear()
        print self.cv_IPMI.ipmi_get_power_limit()
        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_high)
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_low)
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)

    ##
    # @brief  This function will test below dcmi commands at both standby and runtime states
    #            ipmitool dcmi discover                       :This command is used to discover  
    #                                                           supported  capabilities in DCMI.
    #            ipmitool dcmi power reading                  :Get power related readings from the system.
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power sensors                  :Prints the available DCMI sensors.
    #            ipmitool dcmi get_temp_reading               :Get Temperature Sensor Readings.
    #            ipmitool dcmi get_mc_id_string               :Get management controller identifier string.
    #            ipmitool dcmi get_conf_param                 :Get DCMI Configuration Parameters.
    #            ipmitool dcmi oob_discover                   :Ping/Pong Message for DCMI Discovery.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_dcmi_at_standby_and_runtime_states(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Energy scale Test 3: Get Sensors, Temperature and Power reading's at power off and runtime"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at power off"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)


    ##
    # @brief  It will execute and test the return code of ipmi command.
    #
    # @param i_cmd @type string:The ipmitool command, for example: chassis power on; echo $?
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def run_ipmi_cmd(self, i_cmd):
        l_cmd = i_cmd
        l_res = self.cv_IPMI.ipmitool_execute_command(l_cmd)
        print l_res
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI: command failed %c" % l_cmd
            raise OpTestError(l_msg)
        return l_res
Exemplo n.º 13
0
class OpTestPCI:
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(
        self,
        i_bmcIP,
        i_bmcUser,
        i_bmcPasswd,
        i_bmcUserIpmi,
        i_bmcPasswdIpmi,
        i_ffdcDir=None,
        i_hostip=None,
        i_hostuser=None,
        i_hostPasswd=None,
        i_hostLspci=None,
    ):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(
            i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd
        )
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP, i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(
            i_bmcIP,
            i_bmcUser,
            i_bmcPasswd,
            i_bmcUserIpmi,
            i_bmcPasswdIpmi,
            i_ffdcDir,
            i_hostip,
            i_hostuser,
            i_hostPasswd,
        )
        self.util = OpTestUtil()
        self.lspci_file = i_hostLspci

    ##
    # @brief  This function will get the PCI and USB susbsytem Info
    #         And also this test compares known good data of
    #         "lspci -mm -n" which is stored in testcases/data directory
    #         with the current lspci data.
    #         User need to specify the corresponding file name into
    #         machines xml like lspci.txt which contains "lspci -mm -n"
    #         command output in a working good state of system.
    #         tools used are lspci and lsusb
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_host_pci_devices_info(self):
        if self.lspci_file == "empty.txt":
            print "Skipping the pci devices comparision as missing the lspci data file name in machines xml"
            return BMC_CONST.FW_SUCCESS
        filename = os.path.join(os.path.dirname(__file__).split("testcases")[0], self.lspci_file)
        if not os.path.isfile(filename):
            raise OpTestError("lspci file %s not found in top level directory" % filename)
        self.pci_good_data_file = filename
        self.test_skiroot_pci_devices()
        self.cv_IPMI.ipmi_set_boot_to_disk()
        self.cv_IPMI.ipmi_power_off()
        self.cv_IPMI.ipmi_power_on()
        self.cv_IPMI.ipl_wait_for_working_state()
        self.test_host_pci_devices()

    ##
    # @brief  This function will get the "lspci -mm -n" output from the petitboot
    #         and compares it with known good lspci data
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_skiroot_pci_devices(self):
        cmd = "lspci -mm -n"
        self.console = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_SYSTEM.sys_ipmi_boot_system_to_petitboot(self.console)
        self.cv_IPMI.ipmi_host_set_unique_prompt(self.console)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        self.cv_IPMI.run_host_cmd_on_ipmi_console("cat /etc/os-release")
        res = self.cv_IPMI.run_host_cmd_on_ipmi_console(cmd)
        self.cv_SYSTEM.sys_ipmi_close_console(self.console)
        self.pci_data_petitboot = "\n".join(res[1:])
        diff_process = subprocess.Popen(["diff", "-u", self.pci_good_data_file, "-"], stdin=subprocess.PIPE)
        diff_stdout, diff_stderr = diff_process.communicate(self.pci_data_petitboot + "\n")
        r = diff_process.wait()
        if r == 0:
            print "All the pci devices are detected at petitboot"
        else:
            print diff_stdout
            raise OpTestError("There is a mismatch b/w known good output and tested petitboot lspci output")

    ##
    # @brief  This function will get the "lspci -mm -n" output from the host OS
    #         and compares it with known good lspci data
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_host_pci_devices(self):
        self.cv_HOST.host_check_command("lspci", "lsusb")
        self.cv_HOST.host_list_pci_devices()
        self.cv_HOST.host_get_pci_verbose_info()
        self.cv_HOST.host_list_usb_devices()
        l_res = self.cv_HOST.host_run_command("lspci -mm -n")
        self.pci_data_hostos = l_res.replace("\r\n", "\n")
        diff_process = subprocess.Popen(["diff", "-u", self.pci_good_data_file, "-"], stdin=subprocess.PIPE)
        diff_stdout, diff_stderr = diff_process.communicate(self.pci_data_hostos)
        r = diff_process.wait()
        if r == 0:
            print "All the pci devices are detected in host OS"
        else:
            print diff_stdout
            raise OpTestError("There is a mismatch b/w known good output and tested host OS lspci output")
class OpTestAt24driver():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd,i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function has following test steps
    #         1. Getting the host infromation(OS and kernel information)
    #         2. Loading the necessary modules to test at24 device driver functionalites
    #            (i2c_dev, i2c_opal and at24)
    #         3. Getting the list of i2c buses and eeprom chip addresses
    #         4. Accessing the registers visible through the i2cbus using i2cdump utility
    #         5. Getting the eeprom device data using hexdump utility in hex + Ascii format
    #
    # @return BMC_CONST.FW_SUCCESS-success or raise OpTestError
    #
    def testAt24driver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        self.cv_HOST.host_get_OS_Level()

        # Check whether i2cdump and hexdump commands are available on host
        self.cv_HOST.host_check_command("i2cdump", "hexdump")

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Loading i2c_opal module based on config option
        l_config = "CONFIG_I2C_OPAL"
        l_module = "i2c_opal"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # Loading i2c_dev module based on config option
        l_config = "CONFIG_I2C_CHARDEV"
        l_module = "i2c_dev"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # Loading at24 module based on config option
        l_config = "CONFIG_EEPROM_AT24"
        l_module = "at24"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # Get infomtion of EEPROM chips
        self.cv_HOST.host_get_info_of_eeprom_chips()

        # Get list of pairs of i2c bus and EEPROM device addresses in the host
        l_chips = self.cv_HOST.host_get_list_of_eeprom_chips()
        for l_args in l_chips:
            # Accessing the registers visible through the i2cbus using i2cdump utility
            # l_args format: "0 0x51","1 0x53",.....etc
            self.i2c_dump(l_args)

        # Getting the list of sysfs eeprom interfaces
        l_res = self.cv_HOST.host_run_command("find /sys/ -name eeprom; echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            pass
        else:
            l_msg = "EEPROM sysfs entries are not created"
            print l_msg
            raise OpTestError(l_msg)
        for l_dev in l_res:
            if l_dev.__contains__("eeprom"):
                # Getting the eeprom device data using hexdump utility in hex + Ascii format
                self.cv_HOST.host_hexdump(l_dev)
            else:
                pass
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This i2cdump function takes arguments in pair of a string like "i2cbus address".
    #        i2cbus indicates the number or name of the I2C bus to be scanned. This number should
    #        correspond  to  one  of  the busses listed by i2cdetect -l. address indicates
    #        the address to be scanned on that bus, and is an integer between 0x03 and 0x77
    #        i2cdump is a program to examine registers visible through the I2C bus
    #
    # @param i_args @type string: this is the argument to i2cdump utility
    #                             args are in the form of "i2c-bus-number eeprom-chip-address"
    #                             Ex: "0 0x51","3 0x52" ....etc
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def i2c_dump(self, i_args):
        l_res = self.cv_HOST.host_run_command("i2cdump -f -y %s; echo $?" % i_args)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "i2cdump failed on addr %s" % i_args
            print l_msg
            raise OpTestError(l_msg)
Exemplo n.º 15
0
class OpTestEM():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS and kernel versions.
    #        2. Check the cpupower utility is available in host.
    #        3. Get available cpu scaling frequencies
    #        4. Set the userspace governer for all cpu's
    #        5. test the cpufreq driver by set/verify cpu frequency
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_cpu_freq_states(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        self.cv_HOST.host_check_command("cpupower")
        # Get available cpu scaling frequencies
        l_res = self.cv_HOST.host_run_command(
            "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies"
        )
        freq_list = (l_res.strip()).split(' ')
        print freq_list

        # Set the cpu governer to userspace
        self.set_cpu_gov("userspace")
        self.verify_cpu_gov("userspace")
        for i in range(1, 100):
            i_freq = random.choice(freq_list)
            self.set_cpu_freq(i_freq)
            self.verify_cpu_freq(i_freq)

        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS and kernel versions.
    #        2. Check the cpupower utility is available in host.
    #        3. Set the userspace governer for all cpu's
    #        4. test the cpuidle driver by enable/disable/verify the idle states
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_cpu_idle_states(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        self.cv_HOST.host_check_command("cpupower")
        # currently p8 cpu has 3 states
        for i in (0, 1, 2):
            self.enable_idle_state(i)
            self.verify_enable_idle_state(i)
        for i in (0, 1, 2):
            self.disable_idle_state(i)
            self.verify_disable_idle_state(i)

        return BMC_CONST.FW_SUCCESS

    ##
    # @brief sets the cpu frequency with i_freq value
    #
    # @param i_freq @type str: this is the frequency of cpu to be set
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_cpu_freq(self, i_freq):
        l_cmd = "for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_setspeed; do echo %s > $i; done" % i_freq
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief verify the cpu frequency with i_freq value
    #
    # @param i_freq @type str: this is the frequency to be verified with cpu frequency
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_cpu_freq(self, i_freq):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"
        cur_freq = self.cv_HOST.host_run_command(l_cmd)
        if cur_freq.strip() == i_freq:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU frequency not changed to %s" % i_freq
            raise OpTestError(l_msg)

    ##
    # @brief sets the cpu governer with i_gov governer
    #
    # @param i_gov @type str: this is the governer to be set for all cpu's
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_cpu_gov(self, i_gov):
        l_cmd = "for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo %s > $i; done" % i_gov
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief verify the cpu governer with i_gov governer
    #
    # @param i_gov @type str: this is the governer to be verified with cpu governer
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_cpu_gov(self, i_gov):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
        cur_gov = self.cv_HOST.host_run_command(l_cmd)
        if cur_gov.strip() == i_gov:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU governor not changed to %s" % i_gov
            raise OpTestError(l_msg)

    ##
    # @brief enable cpu idle state i_idle
    #
    # @param i_idle @type str: this is the cpu idle state to be enabled
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def enable_idle_state(self, i_idle):
        l_cmd = "cpupower idle-set -e %s" % i_idle
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief disable cpu idle state i_idle
    #
    # @param i_idle @type str: this is the cpu idle state to be disabled
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def disable_idle_state(self, i_idle):
        l_cmd = "cpupower idle-set -d %s" % i_idle
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief verify whether cpu idle state i_idle enabled
    #
    # @param i_idle @type str: this is the cpu idle state to be verified for enable
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_enable_idle_state(self, i_idle):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpuidle/state%s/disable" % i_idle
        cur_value = self.cv_HOST.host_run_command(l_cmd)
        if cur_value.strip() == "0":
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU state%s not enabled" % i_idle
            raise OpTestError(l_msg)

    ##
    # @brief verify whether cpu idle state i_idle disabled
    #
    # @param i_idle @type str: this is the cpu idle state to be verified for disable
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_disable_idle_state(self, i_idle):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpuidle/state%s/disable" % i_idle
        cur_value = self.cv_HOST.host_run_command(l_cmd)
        if cur_value.strip() == "1":
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU state%s not disabled" % i_idle
            raise OpTestError(l_msg)
Exemplo n.º 16
0
class OpTestRTCdriver():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. Getting host information(OS and Kernel info)
    #        2. Loading rtc_opal module based on config option
    #        3. Testing the rtc driver functions
    #                Display the current time,
    #                set the Hardware Clock to a specified time,
    #                set the Hardware Clock from the System Time, or
    #                set the System Time from the Hardware Clock
    #                keep the Hardware clock in UTC or local time format
    #                Hardware clock compare, predict and adjust functions
    #                Hardware clock debug and test modes
    #                Reading the Hardware clock from special file instead of default
    #        4. After executing above each function reading the Hardware clock in b/w functions.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_RTC_driver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Get hwclock version
        l_hwclock = self.cv_HOST.host_run_command("hwclock -V;echo $?")

        # loading rtc_opal module based on config option
        l_config = "CONFIG_RTC_DRV_OPAL"
        l_module = "rtc_opal"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config,
                                                      l_module)

        # Get the device files for rtc driver
        l_res = self.cv_HOST.host_run_command(
            "ls /dev/ | grep -i --color=never rtc")
        l_files = l_res.splitlines()
        l_list = []
        for name in l_files:
            if name.__contains__("rtc"):
                l_file = "/dev/" + name
                l_list.append(l_file)
            else:
                continue
        print l_list

        # Display the time of hwclock from device files
        for l_file in l_list:
            self.read_hwclock_from_file(l_file)

        self.cv_HOST.host_read_hwclock()
        time.sleep(5)
        self.cv_HOST.host_set_hwclock_time("2015-01-01 10:10:10")
        time.sleep(5)
        self.cv_HOST.host_read_hwclock()
        self.cv_HOST.host_set_hwclock_time("2016-01-01 20:20:20")
        self.cv_HOST.host_read_hwclock()
        self.set_hwclock_in_utc("2017-01-01 10:10:10")
        self.cv_HOST.host_read_hwclock()
        self.set_hwclock_in_localtime("2014-01-01 05:05:05")
        self.cv_HOST.host_read_hwclock()
        self.cv_HOST.host_read_systime()
        self.systime_to_hwclock()
        self.cv_HOST.host_read_hwclock()
        self.systime_to_hwclock_in_utc()
        self.cv_HOST.host_read_hwclock()
        self.systime_to_hwclock_in_localtime()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_to_systime()
        self.cv_HOST.host_read_hwclock()
        self.cv_HOST.host_read_systime()
        self.hwclock_in_utc()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_in_localtime()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_predict("2015-01-01 10:10:10")
        self.cv_HOST.host_read_hwclock()
        self.hwclock_debug_mode()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_test_mode("2018-01-01 10:10:10")
        self.cv_HOST.host_read_hwclock()
        self.hwclock_adjust()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_compare()
        self.cv_HOST.host_read_hwclock()

    ##
    # @brief This function reads hwclock from special /dev/... file instead of default
    #
    # @param i_file @type string: special /dev/ file
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def read_hwclock_from_file(self, i_file):
        print "Reading the hwclock from special file /dev/ ...: %s" % i_file
        l_res = self.cv_HOST.host_run_command("hwclock -r -f %s;echo $?" %
                                              i_file)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Reading the hwclock from file failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets hwclock in UTC format
    #
    # @param i_time @type string: time to set hwclock
    #                             Ex: "2016-01-01 12:12:12"
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_hwclock_in_utc(self, i_time):
        print "Setting the hwclock in UTC: %s" % i_time
        l_res = self.cv_HOST.host_run_command(
            "hwclock --set --date \'%s\' --utc;echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock in UTC failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets hwclock in local time format
    #
    # @param i_time @type string: Time to set hwclock
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_hwclock_in_localtime(self, i_time):
        print "Setting the hwclock in localtime: %s" % i_time
        l_res = self.cv_HOST.host_run_command(
            "hwclock --set --date \'%s\' --localtime;echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock in localtime failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the time of hwclock from system time
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def systime_to_hwclock(self):
        print "Setting the hwclock from system time"
        l_res = self.cv_HOST.host_run_command("hwclock --systohc;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock from system time failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the time of hwclock from system time in UTC format
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def systime_to_hwclock_in_utc(self):
        print "Setting the hwclock from system time, in UTC format"
        l_res = self.cv_HOST.host_run_command(
            "hwclock --systohc --utc;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock from system time in UTC format failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the time of hwclock from system time in local time format
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def systime_to_hwclock_in_localtime(self):
        print "Setting the hwclock from system time, in localtime format"
        l_res = self.cv_HOST.host_run_command(
            "hwclock --systohc --localtime;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock from system time in localtime format failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the system time from hwclock.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_to_systime(self):
        print "Setting the system time from hwclock"
        l_res = self.cv_HOST.host_run_command("hwclock --hctosys;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the system time from hwclock failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function keeps hwclock in UTC format.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_in_utc(self):
        print "Keeping the hwclock in UTC format"
        l_res = self.cv_HOST.host_run_command("hwclock --utc;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Keeping the hwclock in UTC is failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function keeps hwclock in local time format.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_in_localtime(self):
        print "Keeping the hwclock in localtime"
        l_res = self.cv_HOST.host_run_command("hwclock --localtime;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Keeping the hwclock in localtime is failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests hwclock compare functionality for a time of 100 seconds.
    #        Here checking the return status of timeout as 124, if compare works fine. any
    #        other return value means compare function failed.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_compare(self):
        print "Testing hwclock compare functionality for a time of 100 seconds"
        l_res = self.cv_HOST.host_run_command(
            "timeout 100 hwclock --compare; echo $?")
        l_res = l_res.splitlines()
        print l_res
        if int(l_res[-1]) == 124:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock compare function failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function predict RTC reading at time given with --date
    #
    # @param i_time @type string: time at which predict hwclock reading
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_predict(self, i_time):
        print "Testing the hwclock predict function to a time: %s" % i_time
        l_res = self.cv_HOST.host_run_command(
            "hwclock --predict --date \'%s\';echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock predict function failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests hwclock debug mode.
    #        In this mode setting hwclock from system time
    #        and setting system time from hwclock
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_debug_mode(self):
        print "Testing the hwclock debug mode"
        l_res = self.cv_HOST.host_run_command(
            "hwclock --systohc --debug;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            pass
        else:
            l_msg = "Setting the hwclock from system time in debug mode failed"
            print l_msg
            raise OpTestError(l_msg)
        l_res = self.cv_HOST.host_run_command(
            "hwclock --hctosys --debug;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the system time from hwclock in debug mode failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests the hwclock test mode. In this mode setting the hwclock
    #        time using --set option. Here it just execute but should not set hwclock time.
    #
    # @param i_time @type string: time to set hwclock in test mode
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_test_mode(self, i_time):
        print "Testing the hwclock test mode, set time to: %s" % i_time
        l_res = self.cv_HOST.host_run_command(
            "hwclock --set --date \'%s\' --test;echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock test function failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests hwclock adjust functionality
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_adjust(self):
        print "Testing the hwclock adjust function"
        l_res = self.cv_HOST.host_run_command("hwclock --adjust;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            l_res = self.cv_HOST.host_run_command("cat /etc/adjtime")
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock adjust function failed"
            print l_msg
            raise OpTestError(l_msg)
Exemplo n.º 17
0
class OpTestFastReboot():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function tests fast reset of power systems.
    #         It will check booting sequence when reboot command
    #         getting executed in both petitboot and host OS
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_opal_fast_reboot(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        self.cv_HOST.host_run_command(BMC_CONST.NVRAM_SET_FAST_RESET_MODE)
        res = self.cv_HOST.host_run_command(BMC_CONST.NVRAM_PRINT_FAST_RESET_VALUE)
        if "feeling-lucky" in res:
            print "Setting the fast-reset mode successful"
        else:
            raise OpTestError("Failed to set the fast-reset mode")
        self.con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_host_login(self.con)
        self.cv_IPMI.ipmi_host_set_unique_prompt(self.con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        self.cv_IPMI.ipmi_set_boot_to_petitboot()
        self.con.sendline("reboot")
        self.con.expect(" RESET: Initiating fast reboot", timeout=60)
        # Exiting to petitboot shell
        self.con.expect('Petitboot', timeout=BMC_CONST.PETITBOOT_TIMEOUT)
        self.con.expect('x=exit', timeout=10)
        # Exiting to petitboot
        self.con.sendcontrol('l')
        self.con.send('\x1b[B')
        self.con.send('\x1b[B')
        self.con.send('\r')
        self.con.expect('Exiting petitboot')
        self.con.send('\r')
        self.con.send('\x08')
        self.cv_IPMI.ipmi_host_set_unique_prompt(self.con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        self.con.sendline("reboot")
        self.con.expect(" RESET: Initiating fast reboot", timeout=60)
        # Exiting to petitboot shell
        self.con.expect('Petitboot', timeout=BMC_CONST.PETITBOOT_TIMEOUT)
        self.con.expect('x=exit', timeout=10)
        print "fast-reset boots the system to runtime"
        self.cv_IPMI.ipmi_set_boot_to_disk()
        return BMC_CONST.FW_SUCCESS
class OpTestMtdPnorDriver():
    ## Initialize this object and also getting the host login credentials to use by scp utility
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()
        self.host_user = i_hostuser
        self.host_ip = i_hostip
        self.host_Passwd = i_hostPasswd

    ##
    # @brief  This function has following test steps
    #         1. Get host information(OS and Kernel information)
    #         2. Load the mtd module based on config value
    #         3. Check /dev/mtd0 character device file existence on host
    #         4. Copying the contents of the flash in a file /tmp/pnor
    #         5. Getting the /tmp/pnor file into local x86 machine using scp utility
    #         6. Remove existing /tmp/ffs directory and
    #            Clone latest ffs git repository in local x86 working machine
    #         7. Compile ffs repository to get fcp utility
    #         8. Check existence of fcp utility in ffs repository, after compiling
    #         9. Get the PNOR flash contents on an x86 machine using fcp utility
    #
    # @return BMC_CONST.FW_SUCCESS-success or raise OpTestError-fail
    #
    def testMtdPnorDriver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # loading mtd module based on config option
        l_config = "CONFIG_MTD_POWERNV_FLASH"
        l_module = "mtd"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # Check /dev/mtd0 file existence on host
        l_cmd = "ls -l /dev/mtd0; echo $?"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            print "/dev/mtd0 character device file exists on host"
        else:
            l_msg = "/dev/mtd0 character device file doesn't exist on host"
            print l_msg
            raise OpTestError(l_msg)

        # Copying the contents of the PNOR flash in a file /tmp/pnor
        l_file = "/tmp/pnor"
        l_cmd = "cat /dev/mtd0 > %s; echo $?" % l_file
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            print "Fetched PNOR data from /dev/mtd0 into temp file /tmp/pnor"
        else:
            l_msg = "Fetching PNOR data is failed from /dev/mtd0 into temp file /tmp/pnor"
            print l_msg
            raise OpTestError(l_msg)

        # Getting the /tmp/pnor file into local x86 machine
        l_path = "/tmp/"
        self.util.copyFilesToDest(l_path, self.host_user, self.host_ip, l_file, self.host_Passwd, "2", BMC_CONST.SCP_TO_LOCAL)
        l_list =  commands.getstatusoutput("ls -l %s; echo $?" % l_path)
        print l_list

        l_workdir = "/tmp/ffs"
        # Remove existing /tmp/ffs directory
        l_res = commands.getstatusoutput("rm -rf %s" % l_workdir)
        print l_res

        # Clone latest ffs git repository in local x86 working machine
        l_cmd = "git clone   https://github.com/open-power/ffs/ %s" % l_workdir
        l_res = commands.getstatusoutput(l_cmd)
        print l_res
        if int(l_res[0]) == 0:
            print "Cloning of ffs repository is successfull"
        else:
            l_msg = "Cloning ffs repository is failed"
            print l_msg
            raise OpTestError(l_msg)

        # Compile ffs repository to get fcp utility
        l_cmd = "cd %s/; make" % l_workdir
        l_res = commands.getstatusoutput(l_cmd)
        print l_res
        if int(l_res[0]) == 0:
            print "Compiling fcp utility is successfull"
        else:
            l_msg = "Compiling fcp utility is failed"
            print l_msg
            raise OpTestError(l_msg)

        # Check existence of fcp utility in ffs repository, after compiling.
        l_cmd = "test -f %s/fcp/x86/fcp" % l_workdir
        l_res = commands.getstatusoutput(l_cmd)
        print l_res
        if int(l_res[0]) == 0:
            print "Compiling fcp utility is successfull"
        else:
            l_msg = "Compiling fcp utility is failed"
            print l_msg
            raise OpTestError(l_msg)

        # Check the PNOR flash contents on an x86 machine using fcp utility
        l_cmd = "%s/fcp/x86/fcp -o 0x0 -L %s" % (l_workdir, l_file)
        l_res = commands.getstatusoutput(l_cmd)
        print l_res[1]
        if int(l_res[0]) == 0:
            print "Getting PNOR data successfull using fcp utility"
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Getting the PNOR data using fcp utility failed"
            print l_msg
            raise OpTestError(l_msg)
Exemplo n.º 19
0
class OpTestSystemBootSequence():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostip The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostpasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostpasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostpasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostpasswd, i_bmcIP, i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostpasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will test mc cold reset boot sequence
    #        It has below steps
    #        1. Do a system Power OFF(Host should go down)
    #        2. Set auto reboot policy to off(chassis policy always-off)
    #        3. Issue a BMC Cold reset.
    #        4. After BMC comes up, Issue a Power ON of the system
    #        5. Check for system status and gather OPAL msg log.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testMcColdResetBootSequence(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Testing MC Cold reset boot sequence"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Setting the system power policy to always-off"
        self.cv_IPMI.ipmi_set_power_policy("always-off")

        # Perform a BMC Cold Reset Operation
        self.cv_IPMI.ipmi_cold_reset()

        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will test mc warm reset boot sequence
    #        It has below steps
    #        1. Do a system Power OFF(Host should go down)
    #        2. Set auto reboot policy to off(chassis policy always-off)
    #        3. Issue a BMC Warm reset.
    #        4. After BMC comes up, Issue a Power ON of the system
    #        5. Check for system status and gather OPAL msg log.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testMcWarmResetBootSequence(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Testing MC Warm reset boot sequence"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Setting the system power policy to always-off"
        self.cv_IPMI.ipmi_set_power_policy("always-off")

        # Perform a BMC Warm Reset Operation
        self.cv_IPMI.ipmi_warm_reset()

        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will test system auto reboot policy always-off.
    #        It has below steps
    #        1. Do a system Power OFF(Host should go down)
    #        2. Set auto reboot policy to off(chassis policy always-off)
    #        3. Issue a BMC Cold reset.
    #        4. After BMC comes up, expect the system to not boot.
    #        5. Issue a Power ON of the system
    #        6. Check for system status and gather OPAL msg log.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testSystemPowerPolicyOff(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Testing System Power Policy:always-off"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Setting the system power policy to always-off"
        self.cv_IPMI.ipmi_set_power_policy("always-off")
        # Perform a BMC Cold Reset Operation
        if int(self.cv_SYSTEM.sys_cold_reset_bmc()) == BMC_CONST.FW_SUCCESS:
            print "System auto reboot policy for always-off works as expected"
            print "System Power status not changed"
            print "Performing a IPMI Power ON Operation"
            # Perform a IPMI Power ON Operation
            self.cv_IPMI.ipmi_power_on()
        else:
            print "Power restore policy failed"
            l_msg = "Fail: chassis policy always-off making the system to auto boot"
            print l_msg
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will test system auto reboot policy always-on.
    #        It has below steps
    #        1. Do a system Power OFF(Host should go down)
    #        2. Set auto reboot policy to on(chassis policy always-on)
    #        3. Issue a BMC Cold reset.
    #        4. After BMC comes up, Here expect the system to boot,
    #           If not power policy is not working as expected
    #        5. Check for system status and gather OPAL msg log.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testSystemPowerPolicyOn(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Testing System Power Policy:Always-ON"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Setting the system power policy to always-on"
        self.cv_IPMI.ipmi_set_power_policy("always-on")

        # Perform a BMC Cold Reset Operation
        if int(self.cv_SYSTEM.sys_cold_reset_bmc()) == BMC_CONST.FW_FAILED:
            print "System auto reboot policy for always-on works as expected"
            print "System Power status changed as expected"
        else:
            print "Power restore policy failed"
            l_msg = "Fail: chassis policy always-on making the system not to auto boot"
            print "Performing a IPMI Power ON Operation"
            # Perform a IPMI Power ON Operation
            self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will test system auto reboot policy previous
    #        It has below steps
    #        1. Do a system Power OFF(Host should go down)
    #        2. Set auto reboot policy to previous(chassis policy previous)
    #        3. Issue a BMC Cold reset.
    #        4. After BMC comes up, system power status will change based on
    #           previous power status before issuing cold reset.
    #        5. Check for system status and gather OPAL msg log.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testSystemPowerPolicyPrevious(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Testing System Power Policy:previous"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Setting the system power policy to previous"
        self.cv_IPMI.ipmi_set_power_policy("previous")

        # Perform a BMC Cold Reset Operation
        if int(self.cv_SYSTEM.sys_cold_reset_bmc()) == BMC_CONST.FW_SUCCESS:
            print "System auto reboot policy for previous works as expected"
            print "System Power status not changed"
            print "Performing a IPMI Power ON Operation"
            # Perform a IPMI Power ON Operation
            self.cv_IPMI.ipmi_power_on()
        else:
            print "Power restore policy failed"
            l_msg = "Fail: chassis policy previous making the system to auto boot"
            print l_msg
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        # Perform a BMC Cold Reset Operation
        if int(self.cv_SYSTEM.sys_cold_reset_bmc()) == BMC_CONST.FW_SUCCESS:
            print "System auto reboot policy for previous works as expected"
            print "System Power status not changed"
        else:
            print "Power restore policy previous failed"
            l_msg = "Fail: chassis policy previous making the system to change power status"
            print l_msg
            # Perform a IPMI Power ON Operation
            self.cv_IPMI.ipmi_power_on()
            self.cv_SYSTEM.sys_check_host_status()
            self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
            self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

            print "Gathering the OPAL msg logs"
            self.cv_HOST.host_gather_opal_msg_log()
Exemplo n.º 20
0
class OpTestRTCdriver():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd,i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. Getting host information(OS and Kernel info)
    #        2. Loading rtc_opal module based on config option
    #        3. Testing the rtc driver functions
    #                Display the current time,
    #                set the Hardware Clock to a specified time,
    #                set the Hardware Clock from the System Time, or
    #                set the System Time from the Hardware Clock
    #                keep the Hardware clock in UTC or local time format
    #                Hardware clock compare, predict and adjust functions
    #                Hardware clock debug and test modes
    #                Reading the Hardware clock from special file instead of default
    #        4. After executing above each function reading the Hardware clock in b/w functions.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_RTC_driver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Get hwclock version
        l_hwclock = self.cv_HOST.host_run_command("hwclock -V;echo $?")

        # loading rtc_opal module based on config option
        l_config = "CONFIG_RTC_DRV_OPAL"
        l_module = "rtc_opal"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # Get the device files for rtc driver
        l_res = self.cv_HOST.host_run_command("ls /dev/ | grep -i --color=never rtc")
        l_files = l_res.splitlines()
        l_list = []
        for name in l_files:
            if name.__contains__("rtc"):
                l_file = "/dev/" + name
                l_list.append(l_file)
            else:
                continue
        print l_list

        # Display the time of hwclock from device files
        for l_file in l_list:
            self.read_hwclock_from_file(l_file)

        self.cv_HOST.host_read_hwclock()
        time.sleep(5)
        self.cv_HOST.host_set_hwclock_time("2015-01-01 10:10:10")
        time.sleep(5)
        self.cv_HOST.host_read_hwclock()
        self.cv_HOST.host_set_hwclock_time("2016-01-01 20:20:20")
        self.cv_HOST.host_read_hwclock()
        self.set_hwclock_in_utc("2017-01-01 10:10:10")
        self.cv_HOST.host_read_hwclock()
        self.set_hwclock_in_localtime("2014-01-01 05:05:05")
        self.cv_HOST.host_read_hwclock()
        self.cv_HOST.host_read_systime()
        self.systime_to_hwclock()
        self.cv_HOST.host_read_hwclock()
        self.systime_to_hwclock_in_utc()
        self.cv_HOST.host_read_hwclock()
        self.systime_to_hwclock_in_localtime()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_to_systime()
        self.cv_HOST.host_read_hwclock()
        self.cv_HOST.host_read_systime()
        self.hwclock_in_utc()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_in_localtime()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_predict("2015-01-01 10:10:10")
        self.cv_HOST.host_read_hwclock()
        self.hwclock_debug_mode()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_test_mode("2018-01-01 10:10:10")
        self.cv_HOST.host_read_hwclock()
        self.hwclock_adjust()
        self.cv_HOST.host_read_hwclock()
        self.hwclock_compare()
        self.cv_HOST.host_read_hwclock()

    ##
    # @brief This function reads hwclock from special /dev/... file instead of default
    #
    # @param i_file @type string: special /dev/ file
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def read_hwclock_from_file(self, i_file):
        print "Reading the hwclock from special file /dev/ ...: %s" % i_file
        l_res = self.cv_HOST.host_run_command("hwclock -r -f %s;echo $?" % i_file)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Reading the hwclock from file failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets hwclock in UTC format
    #
    # @param i_time @type string: time to set hwclock
    #                             Ex: "2016-01-01 12:12:12"
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_hwclock_in_utc(self, i_time):
        print "Setting the hwclock in UTC: %s" % i_time
        l_res = self.cv_HOST.host_run_command("hwclock --set --date \'%s\' --utc;echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock in UTC failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets hwclock in local time format
    #
    # @param i_time @type string: Time to set hwclock
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_hwclock_in_localtime(self, i_time):
        print "Setting the hwclock in localtime: %s" % i_time
        l_res = self.cv_HOST.host_run_command("hwclock --set --date \'%s\' --localtime;echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock in localtime failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the time of hwclock from system time
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def systime_to_hwclock(self):
        print "Setting the hwclock from system time"
        l_res = self.cv_HOST.host_run_command("hwclock --systohc;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock from system time failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the time of hwclock from system time in UTC format
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def systime_to_hwclock_in_utc(self):
        print "Setting the hwclock from system time, in UTC format"
        l_res = self.cv_HOST.host_run_command("hwclock --systohc --utc;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock from system time in UTC format failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the time of hwclock from system time in local time format
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def systime_to_hwclock_in_localtime(self):
        print "Setting the hwclock from system time, in localtime format"
        l_res = self.cv_HOST.host_run_command("hwclock --systohc --localtime;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the hwclock from system time in localtime format failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function sets the system time from hwclock.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_to_systime(self):
        print "Setting the system time from hwclock"
        l_res = self.cv_HOST.host_run_command("hwclock --hctosys;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the system time from hwclock failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function keeps hwclock in UTC format.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_in_utc(self):
        print "Keeping the hwclock in UTC format"
        l_res = self.cv_HOST.host_run_command("hwclock --utc;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Keeping the hwclock in UTC is failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function keeps hwclock in local time format.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_in_localtime(self):
        print "Keeping the hwclock in localtime"
        l_res = self.cv_HOST.host_run_command("hwclock --localtime;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Keeping the hwclock in localtime is failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests hwclock compare functionality for a time of 100 seconds.
    #        Here checking the return status of timeout as 124, if compare works fine. any
    #        other return value means compare function failed.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_compare(self):
        print "Testing hwclock compare functionality for a time of 100 seconds"
        l_res = self.cv_HOST.host_run_command("timeout 100 hwclock --compare; echo $?")
        l_res = l_res.splitlines()
        print l_res
        if int(l_res[-1]) == 124:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock compare function failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function predict RTC reading at time given with --date
    #
    # @param i_time @type string: time at which predict hwclock reading
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_predict(self, i_time):
        print "Testing the hwclock predict function to a time: %s" % i_time
        l_res = self.cv_HOST.host_run_command("hwclock --predict --date \'%s\';echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock predict function failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests hwclock debug mode.
    #        In this mode setting hwclock from system time
    #        and setting system time from hwclock
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_debug_mode(self):
        print "Testing the hwclock debug mode"
        l_res = self.cv_HOST.host_run_command("hwclock --systohc --debug;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            pass
        else:
            l_msg = "Setting the hwclock from system time in debug mode failed"
            print l_msg
            raise OpTestError(l_msg)
        l_res = self.cv_HOST.host_run_command("hwclock --hctosys --debug;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Setting the system time from hwclock in debug mode failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests the hwclock test mode. In this mode setting the hwclock
    #        time using --set option. Here it just execute but should not set hwclock time.
    #
    # @param i_time @type string: time to set hwclock in test mode
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_test_mode(self, i_time):
        print "Testing the hwclock test mode, set time to: %s" % i_time
        l_res = self.cv_HOST.host_run_command("hwclock --set --date \'%s\' --test;echo $?" % i_time)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock test function failed"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function tests hwclock adjust functionality
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def hwclock_adjust(self):
        print "Testing the hwclock adjust function"
        l_res = self.cv_HOST.host_run_command("hwclock --adjust;echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            l_res = self.cv_HOST.host_run_command("cat /etc/adjtime")
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "hwclock adjust function failed"
            print l_msg
            raise OpTestError(l_msg)
Exemplo n.º 21
0
class OpTestAt24driver():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function has following test steps
    #         1. Getting the host infromation(OS and kernel information)
    #         2. Loading the necessary modules to test at24 device driver functionalites
    #            (i2c_dev, i2c_opal and at24)
    #         3. Getting the list of i2c buses and eeprom chip addresses
    #         4. Accessing the registers visible through the i2cbus using i2cdump utility
    #         5. Getting the eeprom device data using hexdump utility in hex + Ascii format
    #
    # @return BMC_CONST.FW_SUCCESS-success or raise OpTestError
    #
    def testAt24driver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        self.cv_HOST.host_get_OS_Level()

        # Check whether i2cdump and hexdump commands are available on host
        self.cv_HOST.host_check_command("i2cdump", "hexdump")

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Loading i2c_opal module based on config option
        l_config = "CONFIG_I2C_OPAL"
        l_module = "i2c_opal"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config,
                                                      l_module)

        # Loading i2c_dev module based on config option
        l_config = "CONFIG_I2C_CHARDEV"
        l_module = "i2c_dev"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config,
                                                      l_module)

        # Loading at24 module based on config option
        l_config = "CONFIG_EEPROM_AT24"
        l_module = "at24"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config,
                                                      l_module)

        # Get infomtion of EEPROM chips
        self.cv_HOST.host_get_info_of_eeprom_chips()

        # Get list of pairs of i2c bus and EEPROM device addresses in the host
        l_chips = self.cv_HOST.host_get_list_of_eeprom_chips()
        for l_args in l_chips:
            # Accessing the registers visible through the i2cbus using i2cdump utility
            # l_args format: "0 0x51","1 0x53",.....etc
            self.i2c_dump(l_args)

        # Getting the list of sysfs eeprom interfaces
        l_res = self.cv_HOST.host_run_command(
            "find /sys/ -name eeprom; echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            pass
        else:
            l_msg = "EEPROM sysfs entries are not created"
            print l_msg
            raise OpTestError(l_msg)
        for l_dev in l_res:
            if l_dev.__contains__("eeprom"):
                # Getting the eeprom device data using hexdump utility in hex + Ascii format
                self.cv_HOST.host_hexdump(l_dev)
            else:
                pass
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This i2cdump function takes arguments in pair of a string like "i2cbus address".
    #        i2cbus indicates the number or name of the I2C bus to be scanned. This number should
    #        correspond  to  one  of  the busses listed by i2cdetect -l. address indicates
    #        the address to be scanned on that bus, and is an integer between 0x03 and 0x77
    #        i2cdump is a program to examine registers visible through the I2C bus
    #
    # @param i_args @type string: this is the argument to i2cdump utility
    #                             args are in the form of "i2c-bus-number eeprom-chip-address"
    #                             Ex: "0 0x51","3 0x52" ....etc
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def i2c_dump(self, i_args):
        l_res = self.cv_HOST.host_run_command("i2cdump -f -y %s; echo $?" %
                                              i_args)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "i2cdump failed on addr %s" % i_args
            print l_msg
            raise OpTestError(l_msg)
Exemplo n.º 22
0
class OpTestOOBIPMI():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  It will execute and test all Out-of-band ipmi commands.
    #         bmc, channel, chassis, dcmi, echo, event, exec, firewall, fru, lan
    #         mc, pef, power, raw, sdr, sel, sensor, session, user
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_oob_ipmi(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for ipmitool command and lm_sensors package
        self.cv_HOST.host_check_command("ipmitool")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "ipmitool")
        print "Installed package: %s" % l_pkg

        # loading below ipmi modules based on config option
        # ipmi_devintf, ipmi_powernv and ipmi_masghandler
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_DEVICE_INTERFACE,
            BMC_CONST.IPMI_DEV_INTF)
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_POWERNV, BMC_CONST.IPMI_POWERNV)
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_HANDLER,
            BMC_CONST.IPMI_MSG_HANDLER)

        test_cases = [
            self.test_chassis, self.test_chassisIdentifytests,
            self.test_chassisBootdev, self.test_Info,
            self.test_sdr_list_by_type, self.test_sdr_elist_by_type,
            self.test_sdr_type_list, self.test_sdr_get_id, self.test_fru_print,
            self.test_fru_read, self.test_mc, self.test_sensor_list,
            self.test_sensor_get_host_status, self.test_sensor_get_os_boot,
            self.test_sel_info, self.test_sel_list, self.test_sel_elist,
            self.test_set_sel_time, self.test_sel_time_get,
            self.test_sel_list_first_3_entries,
            self.test_sel_list_last_3_entries, self.test_sel_get_functionality,
            self.test_sel_clear_functionality, self.test_channel,
            self.test_dcmi, self.test_echo, self.test_event,
            self.test_firewall, self.test_pef, self.test_raw, self.test_exec,
            self.test_bmc_golden_side_version,
            self.test_get_pnor_partition_size_cmd,
            self.test_bmc_boot_completed_cmd, self.test_get_led_state_cmd,
            self.test_set_led_state_cmd
        ]

        fail_count = 0

        for test in test_cases:
            try:
                print "OOB IPMI: test case %s" % test
                test(self)
            except:
                print "Test Fail: %s failed" % test
                fail_count += 1
                print sys.exc_info()
                continue

        print "OOB IPMI: Test case failure count %s" % fail_count

        print self.cv_IPMI.ipmi_get_bmc_golden_side_version()
        print self.cv_IPMI.ipmi_get_pnor_partition_size("NVRAM")
        print self.cv_IPMI.ipmi_get_pnor_partition_size("GUARD")
        print self.cv_IPMI.ipmi_get_pnor_partition_size("BOOTKERNEL")
        print self.cv_IPMI.ipmi_get_bmc_boot_completion_status()
        print self.cv_IPMI.ipmi_get_fault_led_state()
        print self.cv_IPMI.ipmi_get_power_on_led_state()
        print self.cv_IPMI.ipmi_get_host_status_led_state()
        print self.cv_IPMI.ipmi_get_chassis_identify_led_state()
        self.cv_IPMI.ipmi_enable_fan_control_task_command()
        self.cv_IPMI.ipmi_get_fan_control_task_state_command()
        self.cv_IPMI.ipmi_disable_fan_control_task_command()
        self.cv_IPMI.ipmi_get_fan_control_task_state_command()

    ##
    # @brief  This function is used to get the bmc golden image version.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_bmc_golden_side_version(self):
        print "OOB IPMI: Get BMC Golden side Version Test"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_BMC_GOLDEN_SIDE_VERSION)

    ##
    # @brief This function is used to get partition size of given PNOR Partition.
    #        Currently added NVRAM,GUARD and BOOTKERNEL partitions.
    #        TODO: Add all the necessary partitions to get the size.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_get_pnor_partition_size_cmd(self):
        print "OOB IPMI: Get size of PNOR partition Test"
        print "OOB IPMI: Getting the size of NVRAM partition"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_NVRAM_PARTITION_SIZE)
        print "OOB IPMI: Getting the size of GUARD partition"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_GUARD_PARTITION_SIZE)
        print "OOB IPMI: Getting the size of BOOTKERNEL partition"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_BOOTKERNEL_PARTITION_SIZE)

    ##
    # @brief This function is used to test reading of pnor partition data
    #        via ipmitool command. Here it will currently read NVRAM
    #        and FIRDATA partition's data of size 254 bytes.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_read_pnor_partition_data(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_READ_NVRAM_PARTITION_DATA)
        self.run_ipmi_cmd(BMC_CONST.IPMI_READ_FIRDATA_PARTITION_DATA)

    ##
    # @brief This function is used to check whether BMC Completed Booting.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_bmc_boot_completed_cmd(self):
        print "OOB IPMI: Get BMC boot completion status Test"
        self.run_ipmi_cmd(BMC_CONST.IPMI_HAS_BMC_BOOT_COMPLETED)

    ##
    # @brief This command is used to get the State of below Supported LED.
    #        LED Number Table:
    #        Fault RollUP LED      0x00
    #        Power ON LED          0x01
    #        Host Status LED       0x02
    #        Chassis Identify LED  0x03
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_get_led_state_cmd(self):
        print "OOB IPMI: Get state of various LED's"
        print "LED: Fault RollUP LED      0x00"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_FAULT_ROLLUP)
        print "LED: Power ON LED          0x01"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_POWER_ON)
        print "LED: Host Status LED       0x02"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_HOST_STATUS)
        print "LED: Chassis Identify LED  0x03"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_CHASSIS_IDENTIFY)

    ##
    # @brief This function is used to test set LED state feature.
    #        LED Number Table:
    #        Fault RollUP LED      0x00
    #        Power ON LED          0x01
    #        Host Status LED       0x02
    #        Chassis Identify LED  0x03
    #        LED State Table:
    #        LED State to be set.
    #               0x0  LED OFF
    #               0x1  LED ON
    #               0x2  LED Standby Blink Rate
    #               0x3  LED Slow Blink rate.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_set_led_state_cmd(self):
        print "OOB IPMI: Set LED state of various LED's"
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x0")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x1")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x2")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x3")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x0")
        self.cv_IPMI.ipmi_get_power_on_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x1")
        self.cv_IPMI.ipmi_get_power_on_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x2")
        self.cv_IPMI.ipmi_get_power_on_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x3")
        self.cv_IPMI.ipmi_get_power_on_led_state()

    ##
    # @brief Step 1: Stop Fan Control Thread:
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x12 0x00
    #        Step 2: Fan Control STOPPED OEM SEL created
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> sel list |grep OEM
    #           7b | 04/20/2015 | 03:03:14 | OEM record c0 | 000000 | 3a1100ffffff
    #        Step 3: #Run IsFanRunning OEM Command
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x13
    #           00
    #
    # @return return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_fan_control_algorithm_1(self):
        print "OOB IPMI: Testing Fan control disable functionality"
        self.cv_IPMI.ipmi_enable_fan_control_task_command()
        self.cv_IPMI.ipmi_sdr_clear()
        l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
        if str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_RUNNING) in l_state:
            self.cv_IPMI.ipmi_disable_fan_control_task_command()
            l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
            if str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_NOT_RUNNING) in l_state:
                l_output = self.cv_IPMI.ipmi_get_sel_list()
                print l_output
                if "OEM" in l_output:
                    print "IPMI: Disabling of fan control creates an OEM SEL event"
                    return BMC_CONST.FW_SUCCESS
                else:
                    l_msg = "IPMI: Disabling of fan control doesn't create an OEM SEL event"
                    raise OpTestError(l_msg)
            else:
                l_msg = "IPMI: Fan control thread still running, disable failed"
                raise OpTestError(l_msg)
        else:
            l_msg = "IPMI: Fan control thread still in not running state, enable failed"
            raise OpTestError(l_msg)

    ##
    # @brief Step 1: Start Fan Control Thread:
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x12 0x01
    #        Step 2: Fan Control STOPPED OEM SEL created
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> sel list |grep OEM
    #           7b | 04/20/2015 | 03:03:14 | OEM record c0 | 000000 | 3a1100ffffff
    #        Step 3: #Run IsFanRunning OEM Command
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x13
    #           01
    #
    # @return return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_fan_control_algorithm_2(self):
        print "OOB IPMI: Testing Fan control enable functionality"
        self.cv_IPMI.ipmi_disable_fan_control_task_command()
        self.cv_IPMI.ipmi_sdr_clear()
        l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
        if l_state == str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_NOT_RUNNING):
            self.cv_IPMI.ipmi_enable_fan_control_task_command()
            l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
            if l_state == str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_RUNNING):
                l_output = self.cv_IPMI.ipmi_get_sel_list()
                print l_output
                if "OEM" in l_output:
                    print "IPMI: Enabling of fan control creates an OEM SEL event"
                    return BMC_CONST.FW_SUCCESS
                else:
                    l_msg = "IPMI: Enabling of fan control doesn't create an OEM SEL event"
                    raise OpTestError(l_msg)
            else:
                l_msg = "IPMI: Fan control thread still in not running state, enable failed"
                raise OpTestError(l_msg)
        else:
            l_msg = "IPMI: Fan control thread still running, disable failed"
            raise OpTestError(l_msg)

    ##
    # @brief  It will check basic channel functionalities: info and authentication capabilities.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_channel(self):
        print "OOB IPMI: Channel Tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHANNEL_AUTHCAP)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHANNEL_INFO)

    ##
    # @brief  It will execute and test the return code of ipmi command.
    #
    # @param i_cmd @type string:The ipmitool command, for example: chassis power on; echo $?
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def run_ipmi_cmd(self, i_cmd):
        l_cmd = i_cmd
        l_res = self.cv_IPMI.ipmitool_execute_command(l_cmd)
        print l_res
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI: command failed %c" % l_cmd
            raise OpTestError(l_msg)
        return l_res

    ##
    # @brief  It will execute and test the ipmi chassis <cmd> commands
    #         cmd: status, poh, restart_cause, policy list and policy set
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassis(self):
        print "OOB IPMI: Chassis tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_STATUS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_POH)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_RESTART_CAUSE)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_POLICY_LIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_POLICY_ALWAYS_OFF)

    ##
    # @brief  It will execute and test the ipmi chassis identify commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassisIdentifytests(self):
        print "OOB IPMI: chassis identify tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY_5)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY_FORCE)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY)

    ##
    # @brief  It will execute and test the functionality of ipmi chassis bootdev <dev>
    #         dev: none,pxe,cdrom,disk,bios,safe,diag,floppy and none.
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    @staticmethod
    def test_chassisBootdev(self):
        print "OOB IPMI: chassis bootdevice tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_PXE)
        self.verify_bootdev("pxe")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_CDROM)
        self.verify_bootdev("cdrom")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_DISK)
        self.verify_bootdev("disk")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_BIOS)
        self.verify_bootdev("bios")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_SAFE)
        self.verify_bootdev("safe")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_DIAG)
        self.verify_bootdev("diag")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_FLOPPY)
        self.verify_bootdev("floppy")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")

    ##
    # @brief  It will verify whether setting of given bootdevice is honoured or not
    #         by reading chassis bootparam get 5
    #
    # @param i_dev @type string: boot device name: Ex safe, disk and cdrom
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    def verify_bootdev(self, i_dev):
        l_res = self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTPARAM_GET_5)
        if i_dev == "safe":
            l_msg = "Force Boot from default Hard-Drive, request Safe-Mode"
        elif i_dev == "disk":
            l_msg = "Force Boot from default Hard-Drive"
        elif i_dev == "diag":
            l_msg = "Force Boot from Diagnostic Partition"
        elif i_dev == "bios":
            l_msg = "Force Boot into BIOS Setup"
        elif i_dev == "pxe":
            l_msg = "Force PXE"
        elif i_dev == "cdrom":
            l_msg = "Force Boot from CD/DVD"
        elif i_dev == "none":
            l_msg = "No override"
        elif i_dev == "floppy":
            l_msg = "Force Boot from Floppy/primary removable media"
        else:
            print "pass proper bootdevice"

        for l_line in l_res:
            if l_line.__contains__(l_msg):
                print "Verifying bootdev is successfull for %s" % i_dev
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Boot device is not set to %s" % i_dev
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi <sdr/sel/mc/channel> info related commands.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_Info(self):
        print "OOB IPMI: info tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHANNEL_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_INFO)

    ##
    # @brief  It will execute and test the ipmi sdr list <all/fru/event/mcloc/compact/full/generic>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_list_by_type(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_ALL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_FRU)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_EVENT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_MCLOC)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_COMPACT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_FULL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr elist <all/fru/event/mcloc/compact/full/generic>
    #         commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_elist_by_type(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_ALL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_FRU)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_EVENT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_MCLOC)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_COMPACT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_FULL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr type <Temp/fan/Powersupply> commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_type_list(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_LIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_TEMPERATURE)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_FAN)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_POWER_SUPPLY)

    ##
    # @brief  It will execute and test the ipmi sdr get <sensor-id> command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_get_id(self):
        l_cmd = BMC_CONST.IPMI_SDR_GET_WATCHDOG + "; echo $?"
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi fru print command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_print(self):
        print "OOB IPMI: Fru tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_FRU_PRINT)

    ##
    # @brief  It will execute and test the ipmi fru read command.
    #         then the output file is displayed by hexdump
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_read(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_FRU_READ)
        l_res = commands.getstatusoutput("hexdump -C file_fru")
        if int(l_res[0]) == 0:
            print l_res[1]
        else:
            l_msg = "Failing to do hexdump for fru file"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi sensor list functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_list(self):
        print "OOB IPMI: Sensor tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_SENSOR_LIST)

    ##
    # @brief  It will execute and test the ipmi sensor get <id> functionality
    #
    # @param i_sensor @type string:sensor id to retrieve the data
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sensor_byid(self, i_sensor):
        l_cmd = "sensor get \"%s\"; echo $?" % i_sensor
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the management controller(mc) commands functionality
    #         info-Displays information about the BMC hardware, including device revision,
    #              firmware revision, IPMI version supported, manufacturer ID,  and  information
    #               on additional device support
    #         watchdog get-Show current Watchdog Timer settings and countdown state.
    #         watchdog off-Turn off a currently running Watchdog countdown timer.
    #         watchdog reset-Reset the Watchdog Timer to its most recent state and restart the countdown timer.
    #         selftest- Check on the basic health of the BMC by executing the
    #                   Get Self Test results command and report the results.
    #         setenables-Enables  or disables the given option
    #         getenables-Displays a list of the currently enabled options for the BMC.
    #         getsysinfo-Retrieves system info from bmc for given argument
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_mc(self):
        print "OOB IPMI: MC tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_WATCHDOG_GET)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SETENABLES_OEM_0_OFF)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SETENABLES_OEM_0_ON)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_WATCHDOG_OFF)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_WATCHDOG_RESET)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_GETSYS_INFO)

    ##
    # @brief  It will execute and test the ipmi sel info functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_info(self):
        print "OOB IPMI: SEL tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_INFO)

    ##
    # @brief  It will execute and test ipmi sel list functionality.
    #         the entire contents of the System Event Log are displayed.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_LIST)

    ##
    # @brief  It will execute and test the ipmi sel elist functionality
    #         If invoked as elist (extended list) it will also use the
    #         Sensor Data Record entries to display the sensor ID for
    #           the sensor that caused each event.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_elist(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_ELIST)

    ##
    # @brief  It will execute and test the ipmi sel time get functionality
    #         Displays the SEL clock's current time.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_time_get(self):
        l_res = self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_TIME_GET)
        return l_res

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @param i_time @type string: the value to be set as a sel time
    #               <time string> is of the form "MM/DD/YYYY HH:MM:SS"
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_time_set(self, i_time):
        l_cmd = "sel time set \'%s\'; echo $?" % i_time
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list first <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_first_n_entries(self, i_num):
        l_cmd = "sel list first %i; echo $?" % int(i_num)
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list last <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_last_n_entries(self, i_num):
        l_cmd = "sel list last %i; echo $?" % int(i_num)
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @param i_sel_id @type string: for example 0x05, 0x06..
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_get_byid(self, i_sel_id):
        l_cmd = "sel get %s; echo $?" % i_sel_id
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel clear functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_clear(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_CLEAR)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_sel_get_functionality(self):
        l_res = self.cv_IPMI.ipmitool_execute_command(
            "sel list first 3 | awk '{print $1}'; echo $?")
        l_list = l_res.splitlines()
        if int(l_list[-1]) == 0:
            if l_res.__contains__("SEL has no entries"):
                print "There are No sel entries to fetch"
                pass
            else:
                del l_list[-1]
                for l in l_list:
                    l_id = "0x" + l
                    self.test_sel_get_byid(l_id)
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Not able to get sel entries"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi sel clear functionality
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_sel_clear_functionality(self):
        self.test_sel_clear(self)
        l_res = self.cv_HOST.host_run_command("ipmitool sel list; echo $?")
        l_list = l_res.splitlines()
        for l_line in l_list:
            if l_line.__contains__("SEL has no entries"):
                print "Sel clear function got cleared event entries"
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "OOB IPMI: sel clear function failing in clearing entries"
            print l_msg
            print l_res
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the dcmi related ipmi commands.
    #         discover-This command is used to discover supported capabilities in DCMI
    #         Power reading-Get power related readings from the system.
    #               get_limit-Get the configured power limits.
    #         sensors-Prints the available DCMI sensors.
    #         get_mc_id_string-Get management controller identifier string
    #         get_temp_reading-Get Temperature Sensor Readings.
    #         get_conf_param-Get DCMI Configuration Parameters.
    #         oob_discover-Ping/Pong Message for DCMI Discovery
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_dcmi(self):
        print "OOB IPMI: dcmi tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)

    ##
    # @brief  It will execute and test the functionality of ipmi echo command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_echo(self):
        print "OOB IPMI: echo tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_ECHO_DONE)

    ##
    # @brief  It will execute and test event related commands to test sel functionality.
    #         Send a pre-defined test event to the System Event Log.  The following
    #         events are included as a means to test the functionality of  the  System
    #         Event Log component of the BMC (an entry will be added each time the
    #         event N command is executed)
    #         Currently supported values for N are:
    #         1    Temperature: Upper Critical: Going High
    #         2    Voltage Threshold: Lower Critical: Going Low
    #         3    Memory: Correctable ECC
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_event(self):
        print "OOB IPMI: event tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_EVENT_1)
        self.run_ipmi_cmd(BMC_CONST.IPMI_EVENT_2)
        self.run_ipmi_cmd(BMC_CONST.IPMI_EVENT_3)

    ##
    # @brief  It will execute and test ipmi exec command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_exec(self):
        print "OOB IPMI: exec tests"
        pass
        # TODO: need to execute ipmi commands from a file

    ##
    # @brief  It will execute and test firmware firewall info command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_firewall(self):
        print "OOB IPMI: Firewall test"
        self.run_ipmi_cmd(BMC_CONST.IPMI_FIREWALL_INFO)

    ##
    # @brief  It will execute and test pef related commands:
    #         info:This command will query the BMC and print information about the PEF supported features.
    #         status: This command prints the current PEF status
    #         policy: This command lists the PEF policy table entries
    #         list: This  command  lists  the PEF table entries.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_pef(self):
        print "OOB IPMI: Pef tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_STATUS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_POLICY)
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_LIST)

    ##
    # @brief This will test raw IPMI commands. For example to query the POH counter with a raw command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_raw(self):
        print "OOB IPMI: raw command execution tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_RAW_POH)

    ##
    # @brief  It will execute and test the ipmi sensor get "Host Status" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_host_status(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_HOST_STATUS)

    ##
    # @brief  It will execute and test the ipmi sensor get "OS Boot" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_os_boot(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OS_BOOT)

    ##
    # @brief  It will execute and test the ipmi sensor get "OCC Active" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_occ_active(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OCC_ACTIVE)

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_set_sel_time(self):
        l_res = self.test_sel_time_get(self)
        self.test_sel_time_set(l_res[0])

    ##
    # @brief  It will execute and test the ipmi sel list first <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_first_3_entries(self):
        self.test_sel_list_first_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)

    ##
    # @brief  It will execute and test the ipmi sel list last <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_last_3_entries(self):
        self.test_sel_list_last_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)
Exemplo n.º 23
0
class OpTestSwitchEndianSyscall():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd,i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  If git and gcc commands are availble on host, this function will clone linux
    #         git repository and check for switch_endian_test directory and make
    #         the required files. And finally execute bin file switch_endian_test.
    #
    # @return BMC_CONST.FW_SUCCESS-success or BMC_CONST.FW_FAILED-fail
    #
    def testSwitchEndianSysCall(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        self.cv_HOST.host_get_OS_Level()

        # Check whether git and gcc commands are available on host
        self.cv_HOST.host_check_command("git", "gcc")

        # Clone latest linux git repository into l_dir
        l_dir = "/tmp/linux"
        self.cv_HOST.host_clone_linux_source(l_dir)

        # Check for switch_endian test directory.
        self.check_dir_exists(l_dir)

        # make the required files
        self.make_test(l_dir)

        # Run the switch_endian sys call test once
        l_rc = self.run_once(l_dir)
        if int(l_rc) == 1:
            print "Switch endian sys call test got succesful"
            return BMC_CONST.FW_SUCCESS
        else:
            print "Switch endian sys call test failed"
            return BMC_CONST.FW_FAILED

    ##
    # @brief  It will check for existence of switch_endian directory in the cloned repository
    #
    # @param i_dir @type string: linux source directory
    #
    # @return 1-success or raise OpTestError
    #
    def check_dir_exists(self, i_dir):
        l_dir = '%s/tools/testing/selftests/powerpc/switch_endian' % i_dir
        l_cmd = "test -d %s; echo $?" % l_dir
        print l_cmd
        l_res = self.cv_HOST.host_run_command(l_cmd)
        print l_res
        l_res = l_res.replace("\r\n", "")
        if int(l_res) == 0:
            print "Switch endian test directory exists"
            return 1
        else:
            l_msg = "Switch endian directory is not present"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will prepare for executable bin files using make command
    #         At the end it will check for bin file switch_endian_test and
    #         will throw an exception in case of missing bin file after make
    #
    # @param i_dir @type string: linux source directory
    #
    # @return 1-success or raise OpTestError
    #
    def make_test(self, i_dir):
        l_cmd = "cd %s/tools/testing/selftests/powerpc/switch_endian;\
                 make;" % i_dir
        print l_cmd
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_cmd = "test -f %s/tools/testing/selftests/powerpc/switch_endian/switch_endian_test; echo $?" % i_dir
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.replace("\r\n", "")
        if int(l_res) == 0:
            print "Executable binary switch_endian_test is available"
            return 1
        else:
            l_msg = "Switch_endian_test bin file is not present after make"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function will run executable file switch_endian_test and
    #        check for switch_endian() sys call functionality
    #
    # @param i_dir @type string: linux source directory
    #
    # @return 1-success ; 0-fail
    #
    def run_once(self, i_dir):
        l_cmd = "cd %s/tools/testing/selftests/powerpc/switch_endian/;\
                 ./switch_endian_test" % i_dir
        print l_cmd
        l_res = self.cv_HOST.host_run_command(l_cmd)
        if (l_res.__contains__('success: switch_endian_test')):
            return 1
        else:
            return 0
Exemplo n.º 24
0
class OpTestSensors():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd,i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will check for kernel config option CONFIG_SENSORS_IBMPOWERNV
    #        2. It will load ibmpowernv driver only on powernv platform
    #        3. It will check for sensors command existence and lm_sensors package
    #        4. start the lm_sensors service and detect any sensor chips
    #           using sensors-detect.
    #        5. At the end it will test sensors command functionality
    #           with different options
    #
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_hwmon_driver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for sensors config option CONFIG_SENSORS_IBMPOWERNV
        l_config = "CONFIG_SENSORS_IBMPOWERNV"

        l_val = self.cv_HOST.host_check_config(l_kernel, l_config)
        if l_val == "y":
            print "Driver build into kernel itself"
        else:
            print "Driver will be built as module"
            # Loading ibmpowernv driver only on powernv platform
            self.cv_HOST.host_load_ibmpowernv(l_oslevel)

        # Checking for sensors command and lm_sensors package
        self.cv_HOST.host_check_command("sensors")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "sensors")
        print "Installed package: %s" % l_pkg

        # Restart the lm_sensor service
        self.cv_HOST.host_start_lm_sensor_svc(l_oslevel)

        # To detect different sensor chips and modules
        res = self.cv_HOST.host_run_command("yes | sensors-detect")
        print res

        # Checking sensors command functionality with different options
        output = self.cv_HOST.host_run_command("sensors; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors not working,exiting...."
            raise OpTestError(l_msg)
        print output
        output = self.cv_HOST.host_run_command("sensors -f; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors -f not working,exiting...."
            raise OpTestError(l_msg)
        print output
        output = self.cv_HOST.host_run_command("sensors -A; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors -A not working,exiting...."
            raise OpTestError(l_msg)
        print output
        output = self.cv_HOST.host_run_command("sensors -u; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors -u not working,exiting...."
            raise OpTestError(l_msg)
        print output
        return BMC_CONST.FW_SUCCESS
class OpTestMCColdResetEffects():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP, i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                                      i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

        self.opTestSensors = OpTestSensors(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                           i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                                           i_hostuser, i_hostPasswd)

    ##
    # @brief  This function will test BMC Cold reset vs Host FW status
    #         1. When system is in runtime issue BMC Cold reset.
    #         2. Check Host FW services and drivers.
    #         3. Run sensors command
    #         4. Get list of chips
    #         5. This is expected to fail.
    #           https://github.com/open-power/op-build/issues/482
    #         6. Reboot the system at the end of test.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_bmc_cold_reset_effects(self):
        print "Test BMC Cold reset effects versus Host Firmware Status"
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Issue BMC Cold reset"
        result = True
        try:
            self.cv_SYSTEM.sys_cold_reset_bmc()
            l_dir = BMC_CONST.SKIBOOT_WORKING_DIR
            self.cv_HOST.host_clone_skiboot_source(l_dir)
            self.cv_HOST.host_compile_xscom_utilities(l_dir)
            l_con = self.cv_SYSTEM.sys_get_ipmi_console()
            self.cv_IPMI.ipmi_host_login(l_con)
            self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
            self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("cd %s/external/xscom-utils/; ./getscom -l" % l_dir)
            self.opTestSensors.test_hwmon_driver()
            self.cv_SYSTEM.sys_ipmi_close_console(l_con)
        except:
            result = False
            pass
        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        self.cv_IPMI.ipmi_power_off()
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        if result is False:
            raise OpTestError("MC Cold reset vs Host FW Test failed")
Exemplo n.º 26
0
class OpTestEnergyScale():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_platName=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.cv_PLATFORM = i_platName
        self.util = OpTestUtil()

    ##
    # @brief This function will get and return platform power limits for supported machine
    #
    # @param i_platform type: str platform name to get the power limits
    #
    # @return l_power_limit_low lower platform power limit
    #         l_power_limit_high higher platform power limit
    #         or raise OpTestError if it is a new platform
    #
    def get_platform_power_limits(self, i_platform):
        l_platform = i_platform
        if BMC_CONST.HABANERO in l_platform:
            l_power_limit_high = BMC_CONST.HABANERO_POWER_LIMIT_HIGH
            l_power_limit_low = BMC_CONST.HABANERO_POWER_LIMIT_LOW
        elif BMC_CONST.FIRESTONE in l_platform:
            l_power_limit_high = BMC_CONST.FIRESTONE_POWER_LIMIT_HIGH
            l_power_limit_low = BMC_CONST.FIRESTONE_POWER_LIMIT_LOW
        elif BMC_CONST.GARRISON in l_platform:
            l_power_limit_high = BMC_CONST.GARRISON_POWER_LIMIT_HIGH
            l_power_limit_low = BMC_CONST.GARRISON_POWER_LIMIT_LOW
        else:
            l_msg = "New platform, add power limit support to this platform and retry"
            raise OpTestError(l_msg)
        return l_power_limit_low, l_power_limit_high

    ##
    # @brief  This function will test Energy scale features at standby state
    #         1. Power OFF the system.
    #         2. Validate below Energy scale features at standby state
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power set_limit limit <value>  :Power Limit Requested in Watts.
    #            ipmitool dcmi power activate                 :Activate the set power limit.
    #            ipmitool dcmi power deactivate               :Deactivate the set power limit.
    #         3. Once platform power limit activated execute below dcmi commands at standby state.
    #            ipmitool dcmi discover                       :This command is used to discover
    #                                                           supported  capabilities in DCMI.
    #            ipmitool dcmi power reading                  :Get power related readings from the system.
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power sensors                  :Prints the available DCMI sensors.
    #            ipmitool dcmi get_temp_reading               :Get Temperature Sensor Readings.
    #         4. Power ON the system.
    #         5. Check after system booted to runtime, whether occ's are active or not.
    #         6. Again in runtime execute all dcmi commands to check the functionality.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_energy_scale_at_standby_state(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Energy Scale Test 1: Get, Set, activate and deactivate platform power limit at power off"
        l_power_limit_low, l_power_limit_high = self.get_platform_power_limits(
            self.cv_PLATFORM)

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_sdr_clear()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_high)
        self.cv_IPMI.ipmi_activate_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_low)
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_high)
        self.cv_IPMI.ipmi_get_power_limit()
        print "Get All dcmi readings at power off"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print self.cv_IPMI.ipmi_get_power_limit()
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)

    ##
    # @brief  This function will test Energy scale features at standby state
    #         1. Power OFF the system.
    #         2. Power On the system to boot to host OS
    #         2. Validate below Energy scale features at runtime state
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power set_limit limit <value>  :Power Limit Requested in Watts.
    #            ipmitool dcmi power activate                 :Activate the set power limit.
    #            ipmitool dcmi power deactivate               :Deactivate the set power limit.
    #         3. Once platform power limit activated execute below dcmi commands at runtime state.
    #            ipmitool dcmi discover                       :This command is used to discover
    #                                                           supported  capabilities in DCMI.
    #            ipmitool dcmi power reading                  :Get power related readings from the system.
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power sensors                  :Prints the available DCMI sensors.
    #            ipmitool dcmi get_temp_reading               :Get Temperature Sensor Readings.
    #         4. Issue Power OFF/ON to check whether system boots after setting platform power limit at runtime.
    #         5. Again in runtime execute all dcmi commands to check the functionality.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_energy_scale_at_runtime_state(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Energy Scale Test 2: Get, Set, activate and deactivate platform power limit at runtime"
        l_power_limit_low, l_power_limit_high = self.get_platform_power_limits(
            self.cv_PLATFORM)

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at power off"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        self.cv_IPMI.ipmi_sdr_clear()
        print self.cv_IPMI.ipmi_get_power_limit()
        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_high)
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_set_power_limit(l_power_limit_low)
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_deactivate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        self.cv_IPMI.ipmi_activate_power_limit()
        print self.cv_IPMI.ipmi_get_power_limit()
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)

    ##
    # @brief  This function will test below dcmi commands at both standby and runtime states
    #            ipmitool dcmi discover                       :This command is used to discover
    #                                                           supported  capabilities in DCMI.
    #            ipmitool dcmi power reading                  :Get power related readings from the system.
    #            ipmitool dcmi power get_limit                :Get the configured power limits.
    #            ipmitool dcmi power sensors                  :Prints the available DCMI sensors.
    #            ipmitool dcmi get_temp_reading               :Get Temperature Sensor Readings.
    #            ipmitool dcmi get_mc_id_string               :Get management controller identifier string.
    #            ipmitool dcmi get_conf_param                 :Get DCMI Configuration Parameters.
    #            ipmitool dcmi oob_discover                   :Ping/Pong Message for DCMI Discovery.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_dcmi_at_standby_and_runtime_states(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Energy scale Test 3: Get Sensors, Temperature and Power reading's at power off and runtime"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at power off"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)
        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
        else:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        print "Get All dcmi readings at runtime"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)

    ##
    # @brief  It will execute and test the return code of ipmi command.
    #
    # @param i_cmd @type string:The ipmitool command, for example: chassis power on; echo $?
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def run_ipmi_cmd(self, i_cmd):
        l_cmd = i_cmd
        l_res = self.cv_IPMI.ipmitool_execute_command(l_cmd)
        print l_res
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI: command failed %c" % l_cmd
            raise OpTestError(l_msg)
        return l_res
Exemplo n.º 27
0
class OpTestEM():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS and kernel versions.
    #        2. Check the cpupower utility is available in host.
    #        3. Get available cpu scaling frequencies
    #        4. Set the userspace governer for all cpu's
    #        5. test the cpufreq driver by set/verify cpu frequency
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_cpu_freq_states(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        self.cv_HOST.host_check_command("cpupower")
        # Get available cpu scaling frequencies
        l_res = self.cv_HOST.host_run_command("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies")
        freq_list = (l_res.strip()).split(' ')
        print freq_list

        # Set the cpu governer to userspace
        self.set_cpu_gov("userspace")
        self.verify_cpu_gov("userspace")
        for i in range(1, 100):
            i_freq = random.choice(freq_list)
            self.set_cpu_freq(i_freq)
            self.verify_cpu_freq(i_freq)

        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS and kernel versions.
    #        2. Check the cpupower utility is available in host.
    #        3. Set the userspace governer for all cpu's
    #        4. test the cpuidle driver by enable/disable/verify the idle states
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_cpu_idle_states(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        self.cv_HOST.host_check_command("cpupower")
        # currently p8 cpu has 3 states
        for i in (0, 1, 2):
            self.enable_idle_state(i)
            self.verify_enable_idle_state(i)
        for i in (0, 1, 2):
            self.disable_idle_state(i)
            self.verify_disable_idle_state(i)

        return BMC_CONST.FW_SUCCESS

    ##
    # @brief sets the cpu frequency with i_freq value
    #
    # @param i_freq @type str: this is the frequency of cpu to be set
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_cpu_freq(self, i_freq):
        l_cmd = "for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_setspeed; do echo %s > $i; done" % i_freq
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief verify the cpu frequency with i_freq value
    #
    # @param i_freq @type str: this is the frequency to be verified with cpu frequency
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_cpu_freq(self, i_freq):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"
        cur_freq = self.cv_HOST.host_run_command(l_cmd)
        if cur_freq.strip() == i_freq:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU frequency not changed to %s" % i_freq
            raise OpTestError(l_msg)

    ##
    # @brief sets the cpu governer with i_gov governer
    #
    # @param i_gov @type str: this is the governer to be set for all cpu's
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def set_cpu_gov(self, i_gov):
        l_cmd = "for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo %s > $i; done" % i_gov
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief verify the cpu governer with i_gov governer
    #
    # @param i_gov @type str: this is the governer to be verified with cpu governer
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_cpu_gov(self, i_gov):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
        cur_gov = self.cv_HOST.host_run_command(l_cmd)
        if cur_gov.strip() == i_gov:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU governor not changed to %s" % i_gov
            raise OpTestError(l_msg)

    ##
    # @brief enable cpu idle state i_idle
    #
    # @param i_idle @type str: this is the cpu idle state to be enabled
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def enable_idle_state(self, i_idle):
        l_cmd = "cpupower idle-set -e %s" % i_idle
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief disable cpu idle state i_idle
    #
    # @param i_idle @type str: this is the cpu idle state to be disabled
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def disable_idle_state(self, i_idle):
        l_cmd = "cpupower idle-set -d %s" % i_idle
        self.cv_HOST.host_run_command(l_cmd)

    ##
    # @brief verify whether cpu idle state i_idle enabled
    #
    # @param i_idle @type str: this is the cpu idle state to be verified for enable
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_enable_idle_state(self, i_idle):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpuidle/state%s/disable" % i_idle
        cur_value = self.cv_HOST.host_run_command(l_cmd)
        if cur_value.strip() == "0":
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU state%s not enabled" % i_idle
            raise OpTestError(l_msg)

    ##
    # @brief verify whether cpu idle state i_idle disabled
    #
    # @param i_idle @type str: this is the cpu idle state to be verified for disable
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def verify_disable_idle_state(self, i_idle):
        l_cmd = "cat /sys/devices/system/cpu/cpu0/cpuidle/state%s/disable" % i_idle
        cur_value = self.cv_HOST.host_run_command(l_cmd)
        if cur_value.strip() == "1":
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "CPU state%s not disabled" % i_idle
            raise OpTestError(l_msg)
Exemplo n.º 28
0
class OpTestSensors():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will check for kernel config option CONFIG_SENSORS_IBMPOWERNV
    #        2. It will load ibmpowernv driver only on powernv platform
    #        3. It will check for sensors command existence and lm_sensors package
    #        4. start the lm_sensors service and detect any sensor chips
    #           using sensors-detect.
    #        5. At the end it will test sensors command functionality
    #           with different options
    #
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_hwmon_driver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for sensors config option CONFIG_SENSORS_IBMPOWERNV
        l_config = "CONFIG_SENSORS_IBMPOWERNV"

        l_val = self.cv_HOST.host_check_config(l_kernel, l_config)
        if l_val == "y":
            print "Driver build into kernel itself"
        else:
            print "Driver will be built as module"
            # Loading ibmpowernv driver only on powernv platform
            self.cv_HOST.host_load_ibmpowernv(l_oslevel)

        # Checking for sensors command and lm_sensors package
        self.cv_HOST.host_check_command("sensors")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "sensors")
        print "Installed package: %s" % l_pkg

        # Restart the lm_sensor service
        self.cv_HOST.host_start_lm_sensor_svc(l_oslevel)

        # To detect different sensor chips and modules
        res = self.cv_HOST.host_run_command("yes | sensors-detect")
        print res

        # Checking sensors command functionality with different options
        output = self.cv_HOST.host_run_command("sensors; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors not working,exiting...."
            raise OpTestError(l_msg)
        print output
        output = self.cv_HOST.host_run_command("sensors -f; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors -f not working,exiting...."
            raise OpTestError(l_msg)
        print output
        output = self.cv_HOST.host_run_command("sensors -A; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors -A not working,exiting...."
            raise OpTestError(l_msg)
        print output
        output = self.cv_HOST.host_run_command("sensors -u; echo $?")
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "sensors -u not working,exiting...."
            raise OpTestError(l_msg)
        print output
        return BMC_CONST.FW_SUCCESS
Exemplo n.º 29
0
def _config_read():
    """ returns bmc system and test config options """
    bmcConfig = ConfigParser.RawConfigParser()
    configFile = os.path.join(os.path.dirname(__file__), 'op_ci_tools.cfg')
    bmcConfig.read(configFile)
    return dict(bmcConfig.items('bmc')), dict(bmcConfig.items('test')), dict(
        bmcConfig.items('host'))


''' Read the configuration settings into global space so they can be used by
    other functions '''

bmcCfg, testCfg, hostCfg = _config_read()
opTestSys = OpTestSystem(bmcCfg['ip'], bmcCfg['username'], bmcCfg['password'],
                         bmcCfg.get('usernameipmi'),
                         bmcCfg.get('passwordipmi'), testCfg['ffdcdir'],
                         hostCfg['hostip'], hostCfg['hostuser'],
                         hostCfg['hostpasswd'])


def validate_host():
    """This function Validates the host and waits for host to connect
    :returns: int -- 0: success, 1: error
    """
    opTestSys.sys_bmc_validate_host()

    return 0


def outofband_fw_update_hpm():
    """This function Update the BMC fw image using hpm file
    def objs(self):
        host = OpTestHost(self.args.host_ip,
                          self.args.host_user,
                          self.args.host_password,
                          self.args.bmc_ip)
        if self.args.bmc_type in ['AMI']:
            ipmi = OpTestIPMI(self.args.bmc_ip,
                              self.args.bmc_usernameipmi,
                              self.args.bmc_passwordipmi,
                              self.args.ffdcdir, host=host)
            web = OpTestWeb(self.args.bmc_ip,
                            self.args.bmc_usernameipmi,
                            self.args.bmc_passwordipmi)
            bmc = OpTestBMC(ip=self.args.bmc_ip,
                            username=self.args.bmc_username,
                            password=self.args.bmc_password,
                            ipmi=ipmi,
                            web=web,
            )
            self.op_system = OpTestSystem(
                i_ffdcDir=self.args.ffdcdir,
                state=self.startState,
                bmc=bmc,
                host=host,
            )
        elif self.args.bmc_type in ['FSP']:
            ipmi = OpTestIPMI(self.args.bmc_ip,
                              self.args.bmc_usernameipmi,
                              self.args.bmc_passwordipmi,
                              self.args.ffdcdir, host=host)
            bmc = OpTestFSP(self.args.bmc_ip,
                            self.args.bmc_username,
                            self.args.bmc_password,
                            ipmi=ipmi,
            )
            self.op_system = OpTestFSPSystem(
                i_ffdcDir=self.args.ffdcdir,
                state=self.startState,
                bmc=bmc,
                host=host,
            )
        elif self.args.bmc_type in ['OpenBMC']:
            ipmi = OpTestIPMI(self.args.bmc_ip,
                              self.args.bmc_usernameipmi,
                              self.args.bmc_passwordipmi,
                              self.args.ffdcdir, host=host)
            bmc = OpTestOpenBMC(self.args.bmc_ip,
                                self.args.bmc_username,
                                self.args.bmc_password,
                                ipmi=ipmi)
            self.op_system = OpTestOpenBMCSystem(
                host=host,
                bmc=bmc,
                state=self.startState,
            )
        elif self.args.bmc_type in ['qemu']:
            print repr(self.args)
            bmc = OpTestQemu(self.args.qemu_binary,
                             self.args.skiboot,
                             self.args.kernel,
                             self.args.initramfs)
            self.op_system = OpTestQemuSystem(host=host, bmc=bmc)
        else:
            raise Exception("Unsupported BMC Type")

        return
Exemplo n.º 31
0
class OpTestOOBIPMI():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                                      i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  It will execute and test all Out-of-band ipmi commands.
    #         bmc, channel, chassis, dcmi, echo, event, exec, firewall, fru, lan
    #         mc, pef, power, raw, sdr, sel, sensor, session, user
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_oob_ipmi(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
         # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for ipmitool command and lm_sensors package
        self.cv_HOST.host_check_command("ipmitool")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "ipmitool")
        print "Installed package: %s" % l_pkg

        # loading below ipmi modules based on config option
        # ipmi_devintf, ipmi_powernv and ipmi_masghandler
        self.cv_HOST.host_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_DEVICE_INTERFACE,
                                                      BMC_CONST.IPMI_DEV_INTF)
        self.cv_HOST.host_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_POWERNV,
                                                      BMC_CONST.IPMI_POWERNV)
        self.cv_HOST.host_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_HANDLER,
                                                      BMC_CONST.IPMI_MSG_HANDLER)

        test_cases = [self.test_chassis, self.test_chassisIdentifytests,
        self.test_chassisBootdev, self.test_Info, self.test_sdr_list_by_type,
        self.test_sdr_elist_by_type, self.test_sdr_type_list, self.test_sdr_get_id,
        self.test_fru_print, self.test_fru_read, self.test_mc,
        self.test_sensor_list, self.test_sensor_get_host_status,
        self.test_sensor_get_os_boot, self.test_sel_info, self.test_sel_list,
        self.test_sel_elist, self.test_set_sel_time,
        self.test_sel_time_get, self.test_sel_list_first_3_entries,
        self.test_sel_list_last_3_entries, self.test_sel_get_functionality,
        self.test_sel_clear_functionality, self.test_channel,
        self.test_dcmi, self.test_echo, self.test_event,
        self.test_firewall, self.test_pef, self.test_raw,
        self.test_exec, self.test_bmc_golden_side_version,
        self.test_get_pnor_partition_size_cmd,
        self.test_bmc_boot_completed_cmd,
        self.test_get_led_state_cmd, self.test_set_led_state_cmd]

        fail_count = 0

        for test in test_cases:
            try:
                print "OOB IPMI: test case %s" % test
                test(self)
            except:
                print "Test Fail: %s failed" % test
                fail_count += 1
                print sys.exc_info()
                continue

        print "OOB IPMI: Test case failure count %s" % fail_count

        print self.cv_IPMI.ipmi_get_bmc_golden_side_version()
        print self.cv_IPMI.ipmi_get_pnor_partition_size("NVRAM")
        print self.cv_IPMI.ipmi_get_pnor_partition_size("GUARD")
        print self.cv_IPMI.ipmi_get_pnor_partition_size("BOOTKERNEL")
        print self.cv_IPMI.ipmi_get_bmc_boot_completion_status()
        print self.cv_IPMI.ipmi_get_fault_led_state()
        print self.cv_IPMI.ipmi_get_power_on_led_state()
        print self.cv_IPMI.ipmi_get_host_status_led_state()
        print self.cv_IPMI.ipmi_get_chassis_identify_led_state()
        self.cv_IPMI.ipmi_enable_fan_control_task_command()
        self.cv_IPMI.ipmi_get_fan_control_task_state_command()
        self.cv_IPMI.ipmi_disable_fan_control_task_command()
        self.cv_IPMI.ipmi_get_fan_control_task_state_command()

    ##
    # @brief  This function is used to get the bmc golden image version.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_bmc_golden_side_version(self):
        print "OOB IPMI: Get BMC Golden side Version Test"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_BMC_GOLDEN_SIDE_VERSION)

    ##
    # @brief This function is used to get partition size of given PNOR Partition.
    #        Currently added NVRAM,GUARD and BOOTKERNEL partitions.
    #        TODO: Add all the necessary partitions to get the size.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_get_pnor_partition_size_cmd(self):
        print "OOB IPMI: Get size of PNOR partition Test"
        print "OOB IPMI: Getting the size of NVRAM partition"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_NVRAM_PARTITION_SIZE)
        print "OOB IPMI: Getting the size of GUARD partition"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_GUARD_PARTITION_SIZE)
        print "OOB IPMI: Getting the size of BOOTKERNEL partition"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_BOOTKERNEL_PARTITION_SIZE)

    ##
    # @brief This function is used to test reading of pnor partition data
    #        via ipmitool command. Here it will currently read NVRAM
    #        and FIRDATA partition's data of size 254 bytes.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_read_pnor_partition_data(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_READ_NVRAM_PARTITION_DATA)
        self.run_ipmi_cmd(BMC_CONST.IPMI_READ_FIRDATA_PARTITION_DATA)

    ##
    # @brief This function is used to check whether BMC Completed Booting.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_bmc_boot_completed_cmd(self):
        print "OOB IPMI: Get BMC boot completion status Test"
        self.run_ipmi_cmd(BMC_CONST.IPMI_HAS_BMC_BOOT_COMPLETED)

    ##
    # @brief This command is used to get the State of below Supported LED.
    #        LED Number Table:
    #        Fault RollUP LED      0x00
    #        Power ON LED          0x01
    #        Host Status LED       0x02
    #        Chassis Identify LED  0x03
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_get_led_state_cmd(self):
        print "OOB IPMI: Get state of various LED's"
        print "LED: Fault RollUP LED      0x00"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_FAULT_ROLLUP)
        print "LED: Power ON LED          0x01"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_POWER_ON)
        print "LED: Host Status LED       0x02"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_HOST_STATUS)
        print "LED: Chassis Identify LED  0x03"
        self.run_ipmi_cmd(BMC_CONST.IPMI_GET_LED_STATE_CHASSIS_IDENTIFY)

    ##
    # @brief This function is used to test set LED state feature.
    #        LED Number Table:
    #        Fault RollUP LED      0x00
    #        Power ON LED          0x01
    #        Host Status LED       0x02
    #        Chassis Identify LED  0x03
    #        LED State Table:
    #        LED State to be set.
    #               0x0  LED OFF
    #               0x1  LED ON
    #               0x2  LED Standby Blink Rate
    #               0x3  LED Slow Blink rate.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_set_led_state_cmd(self):
        print "OOB IPMI: Set LED state of various LED's"
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x0")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x1")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x2")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x00", "0x3")
        self.cv_IPMI.ipmi_get_fault_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x0")
        self.cv_IPMI.ipmi_get_power_on_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x1")
        self.cv_IPMI.ipmi_get_power_on_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x2")
        self.cv_IPMI.ipmi_get_power_on_led_state()
        self.cv_IPMI.ipmi_set_led_state("0x01", "0x3")
        self.cv_IPMI.ipmi_get_power_on_led_state()

    ##
    # @brief Step 1: Stop Fan Control Thread:
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x12 0x00
    #        Step 2: Fan Control STOPPED OEM SEL created
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> sel list |grep OEM
    #           7b | 04/20/2015 | 03:03:14 | OEM record c0 | 000000 | 3a1100ffffff
    #        Step 3: #Run IsFanRunning OEM Command
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x13
    #           00
    #
    # @return return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_fan_control_algorithm_1(self):
        print "OOB IPMI: Testing Fan control disable functionality"
        self.cv_IPMI.ipmi_enable_fan_control_task_command()
        self.cv_IPMI.ipmi_sdr_clear()
        l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
        if str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_RUNNING) in l_state:
            self.cv_IPMI.ipmi_disable_fan_control_task_command()
            l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
            if str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_NOT_RUNNING) in l_state:
                l_output = self.cv_IPMI.ipmi_get_sel_list()
                print l_output
                if "OEM" in l_output:
                    print "IPMI: Disabling of fan control creates an OEM SEL event"
                    return BMC_CONST.FW_SUCCESS
                else:
                    l_msg = "IPMI: Disabling of fan control doesn't create an OEM SEL event"
                    raise OpTestError(l_msg)
            else:
                l_msg = "IPMI: Fan control thread still running, disable failed"
                raise OpTestError(l_msg)
        else:
            l_msg = "IPMI: Fan control thread still in not running state, enable failed"
            raise OpTestError(l_msg)

    ##
    # @brief Step 1: Start Fan Control Thread:
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x12 0x01
    #        Step 2: Fan Control STOPPED OEM SEL created
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> sel list |grep OEM
    #           7b | 04/20/2015 | 03:03:14 | OEM record c0 | 000000 | 3a1100ffffff
    #        Step 3: #Run IsFanRunning OEM Command
    #           ipmitool -I lanplus -U admin -P admin -H <BMC IP> raw 0x3a 0x13
    #           01
    #
    # @return return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_fan_control_algorithm_2(self):
        print "OOB IPMI: Testing Fan control enable functionality"
        self.cv_IPMI.ipmi_disable_fan_control_task_command()
        self.cv_IPMI.ipmi_sdr_clear()
        l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
        if l_state == str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_NOT_RUNNING):
            self.cv_IPMI.ipmi_enable_fan_control_task_command()
            l_state = self.cv_IPMI.ipmi_get_fan_control_task_state_command()
            if l_state == str(BMC_CONST.IPMI_FAN_CONTROL_THREAD_RUNNING):
                l_output = self.cv_IPMI.ipmi_get_sel_list()
                print l_output
                if "OEM" in l_output:
                    print "IPMI: Enabling of fan control creates an OEM SEL event"
                    return BMC_CONST.FW_SUCCESS
                else:
                    l_msg = "IPMI: Enabling of fan control doesn't create an OEM SEL event"
                    raise OpTestError(l_msg)
            else:
                l_msg = "IPMI: Fan control thread still in not running state, enable failed"
                raise OpTestError(l_msg)
        else:
            l_msg = "IPMI: Fan control thread still running, disable failed"
            raise OpTestError(l_msg)

    ##
    # @brief  It will check basic channel functionalities: info and authentication capabilities.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_channel(self):
        print "OOB IPMI: Channel Tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHANNEL_AUTHCAP)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHANNEL_INFO)

    ##
    # @brief  It will execute and test the return code of ipmi command.
    #
    # @param i_cmd @type string:The ipmitool command, for example: chassis power on; echo $?
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def run_ipmi_cmd(self, i_cmd):
        l_cmd = i_cmd
        l_res = self.cv_IPMI.ipmitool_execute_command(l_cmd)
        print l_res
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI: command failed %c" % l_cmd
            raise OpTestError(l_msg)
        return l_res

    ##
    # @brief  It will execute and test the ipmi chassis <cmd> commands
    #         cmd: status, poh, restart_cause, policy list and policy set
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassis(self):
        print "OOB IPMI: Chassis tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_STATUS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_POH)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_RESTART_CAUSE)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_POLICY_LIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_POLICY_ALWAYS_OFF)

    ##
    # @brief  It will execute and test the ipmi chassis identify commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassisIdentifytests(self):
        print "OOB IPMI: chassis identify tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY_5)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY_FORCE)
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_IDENTIFY)

    ##
    # @brief  It will execute and test the functionality of ipmi chassis bootdev <dev>
    #         dev: none,pxe,cdrom,disk,bios,safe,diag,floppy and none.
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    @staticmethod
    def test_chassisBootdev(self):
        print "OOB IPMI: chassis bootdevice tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_PXE)
        self.verify_bootdev("pxe")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_CDROM)
        self.verify_bootdev("cdrom")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_DISK)
        self.verify_bootdev("disk")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_BIOS)
        self.verify_bootdev("bios")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_SAFE)
        self.verify_bootdev("safe")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_DIAG)
        self.verify_bootdev("diag")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_FLOPPY)
        self.verify_bootdev("floppy")
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")

    ##
    # @brief  It will verify whether setting of given bootdevice is honoured or not
    #         by reading chassis bootparam get 5
    #
    # @param i_dev @type string: boot device name: Ex safe, disk and cdrom
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    def verify_bootdev(self, i_dev):
        l_res = self.run_ipmi_cmd(BMC_CONST.IPMI_CHASSIS_BOOTPARAM_GET_5)
        if i_dev == "safe":
            l_msg = "Force Boot from default Hard-Drive, request Safe-Mode"
        elif i_dev == "disk":
            l_msg = "Force Boot from default Hard-Drive"
        elif i_dev == "diag":
            l_msg = "Force Boot from Diagnostic Partition"
        elif i_dev == "bios":
            l_msg = "Force Boot into BIOS Setup"
        elif i_dev == "pxe":
            l_msg = "Force PXE"
        elif i_dev == "cdrom":
            l_msg = "Force Boot from CD/DVD"
        elif i_dev == "none":
            l_msg = "No override"
        elif i_dev == "floppy":
            l_msg = "Force Boot from Floppy/primary removable media"
        else:
            print "pass proper bootdevice"

        for l_line in l_res:
            if l_line.__contains__(l_msg):
                print "Verifying bootdev is successfull for %s" % i_dev
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Boot device is not set to %s" % i_dev
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi <sdr/sel/mc/channel> info related commands.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_Info(self):
        print "OOB IPMI: info tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_CHANNEL_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_INFO)

    ##
    # @brief  It will execute and test the ipmi sdr list <all/fru/event/mcloc/compact/full/generic>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_list_by_type(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_ALL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_FRU)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_EVENT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_MCLOC)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_COMPACT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_FULL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_LIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr elist <all/fru/event/mcloc/compact/full/generic>
    #         commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_elist_by_type(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_ALL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_FRU)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_EVENT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_MCLOC)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_COMPACT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_FULL)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_ELIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr type <Temp/fan/Powersupply> commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_type_list(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_LIST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_TEMPERATURE)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_FAN)
        self.run_ipmi_cmd(BMC_CONST.IPMI_SDR_TYPE_POWER_SUPPLY)

    ##
    # @brief  It will execute and test the ipmi sdr get <sensor-id> command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_get_id(self):
        l_cmd = BMC_CONST.IPMI_SDR_GET_WATCHDOG + "; echo $?"
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi fru print command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_print(self):
        print "OOB IPMI: Fru tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_FRU_PRINT)

    ##
    # @brief  It will execute and test the ipmi fru read command.
    #         then the output file is displayed by hexdump
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_read(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_FRU_READ)
        l_res = commands.getstatusoutput("hexdump -C file_fru")
        if int(l_res[0]) == 0:
            print l_res[1]
        else:
            l_msg = "Failing to do hexdump for fru file"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi sensor list functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_list(self):
        print "OOB IPMI: Sensor tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_SENSOR_LIST)

    ##
    # @brief  It will execute and test the ipmi sensor get <id> functionality
    #
    # @param i_sensor @type string:sensor id to retrieve the data
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sensor_byid(self, i_sensor):
        l_cmd = "sensor get \"%s\"; echo $?" % i_sensor
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the management controller(mc) commands functionality
    #         info-Displays information about the BMC hardware, including device revision,
    #              firmware revision, IPMI version supported, manufacturer ID,  and  information
    #               on additional device support
    #         watchdog get-Show current Watchdog Timer settings and countdown state.
    #         watchdog off-Turn off a currently running Watchdog countdown timer.
    #         watchdog reset-Reset the Watchdog Timer to its most recent state and restart the countdown timer.
    #         selftest- Check on the basic health of the BMC by executing the
    #                   Get Self Test results command and report the results.
    #         setenables-Enables  or disables the given option
    #         getenables-Displays a list of the currently enabled options for the BMC.
    #         getsysinfo-Retrieves system info from bmc for given argument
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_mc(self):
        print "OOB IPMI: MC tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_WATCHDOG_GET)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SETENABLES_OEM_0_OFF)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_SETENABLES_OEM_0_ON)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_WATCHDOG_OFF)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_WATCHDOG_RESET)
        self.run_ipmi_cmd(BMC_CONST.IPMI_MC_GETSYS_INFO)

    ##
    # @brief  It will execute and test the ipmi sel info functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_info(self):
        print "OOB IPMI: SEL tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_INFO)

    ##
    # @brief  It will execute and test ipmi sel list functionality.
    #         the entire contents of the System Event Log are displayed.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_LIST)

    ##
    # @brief  It will execute and test the ipmi sel elist functionality
    #         If invoked as elist (extended list) it will also use the
    #         Sensor Data Record entries to display the sensor ID for
    #           the sensor that caused each event.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_elist(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_ELIST)

    ##
    # @brief  It will execute and test the ipmi sel time get functionality
    #         Displays the SEL clock's current time.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_time_get(self):
        l_res = self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_TIME_GET)
        return l_res

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @param i_time @type string: the value to be set as a sel time
    #               <time string> is of the form "MM/DD/YYYY HH:MM:SS"
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_time_set(self, i_time):
        l_cmd = "sel time set \'%s\'; echo $?" % i_time
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list first <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_first_n_entries(self, i_num):
        l_cmd = "sel list first %i; echo $?" % int(i_num)
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list last <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_last_n_entries(self, i_num):
        l_cmd = "sel list last %i; echo $?" % int(i_num)
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @param i_sel_id @type string: for example 0x05, 0x06..
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_get_byid(self, i_sel_id):
        l_cmd = "sel get %s; echo $?" % i_sel_id
        self.run_ipmi_cmd(l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel clear functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_clear(self):
        self.run_ipmi_cmd(BMC_CONST.IPMI_SEL_CLEAR)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_sel_get_functionality(self):
        l_res = self.cv_IPMI.ipmitool_execute_command("sel list first 3 | awk '{print $1}'; echo $?")
        l_list = l_res.splitlines()
        if int(l_list[-1]) == 0:
            if l_res.__contains__("SEL has no entries"):
                print "There are No sel entries to fetch"
                pass
            else:
                del l_list[-1]
                for l in l_list:
                    l_id = "0x" + l
                    self.test_sel_get_byid(l_id)
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Not able to get sel entries"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi sel clear functionality
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    @staticmethod
    def test_sel_clear_functionality(self):
        self.test_sel_clear(self)
        l_res = self.cv_HOST.host_run_command("ipmitool sel list; echo $?")
        l_list = l_res.splitlines()
        for l_line in l_list:
            if l_line.__contains__("SEL has no entries"):
                print "Sel clear function got cleared event entries"
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "OOB IPMI: sel clear function failing in clearing entries"
            print l_msg
            print l_res
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the dcmi related ipmi commands.
    #         discover-This command is used to discover supported capabilities in DCMI
    #         Power reading-Get power related readings from the system.
    #               get_limit-Get the configured power limits.
    #         sensors-Prints the available DCMI sensors.
    #         get_mc_id_string-Get management controller identifier string
    #         get_temp_reading-Get Temperature Sensor Readings.
    #         get_conf_param-Get DCMI Configuration Parameters.
    #         oob_discover-Ping/Pong Message for DCMI Discovery
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_dcmi(self):
        print "OOB IPMI: dcmi tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)
        self.run_ipmi_cmd(BMC_CONST.IPMI_DCMI_OOB_DISCOVER)

    ##
    # @brief  It will execute and test the functionality of ipmi echo command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_echo(self):
        print "OOB IPMI: echo tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_ECHO_DONE)

    ##
    # @brief  It will execute and test event related commands to test sel functionality.
    #         Send a pre-defined test event to the System Event Log.  The following
    #         events are included as a means to test the functionality of  the  System
    #         Event Log component of the BMC (an entry will be added each time the
    #         event N command is executed)
    #         Currently supported values for N are:
    #         1    Temperature: Upper Critical: Going High
    #         2    Voltage Threshold: Lower Critical: Going Low
    #         3    Memory: Correctable ECC
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_event(self):
        print "OOB IPMI: event tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_EVENT_1)
        self.run_ipmi_cmd(BMC_CONST.IPMI_EVENT_2)
        self.run_ipmi_cmd(BMC_CONST.IPMI_EVENT_3)

    ##
    # @brief  It will execute and test ipmi exec command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_exec(self):
        print "OOB IPMI: exec tests"
        pass
        # TODO: need to execute ipmi commands from a file

    ##
    # @brief  It will execute and test firmware firewall info command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_firewall(self):
        print "OOB IPMI: Firewall test"
        self.run_ipmi_cmd(BMC_CONST.IPMI_FIREWALL_INFO)

    ##
    # @brief  It will execute and test pef related commands:
    #         info:This command will query the BMC and print information about the PEF supported features.
    #         status: This command prints the current PEF status
    #         policy: This command lists the PEF policy table entries
    #         list: This  command  lists  the PEF table entries.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_pef(self):
        print "OOB IPMI: Pef tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_INFO)
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_STATUS)
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_POLICY)
        self.run_ipmi_cmd(BMC_CONST.IPMI_PEF_LIST)

    ##
    # @brief This will test raw IPMI commands. For example to query the POH counter with a raw command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_raw(self):
        print "OOB IPMI: raw command execution tests"
        self.run_ipmi_cmd(BMC_CONST.IPMI_RAW_POH)

    ##
    # @brief  It will execute and test the ipmi sensor get "Host Status" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_host_status(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_HOST_STATUS)

    ##
    # @brief  It will execute and test the ipmi sensor get "OS Boot" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_os_boot(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OS_BOOT)

    ##
    # @brief  It will execute and test the ipmi sensor get "OCC Active" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_occ_active(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OCC_ACTIVE)

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_set_sel_time(self):
        l_res = self.test_sel_time_get(self)
        self.test_sel_time_set(l_res[0])

    ##
    # @brief  It will execute and test the ipmi sel list first <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_first_3_entries(self):
        self.test_sel_list_first_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)

    ##
    # @brief  It will execute and test the ipmi sel list last <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_last_3_entries(self):
        self.test_sel_list_last_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)
Exemplo n.º 32
0
class OpTestIPMIPowerControl():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will test below system power control operations
    #        IPMI Power ON
    #             Power OFF
    #             Power Soft
    #             Power Cycle
    #             Power Reset
    #        So each operation is executed through ipmi commands. and
    #        check_system_status function will check whether FW and Host OS
    #        Boot completed or not.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testIPMIPowerControl(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        print "Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.check_system_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)

        print "Performing a IPMI Soft Power OFF Operation"
        # Perform a IPMI Soft Power OFF Operation(Graceful shutdown)
        self.cv_IPMI.ipmi_power_soft()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        print "Perform a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.check_system_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)

        print "Performing a IPMI Power Cycle(Soft reboot) Operation "
        # Perform a IPMI Power Cycle(Soft reboot) Operation only when system is in ON state
        self.cv_IPMI.ipmi_power_cycle()
        self.check_system_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)

        print "Performing a IPMI Power Hard Reset Operation"
        # Perform a IPMI Power Hard Reset Operation
        self.cv_IPMI.ipmi_power_reset()
        self.check_system_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)

        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will check for system status and wait for
    #        FW and Host OS Boot progress to complete.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def check_system_status(self):
        if int(self.cv_SYSTEM.sys_ipl_wait_for_working_state()) == 0:
            print "System booted to working state"
        else:
            l_msg = "System failed to boot"
            raise OpTestError(l_msg)
        if int(self.cv_SYSTEM.sys_wait_for_os_boot_complete()) == 0:
            print "System booted to Host OS"
        else:
            l_msg = "System failed to boot Host OS"
            raise OpTestError(l_msg)

        return BMC_CONST.FW_SUCCESS
Exemplo n.º 33
0
class OpTestOCC():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function is used to test OCC Reset funtionality in BMC based systems.
    #        OCC Reset reload is limited to 3 times per full power cycle.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_occ_reset_functionality(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            #raise OpTestError(l_msg)
        print "OPAL-PRD: OCC Enable"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
        print "OPAL-PRD: OCC DISABLE"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
        print "OPAL-PRD: OCC RESET"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
        time.sleep(60)
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            #raise OpTestError(l_msg)
        print "OPAL-PRD: OCC Enable"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
        print "OPAL-PRD: OCC DISABLE"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
        print "OPAL-PRD: OCC RESET"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
        time.sleep(60)
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            #raise OpTestError(l_msg)
        print "OPAL-PRD: OCC Enable"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
        print "OPAL-PRD: OCC DISABLE"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
        print "OPAL-PRD: OCC RESET"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
        time.sleep(60)
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state, rebooting the system"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)

    ##
    # @brief This function is used to test OCC Reset funtionality in BMC based systems.
    #        OCC Reset reload can be done more than 3 times per full power cycle, by
    #        resetting OCC resetreload count.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_occ_reset_n_times(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state after rebooting"
            raise OpTestError(l_msg)

        for i in range(1, BMC_CONST.OCC_RESET_RELOAD_COUNT):
            print "*******************OCC Reset count %d*******************" % i
            print "OPAL-PRD: OCC Enable"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
            print "OPAL-PRD: OCC DISABLE"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
            print "OPAL-PRD: OCC RESET"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
            time.sleep(60)
            if self.check_occ_status() == BMC_CONST.FW_FAILED:
                l_msg = "OCC's are not in active state"
                raise OpTestError(l_msg)
            print "OPAL-PRD: occ query reset reload count"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_QUERY_RESET_COUNTS)
            print "OPAL-PRD: occ reset reset/reload count"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_SET_RESET_RELOAD_COUNT)
            print "OPAL-PRD: occ query reset reload count"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_QUERY_RESET_COUNTS)

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state after rebooting"
            raise OpTestError(l_msg)

    ##
    # @brief This function is used to test OCC Enable and Disable funtionality in BMC based systems.
    #        There is no limit for occ enable and disable, as of now doing 10 times in a loop.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_occ_enable_disable_functionality(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        for count in range(1, 10):
            print "OPAL-PRD: OCC Enable"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
            print "OPAL-PRD: OCC Disable"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
            time.sleep(60)
            if self.check_occ_status() == BMC_CONST.FW_FAILED:
                l_msg = "OCC's are not in active state"
                #raise OpTestError(l_msg)
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)

    ##
    # @brief This function is used to get OCC status enable/disable.
    #
    # @return BMC_CONST.FW_SUCCESS - OCC's are active or
    #         BMC_CONST.FW_FAILED  - OCC's are not in active state
    #
    def check_occ_status(self):
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
            return BMC_CONST.FW_SUCCESS
        else:
            print "OCC's are not in active state"
            return BMC_CONST.FW_FAILED
class OpTestIPMILockMode():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_lparIP The IP address of the LPAR
    # @param i_lparuser The userid to log into the LPAR
    # @param i_lparPasswd The password of the userid to log into the LPAR with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_lparip=None,
                 i_lparuser=None, i_lparPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_lparip, i_lparuser, i_lparPasswd)
        self.cv_LPAR = OpTestLpar(i_lparip, i_lparuser, i_lparPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_lparip,
                 i_lparuser, i_lparPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS level installed on power platform
    #        2. It will check for kernel version installed on the Open Power Machine
    #        3. It will check for ipmitool command existence and ipmitool package
    #        4. Load the necessary ipmi modules based on config values
    #        5. Issue a ipmi lock command through out-of-band authenticated interface
    #        6. Now BMC IPMI is in locked mode, at this point only white listed
    #           in-band ipmi commands sholud work(No other in-band ipmi command should work)
    #        7. Execute and test the functionality of whitelisted in-band ipmi
    #           commands in locked mode
    #        8. At the end of test issue a ipmi unlock command to revert the availablity of all
    #           in-band ipmi commands in unlocked mode.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_ipmi_lock_mode(self):
        # Get OS level
        l_oslevel = self.cv_LPAR.lpar_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_LPAR.lpar_get_kernel_version()

        # Checking for ipmitool command and lm_sensors package
        self.cv_LPAR.lpar_check_command("ipmitool")

        l_pkg = self.cv_LPAR.lpar_check_pkg_for_utility(l_oslevel, "ipmitool")
        print "Installed package: %s" % l_pkg

        # loading below ipmi modules based on config option
        # ipmi_devintf, ipmi_powernv and ipmi_masghandler
        self.cv_LPAR.lpar_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_DEVICE_INTERFACE,
                                                      BMC_CONST.IPMI_DEV_INTF)
        self.cv_LPAR.lpar_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_POWERNV,
                                                      BMC_CONST.IPMI_POWERNV)
        self.cv_LPAR.lpar_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_HANDLER,
                                                      BMC_CONST.IPMI_MSG_HANDLER)

        # Issue a ipmi lock command through authenticated interface
        print "Issuing ipmi lock command through authenticated interface"
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_LOCK_CMD)
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI:Lock command failed, There may be two reasons here.\n\
                a. check the corresponding parches available in AMI driver code,\n\
                b. if patches available then command is failing"
            print l_msg
            raise OpTestError(l_msg)
        print "IPMI:Lock command executed successfully"

        try:
            self.run_inband_ipmi_whitelisted_cmds()
        except:
            l_msg = "One of white listed in-band ipmi command execution failed"
            print sys.exc_info()
        finally:
            # Issue a ipmi unlock command at the end of test.
            print "Issuing ipmi unlock command through authenticated interface"
            self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_UNLOCK_CMD)

    ##
    # @brief This function will execute whitelisted in-band ipmi commands
    #        and test the functionality in locked mode.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def run_inband_ipmi_whitelisted_cmds(self):
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_lpar_login(l_con)
        self.cv_IPMI.ipmi_lpar_set_unique_prompt(l_con)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console("uname -a")

        # Test IPMI white listed commands those should be allowed through un-authenticated
        # in-band interface
        # 1.[App] Get Device ID
        print "Testing Get Device ID command"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_DEVICE_ID)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Device ID command failed"
            raise OpTestError(l_msg)

        # 2.[App] Get Device GUID
        print "Testing Get Device GUID"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_DEVICE_GUID)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Device GUID command failed"
            raise OpTestError(l_msg)

        # 3.[App] Get System GUID
        print "Testing Get system GUID"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SYSTEM_GUID)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System GUID command failed"
            raise OpTestError(l_msg)

        # 4.[Storage] Get SEL info
        print "Testing Get SEL info"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SEL_INFO)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get SEL info command failed"
            raise OpTestError(l_msg)

        # 5.[Storage] Get SEL time
        print "Testing Get SEL time"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SEL_TIME_RAW)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get SEL time command failed"
            raise OpTestError(l_msg)

        # 6. [Storage] Reserve SEL
        print "Testing Reserve SEL"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_RESERVE_SEL)
        if l_res[-1] != "0":
            l_msg = "IPMI: Reserve SEL command failed"
            raise OpTestError(l_msg)

        # 7. [Storage] Set SEL time (required for RTC)
        print "Testing Set SEL time"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SEL_TIME)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_SET_SEL_TIME + " \'" + l_res[-1] + "\'; echo $?")
        if l_res[-1] != "0":
            l_msg = "IPMI: Set SEL time command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SEL_TIME)

        # 8. [Transport] Get LAN parameters
        print "Testing Get LAN parameters"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_LAN_PARAMETERS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get LAN parameters command failed"
            raise OpTestError(l_msg)

        # 9.[Chassis] Get System Boot Options
        print "Testing Get System Boot Options"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SYSTEM_BOOT_OPTIONS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System Boot Options command failed"
            raise OpTestError(l_msg)

        # 10.[Chassis] Set System Boot Options
        print "Testing Set System Boot Options"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_SET_SYTEM_BOOT_OPTIONS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set System Boot Options command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SYSTEM_BOOT_OPTIONS)

        # 11. [App] Get BMC Global Enables
        print "Testing Get BMC Global Enables"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_BMC_GLOBAL_ENABLES_RAW)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get BMC Global Enables command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_BMC_GLOBAL_ENABLES)

        # 12. [App] Set BMC Global Enables
        print "Testing Set BMC Global Enables"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_SET_BMC_GLOBAL_ENABLES_SEL_OFF)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set BMC Global Enables sel=off command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_BMC_GLOBAL_ENABLES)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_SET_BMC_GLOBAL_ENABLES_SEL_ON)

        # 13.[App] Get System Interface Capabilities
        print "Testing Get System Interface Capabilities"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SYSTEM_INTERFACE_CAPABILITIES_SSIF)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System Interface Capabilities SSIF command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SYSTEM_INTERFACE_CAPABILITIES_KCS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get System Interface Capabilities KCS command failed"
            raise OpTestError(l_msg)

        # 14.[App] Get Message Flags
        print "Testing Get Message Flags"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_MESSAGE_FLAGS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Message Flags command failed"
            raise OpTestError(l_msg)

        # 15. [App] Get BT Capabilities
        print "Testing Get BT Capabilities"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_BT_CAPABILITIES)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get BT Capabilities command failed"
            raise OpTestError(l_msg)

        # 16. [App] Clear Message Flags
        print "Testing Clear Message Flags"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_CLEAR_MESSAGE_FLAGS)
        if l_res[-1] != "0":
            l_msg = "IPMI: Clear Message Flags command failed"
            raise OpTestError(l_msg)

        # 17. [OEM] PNOR Access Status
        print "Testing the PNOR Access Status"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PNOR_ACCESS_STATUS_DENY)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Status:deny command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PNOR_ACCESS_STATUS_GRANT)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Status:grant command failed"
            raise OpTestError(l_msg)

        # 18. [Storage] Add SEL Entry
        print "Testing Add SEL Entry"
        print "Clearing the SEL list"
        self.cv_IPMI.ipmi_sdr_clear()
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_ADD_SEL_ENTRY)
        if l_res[-1] != "0":
            l_msg = "IPMI: Add SEL Entry command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_LIST_LAST_SEL_EVENT)
        print "Checking for Reserved entry creation in SEL"
        if "Reserved" not in l_res:
            l_msg = "IPMI: Add SEL Entry command, doesn't create an SEL event"
            raise OpTestError(l_msg)

        # 19. [App] Set Power State
        print "Testing Set Power State"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_SET_ACPI_POWER_STATE)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set Power State command failed"
            raise OpTestError(l_msg)

        # 20. [App] Set watchdog
        print "Testing Set watchdog"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_SET_WATCHDOG)
        if l_res[-1] != "0":
            l_msg = "IPMI: Set watchdog command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_MC_WATCHDOG_GET)

        # 21. [Sensor/Event] Get Sensor Type
        print "Testing Get Sensor Type"
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_SDR_GET_WATCHDOG)
        matchObj = re.search( "Watchdog \((0x\d{1,})\)", l_res)
        if matchObj:
            print "Got sensor Id for watchdog: %s" % matchObj.group(1)
        else:
            l_msg = "Failed to get sensor id for watchdog sensor"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SENSOR_TYPE_FOR_WATCHDOG + " " + matchObj.group(1) + " ;echo $?")
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Sensor Type command failed"
            raise OpTestError(l_msg)

        # 22.[Sensor/Event] Get Sensor Reading
        print "Testing Get Sensor Reading"
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_SDR_GET_WATCHDOG)
        matchObj = re.search( "Watchdog \((0x\d{1,})\)", l_res)
        if matchObj:
            print "Got sensor Id for watchdog: %s" % matchObj.group(1)
        else:
            l_msg = "Failed to get sensor id for watchdog sensor"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_SENSOR_READING + " " + matchObj.group(1) + " ;echo $?")
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Sensor Reading command failed"
            raise OpTestError(l_msg)

        # 23.[Sensor/Event] Platform Event (0x02)
        print "Testing Platform Event"
        self.cv_IPMI.ipmi_sdr_clear()
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PLATFORM_EVENT)
        if l_res[-1] != "0":
            l_msg = "IPMI: Platform Event command failed"
            raise OpTestError(l_msg)
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_LIST_LAST_SEL_EVENT)
        if "Reserved" not in l_res:
            l_msg = "IPMI: Platform Event command failed to log SEL event"
            raise OpTestError(l_msg)

        # 24. [OEM] PNOR Access Response (0x08)
        print "Testing PNOR Access Response"
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PNOR_ACCESS_STATUS_GRANT)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PNOR_ACCESS_RESPONSE)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Response command failed"
            raise OpTestError(l_msg)
        self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PNOR_ACCESS_STATUS_DENY)
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_PNOR_ACCESS_RESPONSE)
        if l_res[-1] != "0":
            l_msg = "IPMI: PNOR Access Response command failed"
            raise OpTestError(l_msg)

        # 25.[Chassis] Chassis Control
        print "Testing chassis power on"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_CHASSIS_POWER_ON)
        if l_res[-1] != "0":
            l_msg = "IPMI: chassis power on command failed"
            raise OpTestError(l_msg)

        # 26.[App] 0x38 Get Channel Authentication Cap
        print "Testing Get Channel Authentication Capabilities"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_CHANNEL_AUTH_CAP)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get Channel Authentication Capabilities command failed"
            raise OpTestError(l_msg)

        # 27.[App] Reset Watchdog (0x22)
        print "Testing reset watchdog"
        self.cv_IPMI.ipmi_sdr_clear()
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_RESET_WATCHDOG)
        if l_res[-1] != "0":
            l_msg = "IPMI: Reset Watchdog command failed"
            raise OpTestError(l_msg)

        time.sleep(10)
        # Reset watchdog should create a SEL event log
        l_res = self.cv_IPMI.ipmitool_execute_command(BMC_CONST.IPMI_LIST_LAST_SEL_EVENT)
        if "Watchdog" not in l_res:
            l_msg = "IPMI: Reset Watchdog command, doesn't create an SEL event"
            raise OpTestError(l_msg)

        # 28. [App] Get ACPI Power State (0x06)
        print "Testing Get ACPI Power State"
        l_res = self.cv_IPMI.run_lpar_cmd_on_ipmi_console(BMC_CONST.LPAR_GET_ACPI_POWER_STATE)
        if l_res[-1] != "0":
            l_msg = "IPMI: Get ACPI Power State command failed"
            raise OpTestError(l_msg)
Exemplo n.º 35
0
class OpTestHMIHandling():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the Host
    # @param i_hostuser The userid to log into the Host
    # @param i_hostPasswd The password of the userid to log into the Host with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP, i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This is a common function for all the hmi test cases. This will be executed before
    #        any test case starts. Basically this provides below requirements.
    #        1. Validates all required host commands
    #        2. It will clone skiboot source repository
    #        3. Compile the necessary tools xscom-utils and gard utility to test HMI.
    #        4. Get the list Of Chips and cores in the form of dictionary.
    #           Ex: [['00000000', ['4', '5', '6', 'c', 'd', 'e']], ['00000001', ['4', '5', '6', 'c', 'd', 'e']], ['00000010', ['4', '5', '6', 'c', 'd', 'e']]]
    #        5. In-order to inject HMI errors on cpu's, cpu should be running,
    #           so disabling the sleep states 1 and 2 of all CPU's.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_init(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()

        # Get OS level
        self.l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Check whether git and gcc commands are available on the host
        self.cv_HOST.host_check_command("git")
        self.cv_HOST.host_check_command("gcc")

        # It will clone skiboot source repository
        l_dir = "/tmp/skiboot"
        self.cv_HOST.host_clone_skiboot_source(l_dir)
        # Compile the necessary tools xscom-utils and gard utility
        self.cv_HOST.host_compile_xscom_utilities(l_dir)
        self.cv_HOST.host_compile_gard_utility(l_dir)

        # Getting list of processor chip Id's(executing getscom -l to get chip id's)
        l_res = self.cv_HOST.host_run_command("cd %s/external/xscom-utils/; ./getscom -l" % l_dir)
        l_res = l_res.splitlines()
        l_chips = []
        for line in l_res:
            matchObj = re.search("(\d{8}).*processor", line)
            if matchObj:
                l_chips.append(matchObj.group(1))
        if not l_chips:
            l_msg = "Getscom failed to list processor chip id's"
            raise OpTestError(l_msg)
        l_chips.sort()
        print l_chips # ['00000000', '00000001', '00000010']

        # Currently getting the list of active core id's with respect to each chip is by using opal msg log
        # TODO: Need to identify best way to get list of cores(If Opal msg log is empty)
        l_cmd = "cat /sys/firmware/opal/msglog | grep -i CHIP"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_cores = {}
        self.l_dic = []
        l_res = l_res.splitlines()
        for line in l_res:
            matchObj = re.search("Chip (\d{1,2}) Core ([a-z0-9])", line)
            if matchObj:
                if l_cores.has_key(int(matchObj.group(1))):
                    (l_cores[int(matchObj.group(1))]).append(matchObj.group(2))
                else:
                    l_cores[int(matchObj.group(1))] = list(matchObj.group(2))
        if not l_cores:
            l_msg = "Failed in getting core id's information from OPAL msg log"
            raise OpTestError(l_msg)

        print l_cores # {0: ['4', '5', '6', 'c', 'd', 'e'], 1: ['4', '5', '6', 'c', 'd', 'e'], 10: ['4', '5', '6', 'c', 'd', 'e']}
        l_cores = sorted(l_cores.iteritems())
        print l_cores
        i=0
        for tup in l_cores:
            new_list = [l_chips[i], tup[1]]
            self.l_dic.append(new_list)
            i+=1
        print self.l_dic
        # self.l_dic is a list of chip id's, core id's . and is of below format 
        # [['00000000', ['4', '5', '6', 'c', 'd', 'e']], ['00000001', ['4', '5', '6', 'c', 'd', 'e']], ['00000010', ['4', '5', '6', 'c', 'd', 'e']]]

        self.l_dir = l_dir
        # In-order to inject HMI errors on cpu's, cpu should be running, so disabling the sleep states 1 and 2 of all CPU's
        self.cv_HOST.host_run_command(BMC_CONST.GET_CPU_SLEEP_STATE2)
        self.cv_HOST.host_run_command(BMC_CONST.GET_CPU_SLEEP_STATE1)
        self.cv_HOST.host_run_command(BMC_CONST.GET_CPU_SLEEP_STATE0)
        self.cv_HOST.host_run_command(BMC_CONST.DISABLE_CPU_SLEEP_STATE1)
        self.cv_HOST.host_run_command(BMC_CONST.DISABLE_CPU_SLEEP_STATE2)
        self.cv_HOST.host_run_command(BMC_CONST.GET_CPU_SLEEP_STATE2)
        self.cv_HOST.host_run_command(BMC_CONST.GET_CPU_SLEEP_STATE1)
        self.cv_HOST.host_run_command(BMC_CONST.GET_CPU_SLEEP_STATE0)

        if "Ubuntu" in self.l_oslevel:
            self.cv_HOST.host_run_command("service kdump-tools stop")
            self.cv_HOST.host_run_command("service kdump-tools status")
        else:
            self.cv_HOST.host_run_command("service kdump stop")
            self.cv_HOST.host_run_command("service kdump status")

    ##
    # @brief This function is mainly used to clear hardware gard entries.
    #        It will perform below steps
    #           1. Reboot the system(Power off/on)
    #           2. Clear any Hardware gard entries
    #           3. Again reboot the system, to make use of garded Hardware.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def clearGardEntries(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Power off and on the system.
        self.cv_IPMI.ipmi_power_off()
        self.cv_IPMI.ipmi_power_on()
        if int(self.cv_SYSTEM.sys_ipl_wait_for_working_state()):
            l_msg = "System failed to boot host OS"
            raise OpTestError(l_msg)
        time.sleep(BMC_CONST.HOST_BRINGUP_TIME)

        # Clearing gard entries after host comes up
        self.cv_HOST.host_get_OS_Level()
        # It will clone skiboot source repository
        l_dir = "/tmp/skiboot"
        self.cv_HOST.host_clone_skiboot_source(l_dir)
        # Compile the necessary tools xscom-utils and gard utility
        self.cv_HOST.host_compile_xscom_utilities(l_dir)
        self.cv_HOST.host_compile_gard_utility(l_dir)

        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_host_login(l_con)
        self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        l_dir = "/tmp/skiboot"
        self.cv_IPMI.run_host_cmd_on_ipmi_console("cd %s/external/gard/;" % l_dir)
        l_cmd = "./gard list; echo $?"
        self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        l_cmd = "./gard clear all; echo $?"
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        if int(l_res[-1]):
            l_msg = "Clearing gard entries through gard tool is failed"
            raise OpTestError(l_msg)
        l_cmd = "./gard list; echo $?"
        self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)

        # Rebooting the system again to make use of garded hardware
        self.cv_IPMI.ipmi_power_off()
        self.cv_IPMI.ipmi_power_on()
        if int(self.cv_SYSTEM.sys_ipl_wait_for_working_state()):
            l_msg = "System failed to boot host OS"
            raise OpTestError(l_msg)
        time.sleep(BMC_CONST.HOST_BRINGUP_TIME)
        self.cv_HOST.host_get_OS_Level()
        self.cv_SYSTEM.sys_ipmi_close_console(l_con)

    ##
    # @brief This function executes HMI test case based on the i_test value, Before test starts
    #        disabling kdump service to make sure system reboots, after injecting non-recoverable errors.
    #
    # @param i_test @type int: this is the type of test case want to execute
    #                          BMC_CONST.HMI_PROC_RECV_DONE: Processor recovery done
    #                          BMC_CONST.HMI_PROC_RECV_ERROR_MASKED: proc_recv_error_masked
    #                          BMC_CONST.HMI_MALFUNCTION_ALERT: malfunction_alert
    #                          BMC_CONST.HMI_HYPERVISOR_RESOURCE_ERROR: hypervisor resource error
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testHMIHandling(self, i_test):
        l_test = i_test
        self.test_init()
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_host_login(l_con)
        self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        self.cv_IPMI.run_host_cmd_on_ipmi_console("cat /etc/os-release")
        self.cv_IPMI.run_host_cmd_on_ipmi_console("cd %s/external/xscom-utils/;" % self.l_dir)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("lscpu")
        self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg -D")
        if l_test == BMC_CONST.HMI_PROC_RECV_DONE:
            self.test_proc_recv_done()
        elif l_test == BMC_CONST.HMI_PROC_RECV_ERROR_MASKED:
            self.test_proc_recv_error_masked()
        elif l_test == BMC_CONST.HMI_MALFUNCTION_ALERT:
            self.test_malfunction_allert()
        elif l_test == BMC_CONST.HMI_HYPERVISOR_RESOURCE_ERROR:
            self.test_hyp_resource_err()
        elif l_test == BMC_CONST.TOD_ERRORS:
            # TOD Error recovery works on systems having more than one chip TOD
            # Skip this test on single chip systems(as recovery fails on 1S systems)
            if len(self.l_dic) == 1:
                l_msg = "This is a single chip system, TOD Error recovery won't work"
                print l_msg
                return BMC_CONST.FW_SUCCESS
            elif len(self.l_dic) > 1:
                self.test_tod_errors(BMC_CONST.PSS_HAMMING_DISTANCE)
                self.test_tod_errors(BMC_CONST.INTERNAL_PATH_OR_PARITY_ERROR)
                self.test_tod_errors(BMC_CONST.TOD_DATA_PARITY_ERROR)
                self.test_tod_errors(BMC_CONST.TOD_SYNC_CHECK_ERROR)
                self.test_tod_errors(BMC_CONST.FSM_STATE_PARITY_ERROR)
                self.test_tod_errors(BMC_CONST.MASTER_PATH_CONTROL_REGISTER)
                self.test_tod_errors(BMC_CONST.PORT_0_PRIMARY_CONFIGURATION_REGISTER)
                self.test_tod_errors(BMC_CONST.PORT_1_PRIMARY_CONFIGURATION_REGISTER)
                self.test_tod_errors(BMC_CONST.PORT_0_SECONDARY_CONFIGURATION_REGISTER)
                self.test_tod_errors(BMC_CONST.PORT_1_SECONDARY_CONFIGURATION_REGISTER)
                self.test_tod_errors(BMC_CONST.SLAVE_PATH_CONTROL_REGISTER)
                self.test_tod_errors(BMC_CONST.INTERNAL_PATH_CONTROL_REGISTER)
                self.test_tod_errors(BMC_CONST.PR_SC_MS_SL_CONTROL_REGISTER)
            else:
                l_msg = "Getting Chip information failed"
                raise OpTestError(l_msg)
        elif l_test == BMC_CONST.TFMR_ERRORS:
            self.testTFMR_Errors(BMC_CONST.TB_PARITY_ERROR)
            self.testTFMR_Errors(BMC_CONST.TFMR_PARITY_ERROR)
            self.testTFMR_Errors(BMC_CONST.TFMR_HDEC_PARITY_ERROR)
            self.testTFMR_Errors(BMC_CONST.TFMR_DEC_PARITY_ERROR)
            self.testTFMR_Errors(BMC_CONST.TFMR_PURR_PARITY_ERROR)
            self.testTFMR_Errors(BMC_CONST.TFMR_SPURR_PARITY_ERROR)
        else:
            l_msg = "Please provide valid test case"
            raise OpTestError(l_msg)
        self.cv_SYSTEM.sys_ipmi_close_console(l_con)
        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test HMI: processor recovery done
    #        and also this function injecting error on all the cpus one by one and 
    #        verify whether cpu is recovered or not.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_proc_recv_done(self):
        for l_pair in self.l_dic:
            l_chip = l_pair[0]
            for l_core in l_pair[1]:
                l_reg = "1%s013100" % l_core
                l_cmd = "./putscom -c %s %s 0000000000100000; echo $?" % (l_chip, l_reg)

                self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg -C")
                time.sleep(10)
                l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
                time.sleep(10)
                if l_res[-1] == "0":
                    print "Injected thread hang recoverable error"
                elif l_res[-1] == "1":
                    # putscom returns -5 when it is trying to read from write only access register,
                    # In these cases we should not exit and we will contiue with other error injetions
                    continue
                else:
                    if any("Kernel panic - not syncing" in line for line in l_res):
                        l_msg = "Processor recovery failed: Kernel got panic"
                    elif any("Petitboot" in line for line in l_res):
                        l_msg = "System reached petitboot:Processor recovery failed"
                    elif any("ISTEP" in line for line in l_res):
                        l_msg = "System started booting: Processor recovery failed"
                    else:
                        l_msg = "Failed to inject thread hang recoverable error"
                    print l_msg
                    raise OpTestError(l_msg)

                l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg")
                if any("Processor Recovery done" in line for line in l_res) and \
                any("Harmless Hypervisor Maintenance interrupt [Recovered]" in line for line in l_res):
                    print "Processor recovery done"
                else:
                    l_msg = "HMI handling failed to log message: for proc_recv_done"
                    raise OpTestError(l_msg)
                time.sleep(BMC_CONST.HMI_TEST_CASE_SLEEP_TIME)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test HMI: proc_recv_error_masked
    #        Processor went through recovery for an error which is actually masked for reporting
    #        this function also injecting the error on all the cpu's one-by-one.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_proc_recv_error_masked(self):
        for l_pair in self.l_dic:
            l_chip = l_pair[0]
            for l_core in l_pair[1]:
                l_reg = "1%s013100" % l_core
                l_cmd = "./putscom -c %s %s 0000000000080000; echo $?" % (l_chip, l_reg)
                self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg -C")
                time.sleep(10)
                l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
                time.sleep(10)
                if l_res[-1] == "0":
                    print "Injected thread hang recoverable error"
                elif l_res[-1] == "1":
                    continue
                else:
                    if any("Kernel panic - not syncing" in line for line in l_res):
                        l_msg = "Processor recovery failed: Kernel got panic"
                    elif any("Petitboot" in line for line in l_res):
                        l_msg = "System reached petitboot:Processor recovery failed"
                    elif any("ISTEP" in line for line in l_res):
                        l_msg = "System started booting: Processor recovery failed"
                    else:
                        l_msg = "Failed to inject thread hang recoverable error"
                    print l_msg
                    raise OpTestError(l_msg)

                l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg")
                if any("Processor Recovery done" in line for line in l_res) and \
                any("Harmless Hypervisor Maintenance interrupt [Recovered]" in line for line in l_res):
                    print "Processor recovery done"
                else:
                    l_msg = "HMI handling failed to log message"
                    raise OpTestError(l_msg)
                time.sleep(BMC_CONST.HMI_TEST_CASE_SLEEP_TIME)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test hmi malfunction alert:Core checkstop
    #        A processor core in the system has to be checkstopped (failed recovery).
    #        Injecting core checkstop on random core of random chip
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_malfunction_allert(self):
        # Get random pair of chip vs cores
        l_pair = random.choice(self.l_dic)
        # Get random chip id
        l_chip = l_pair[0]
        # Get random core number
        l_core = random.choice(l_pair[1])

        l_reg = "1%s013100" % l_core
        l_cmd = "./putscom -c %s %s 1000000000000000" % (l_chip, l_reg)

        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        if any("Kernel panic - not syncing" in line for line in l_res):
            print "Malfunction alert: kernel got panic"
        elif any("login:"******"System booted to host OS without any kernel panic message"
        elif any("Petitboot" in line for line in l_res):
            print "System reached petitboot without any kernel panic message"
        elif any("ISTEP" in line for line in l_res):
            print "System started booting without any kernel panic message"
        else:
            l_msg = "HMI: Malfunction alert failed"
            raise OpTestError(l_msg)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function is used to test HMI: Hypervisor resource error
    #        Injecting Hypervisor resource error on random core of random chip
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_hyp_resource_err(self):
        # Get random pair of chip vs cores
        l_pair = random.choice(self.l_dic)
        # Get random chip id
        l_chip = l_pair[0]
        # Get random core number
        l_core = random.choice(l_pair[1])

        l_reg = "1%s013100" % l_core
        l_cmd = "./putscom -c %s %s 0000000000008000" % (l_chip, l_reg)

        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        if any("Kernel panic - not syncing" in line for line in l_res) and \
        any("Hypervisor Resource error - core check stop" in line for line in l_res):
            print "Hypervisor resource error: kernel got panic"
        elif any("login:"******"System booted to host OS without any kernel panic message"
        elif any("Petitboot" in line for line in l_res):
            print "System reached petitboot without any kernel panic message"
        elif any("ISTEP" in line for line in l_res):
            print "System started booting without any kernel panic message"
        else:
            l_msg = "HMI: Hypervisor resource error failed"
            raise OpTestError(l_msg)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function tests timer facility related error injections and check
    #        the corresponding error got recovered. And this process is repeated
    #        for all the active cores in all the chips.
    #
    # @param i_error @type string: this is the type of error want to inject
    #                          BMC_CONST.TB_PARITY_ERROR
    #                          BMC_CONST.TFMR_PARITY_ERROR
    #                          BMC_CONST.TFMR_HDEC_PARITY_ERROR
    #                          BMC_CONST.TFMR_DEC_PARITY_ERROR
    #                          BMC_CONST.TFMR_PURR_PARITY_ERROR
    #                          BMC_CONST.TFMR_SPURR_PARITY_ERROR
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testTFMR_Errors(self, i_error):
        l_error = i_error
        for l_pair in self.l_dic:
            l_chip = l_pair[0]
            for l_core in l_pair[1]:
                l_reg = "1%s013281" % l_core
                l_cmd = "./putscom -c %s %s %s;echo $?" % (l_chip, l_reg, l_error)
                self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg -C")
                l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
                time.sleep(10)
                if l_res[-1] == "0":
                    print "Injected TFMR error %s" % l_error
                elif l_res[-1] == "1":
                    continue
                else:
                    if any("Kernel panic - not syncing" in line for line in l_res):
                        l_msg = "TFMR error injection: Kernel got panic"
                    elif any("Petitboot" in line for line in l_res):
                        l_msg = "System reached petitboot:TFMR error injection recovery failed"
                    elif any("ISTEP" in line for line in l_res):
                        l_msg = "System started booting: TFMR error injection recovery failed"
                    else:
                        l_msg = "Failed to inject TFMR error %s " % l_error
                        print l_msg
                        raise OpTestError(l_msg)

                l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg")
                if any("Timer facility experienced an error" in line for line in l_res) and \
                    any("Severe Hypervisor Maintenance interrupt [Recovered]" in line for line in l_res):
                    print "Timer facility experienced an error and got recovered"
                else:
                    l_msg = "HMI handling failed to log message"
                    raise OpTestError(l_msg)
                time.sleep(BMC_CONST.HMI_TEST_CASE_SLEEP_TIME)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function tests chip TOD related error injections and check
    #        the corresponding error got recovered. And this error injection
    #        happening on a random chip. This tod errors should test on systems
    #        having more than one processor socket(chip). On single chip system
    #        TOD error recovery won't work.
    #
    # @param i_error @type string: this is the type of error want to inject
    #                       These errors represented in common/OpTestConstants.py file.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_tod_errors(self, i_error):
        l_error = i_error
        l_pair = random.choice(self.l_dic)
        # Get random chip id
        l_chip = l_pair[0]
        l_cmd = "./putscom -c %s %s %s;echo $?" % (l_chip, BMC_CONST.TOD_ERROR_REG, l_error)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg -C")
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        time.sleep(10)
        # As of now putscom command to TOD register will fail with return code -1.
        # putscom indirectly call getscom to read the value again.
        # But getscom to TOD error reg there is no access
        # TOD Error reg has only WO access and there is no read access
        if l_res[-1] == "1":
            print "Injected TOD error %s" % l_error
        else:
            if any("Kernel panic - not syncing" in line for line in l_res):
                print "TOD ERROR Injection-kernel got panic"
            elif any("login:"******"System booted to host OS without any kernel panic message"
            elif any("Petitboot" in line for line in l_res):
                print "System reached petitboot without any kernel panic message"
            elif any("ISTEP" in line for line in l_res):
                print "System started booting without any kernel panic message"
            else:
                l_msg = "TOD: PSS Hamming distance error injection failed"
                raise OpTestError(l_msg)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console("dmesg")
        if any("Timer facility experienced an error" in line for line in l_res) and \
            any("Severe Hypervisor Maintenance interrupt [Recovered]" in line for line in l_res):
            print "Timer facility experienced an error and got recovered"
        else:
            l_msg = "HMI handling failed to log message"
            raise OpTestError(l_msg)
        time.sleep(BMC_CONST.HMI_TEST_CASE_SLEEP_TIME)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function enables a single core
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def host_enable_single_core(self):
        self.cv_HOST.host_enable_single_core()
Exemplo n.º 36
0
class OpTestOCC():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()


    ##
    # @brief This function is used to test OCC Reset funtionality in BMC based systems.
    #        OCC Reset reload is limited to 3 times per full power cycle.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_occ_reset_functionality(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            #raise OpTestError(l_msg)
        print "OPAL-PRD: OCC Enable"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
        print "OPAL-PRD: OCC DISABLE"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
        print "OPAL-PRD: OCC RESET"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
        time.sleep(60)
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            #raise OpTestError(l_msg)
        print "OPAL-PRD: OCC Enable"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
        print "OPAL-PRD: OCC DISABLE"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
        print "OPAL-PRD: OCC RESET"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
        time.sleep(60)
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            #raise OpTestError(l_msg)
        print "OPAL-PRD: OCC Enable"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
        print "OPAL-PRD: OCC DISABLE"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
        print "OPAL-PRD: OCC RESET"
        self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
        time.sleep(60)
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state, rebooting the system"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)

    ##
    # @brief This function is used to test OCC Reset funtionality in BMC based systems.
    #        OCC Reset reload can be done more than 3 times per full power cycle, by
    #        resetting OCC resetreload count.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_occ_reset_n_times(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state after rebooting"
            raise OpTestError(l_msg)

        for i in range(1, BMC_CONST.OCC_RESET_RELOAD_COUNT):
            print "*******************OCC Reset count %d*******************" % i
            print "OPAL-PRD: OCC Enable"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
            print "OPAL-PRD: OCC DISABLE"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
            print "OPAL-PRD: OCC RESET"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_RESET)
            time.sleep(60)
            if self.check_occ_status() == BMC_CONST.FW_FAILED:
                l_msg = "OCC's are not in active state"
                raise OpTestError(l_msg)
            print "OPAL-PRD: occ query reset reload count"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_QUERY_RESET_COUNTS)
            print "OPAL-PRD: occ reset reset/reload count"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_SET_RESET_RELOAD_COUNT)
            print "OPAL-PRD: occ query reset reload count"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_QUERY_RESET_COUNTS)

        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state after rebooting"
            raise OpTestError(l_msg)

    ##
    # @brief This function is used to test OCC Enable and Disable funtionality in BMC based systems.
    #        There is no limit for occ enable and disable, as of now doing 10 times in a loop.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_occ_enable_disable_functionality(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)
        for count in range(1,10):
            print "OPAL-PRD: OCC Enable"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_ENABLE)
            print "OPAL-PRD: OCC Disable"
            self.cv_HOST.host_run_command(BMC_CONST.OCC_DISABLE)
            time.sleep(60)
            if self.check_occ_status() == BMC_CONST.FW_FAILED:
                l_msg = "OCC's are not in active state"
                #raise OpTestError(l_msg)
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == 0:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        if self.check_occ_status() == BMC_CONST.FW_FAILED:
            l_msg = "OCC's are not in active state"
            raise OpTestError(l_msg)

    ##
    # @brief This function is used to get OCC status enable/disable.
    #
    # @return BMC_CONST.FW_SUCCESS - OCC's are active or 
    #         BMC_CONST.FW_FAILED  - OCC's are not in active state
    #
    def check_occ_status(self):
        l_status = self.cv_IPMI.ipmi_get_occ_status()
        print l_status
        if BMC_CONST.OCC_DEVICE_ENABLED in l_status:
            print "OCC's are up and active"
            return BMC_CONST.FW_SUCCESS
        else:
            print "OCC's are not in active state"
            return BMC_CONST.FW_FAILED
class OpTestIPMIReprovision():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostUser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostIP=None,
                 i_hostUser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostIP, i_hostUser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostIP, i_hostUser, i_hostPasswd,i_bmcIP, i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostIP,
                 i_hostUser, i_hostPasswd)
        self.util = OpTestUtil()
        self.opTestHMIHandling = OpTestHMIHandling(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostIP,
                 i_hostUser, i_hostPasswd)

    ##
    # @brief This function will cover following test steps
    #        Testcase: NVRAM Partition-IPMI Reprovision
    #        1. Update NVRAM config data with test config data
    #           i.e "nvram --update-config test-name=test-value"

    #        2. Issue an IPMI PNOR Reprovision request command, to reset NVRAM partition to default.
    #        3. Wait for PNOR Reprovision progress to complete(00).
    #        4. Do a Hard reboot(Power OFF/ON) to avoid nvram cache data.
    #        5. Once system booted, check for NVRAM parition whether the test config data
    #           got erased or not.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_nvram_ipmi_reprovision(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        self.cv_HOST.host_run_command("uname -a")
        self.cv_HOST.host_run_command(BMC_CONST.NVRAM_PRINT_CFG)
        print "IPMI_Reprovision: Updating the nvram partition with test cfg data"
        self.cv_HOST.host_run_command(BMC_CONST.NVRAM_UPDATE_CONFIG_TEST_DATA)
        self.cv_HOST.host_run_command(BMC_CONST.NVRAM_PRINT_CFG)
        print "IPMI_Reprovision: issuing ipmi pnor reprovision request"
        self.cv_SYSTEM.sys_issue_ipmi_pnor_reprovision_request()
        print "IPMI_Reprovision: wait for reprovision to complete"
        self.cv_SYSTEM.sys_wait_for_ipmi_pnor_reprovision_to_complete()
        print "IPMI_Reprovision: gathering the opal message logs"
        self.cv_HOST.host_gather_opal_msg_log()
        print "IPMI_Reprovision: Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "IPMI_Reprovision: System is in standby/Soft-off state"
        else:
            l_msg = "IPMI_Reprovision: System failed to reach standby/Soft-off state after pnor reprovisioning"
            raise OpTestError(l_msg)

        print "IPMI_Reprovision: Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        l_res = self.cv_HOST.host_run_command(BMC_CONST.NVRAM_PRINT_CFG)
        if l_res.__contains__(BMC_CONST.NVRAM_TEST_DATA):
            l_msg = "NVRAM Partition - IPMI Reprovision not happening, nvram test config data still exists"
            raise OpTestError(l_msg)
        print "NVRAM Partition - IPMI Reprovision is done, cleared the nvram test config data"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function will cover following test steps
    #        Testcase: GARD Partition-IPMI Reprovision
    #        1. Inject core checkstop using existed function from OpTestHMIHandling.py
    #        2. Do a Hard reboot(IPMI Power OFF/ON)
    #        2. Issue an IPMI PNOR Reprovision request command, to reset GUARD partition to default.
    #        3. Wait for IPMI PNOR Reprovision progress to complete(00).
    #        4. Check for GUARD parition whether the existing gard records erased or not.
    #        6. Reboot the system back to see system is booting fine or not.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_gard_ipmi_reprovision(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "IPMI_Reprovision: Injecting system core checkstop to guard the phyisical cpu"
        self.opTestHMIHandling.testHMIHandling(BMC_CONST.HMI_MALFUNCTION_ALERT)
        print "IPMI_Reprovision: Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "IPMI_Reprovision: System is in standby/Soft-off state"
        else:
            l_msg = "IPMI_Reprovision: System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        print "IPMI_Reprovision: Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        print "IPMI_Reprovision: issuing ipmi pnor reprovision request"
        self.cv_SYSTEM.sys_issue_ipmi_pnor_reprovision_request()
        print "IPMI_Reprovision: wait for reprovision to complete"
        self.cv_SYSTEM.sys_wait_for_ipmi_pnor_reprovision_to_complete()
        print "IPMI_Reprovision: gathering the opal message logs"
        self.cv_HOST.host_gather_opal_msg_log()
        self.cv_HOST.host_get_OS_Level()
        self.cv_HOST.host_clone_skiboot_source(BMC_CONST.CLONE_SKIBOOT_DIR)
        # Compile the necessary tools xscom-utils and gard utility
        self.cv_HOST.host_compile_gard_utility(BMC_CONST.CLONE_SKIBOOT_DIR)
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_host_login(l_con)
        self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        l_res = self.cv_SYSTEM.sys_list_gard_records(BMC_CONST.GARD_TOOL_DIR)
        print l_res
        if BMC_CONST.NO_GARD_RECORDS in l_res:
            print "GUARD Partition - IPMI Reprovision is done, cleared HW gard records"
        else:
            l_msg = "IPMI: Reprovision not happening, gard records are not erased"
            raise OpTestError(l_msg)
        print "IPMI_Reprovision: Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "IPMI_Reprovision: System is in standby/Soft-off state"
        else:
            l_msg = "IPMI_Reprovision: System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        print "IPMI_Reprovision: Performing a IPMI Power ON Operation"
        # Perform a IPMI Power ON Operation
        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)

        print "IPMI_Reprovision: gathering the opal message logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS
class OpTestInbandUsbInterface():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the host
    # @param i_hostUser The userid to log into the host
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostIP=None,
                 i_hostUser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostIP, i_hostUser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostIP,
                 i_hostUser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS level installed on powernv platform
    #        2. It will check for kernel version installed on the Open Power Machine
    #        3. It will check for ipmitool command existence and ipmitool package
    #        4. Checking Inband ipmitool command functionality with different options
    #           using ipmitool usb interface.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_ipmi_inband_usb_interface(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
         # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for ipmitool command and lm_sensors package
        self.cv_HOST.host_check_command("ipmitool")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "ipmitool")
        print "Installed package: %s" % l_pkg

        # loading below ipmi modules based on config option
        # ipmi_devintf, ipmi_powernv and ipmi_masghandler
        self.cv_HOST.host_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_DEVICE_INTERFACE,
                                                      BMC_CONST.IPMI_DEV_INTF)
        self.cv_HOST.host_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_POWERNV,
                                                      BMC_CONST.IPMI_POWERNV)
        self.cv_HOST.host_load_module_based_on_config(l_kernel, BMC_CONST.CONFIG_IPMI_HANDLER,
                                                      BMC_CONST.IPMI_MSG_HANDLER)

        fail_count = 0
        test_cases = [self.test_chassis, self.test_chassis_identifytests,
                        self.test_chassis_bootdev, self.test_channel,
                        self.test_Info, self.test_sdr_list_by_type,
                        self.test_sdr_elist_by_type, self.test_sdr_type_list,
                        self.test_sdr_get_id, self.test_fru_print, self.test_fru_read,
                        self.test_sel_info, self.test_sel_list,
                        self.test_sel_elist, self.test_sel_time_get,
                        self.test_sel_set_time, self.test_sel_list_first_3_entries,
                        self.test_sel_list_last_3_entries, self.test_sel_get_functionality,
                        self.test_sel_clear_functionality, self.test_mc,
                        self.test_sensor_list,self.test_sensor_get_host_status,
                        self.test_sensor_get_os_boot, self.test_sensor_get_occ_active,
                        self.test_dcmi, self.test_echo, self.test_event,
                        self.test_firewall, self.test_pef, self.test_raw,
                        self.test_exec]

        for test in test_cases:
            try:
                print "In-band IPMI[USB]: test case %s" % test
                test(self)
            except:
                print "Test Fail: %s failed" % test
                fail_count += 1
                print sys.exc_info()
                continue

        print "Inband IPMI[USB]: Test case failure count %s" % fail_count


    ##
    # @brief  It will execute and test the return code of ipmi command.
    #
    # @param i_cmd @type string:The ipmitool command, for example: ipmitool -I usb chassis status; echo $?
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def run_ipmi_cmd_on_host(self, i_cmd):
        l_cmd = i_cmd
        print l_cmd
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI: command failed %c" % l_cmd
            raise OpTestError(l_msg)
        return l_res

    ##
    # @brief  It will execute and test the ipmitool -I usb chassis <cmd> commands
    #         cmd: status, poh, restart_cause, policy list and policy set
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassis(self):
        print "Inband IPMI[USB]: Chassis tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_POH)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_RESTART_CAUSE)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_POLICY_LIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_POLICY_ALWAYS_OFF)

    ##
    # @brief  It will execute and test the ipmi chassis identify commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassis_identifytests(self):
        print "Inband IPMI[USB]: Chassis Identify tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_IDENTIFY_5)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_IDENTIFY_FORCE)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_IDENTIFY)

    ##
    # @brief  It will execute and test the functionality of ipmi chassis bootdev <dev>
    #         dev: none,pxe,cdrom,disk,bios,safe,diag,floppy and none.
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    @staticmethod
    def test_chassis_bootdev(self):
        print "Inband IPMI[USB]: Chassis Bootdevice tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_PXE)
        self.verify_bootdev("pxe")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_CDROM)
        self.verify_bootdev("cdrom")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_DISK)
        self.verify_bootdev("disk")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_BIOS)
        self.verify_bootdev("bios")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_SAFE)
        self.verify_bootdev("safe")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_DIAG)
        self.verify_bootdev("diag")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_FLOPPY)
        self.verify_bootdev("floppy")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")

    ##
    # @brief  It will verify whether setting of given bootdevice is honoured or not
    #         by reading chassis bootparam get 5
    #
    # @param i_dev @type string: boot device name: Ex safe, disk and cdrom
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    def verify_bootdev(self, i_dev):
        l_res = self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTPARAM_GET_5)
        if i_dev == "safe":
            l_msg = "Force Boot from default Hard-Drive, request Safe-Mode"
        elif i_dev == "disk":
            l_msg = "Force Boot from default Hard-Drive"
        elif i_dev == "diag":
            l_msg = "Force Boot from Diagnostic Partition"
        elif i_dev == "bios":
            l_msg = "Force Boot into BIOS Setup"
        elif i_dev == "pxe":
            l_msg = "Force PXE"
        elif i_dev == "cdrom":
            l_msg = "Force Boot from CD/DVD"
        elif i_dev == "none":
            l_msg = "No override"
        elif i_dev == "floppy":
            l_msg = "Force Boot from Floppy/primary removable media"
        else:
            print "pass proper bootdevice"

        for l_line in l_res:
            if l_line.__contains__(l_msg):
                print "Verifying bootdev is successfull for %s" % i_dev
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Boot device is not set to %s" % i_dev
            raise OpTestError(l_msg)

    ##
    # @brief  It will check basic channel functionalities: info and authentication capabilities.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_channel(self):
        print "Inband IPMI[USB]: Channel tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHANNEL_AUTHCAP)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHANNEL_INFO)

    ##
    # @brief  It will execute and test the ipmi <sdr/sel/mc/channel> info related commands.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_Info(self):
        print "Inband IPMI[USB]: Info tests"
        #self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHANNEL_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SEL_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_INFO)

    ##
    # @brief  It will execute and test the ipmi sdr list <all/fru/event/mcloc/compact/full/generic>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_list_by_type(self):
        print "Inband IPMI[USB]: SDR list tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_ALL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_FRU)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_EVENT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_MCLOC)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_COMPACT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_FULL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_LIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr elist <all/fru/event/mcloc/compact/full/generic>
    #         commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_elist_by_type(self):
        print "Inband IPMI[USB]: SDR elist tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_ALL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_FRU)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_EVENT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_MCLOC)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_COMPACT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_FULL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_ELIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr type <Temp/fan/Powersupply> commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_type_list(self):
        print "Inband IPMI[USB]: SDR type list tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_TYPE_LIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_TYPE_TEMPERATURE)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_TYPE_FAN)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_TYPE_POWER_SUPPLY)

    ##
    # @brief  It will execute and test the ipmi sdr get <sensor-id> command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_get_id(self):
        print "Inband IPMI[USB]: SDR get tests"
        l_cmd = BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_GET_WATCHDOG + "; echo $?"
        self.run_ipmi_cmd_on_host(l_cmd)

    ##
    # @brief  It will execute and test the ipmi fru print command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_print(self):
        print "Inband IPMI[USB]: FRU Print Test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_FRU_PRINT)

    ##
    # @brief  It will execute and test the ipmi fru read command.
    #         then the output file is displayed by hexdump
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_read(self):
        print "Inband IPMI[USB]: FRU Read Test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + "fru read 0 /tmp/file_fru; echo $?")
        l_res = self.cv_HOST.host_run_command("hexdump -C /tmp/file_fru; echo $?")
        # TODO: Check for file output

    ##
    # @brief  It will execute and test the management controller(mc) commands functionality
    #         info-Displays information about the BMC hardware, including device revision,
    #              firmware revision, IPMI version supported, manufacturer ID,  and  information
    #               on additional device support
    #         watchdog get-Show current Watchdog Timer settings and countdown state.
    #         watchdog off-Turn off a currently running Watchdog countdown timer.
    #         watchdog reset-Reset the Watchdog Timer to its most recent state and restart the countdown timer.
    #         selftest- Check on the basic health of the BMC by executing the
    #                   Get Self Test results command and report the results.
    #         setenables-Enables  or disables the given option
    #         getenables-Displays a list of the currently enabled options for the BMC.
    #         getsysinfo-Retrieves system info from bmc for given argument
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_mc(self):
        print "Inband IPMI[USB]: MC tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_WATCHDOG_GET)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_SETENABLES_OEM_0_OFF)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_SETENABLES_OEM_0_ON)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_WATCHDOG_OFF)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_WATCHDOG_RESET)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_MC_GETSYS_INFO)

    ##
    # @brief  It will execute and test the ipmi sel info functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_info(self):
        print "Inband IPMI[USB]: SEL Info test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SEL_INFO)

    ##
    # @brief  It will execute and test ipmi sel list functionality.
    #         the entire contents of the System Event Log are displayed.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list(self):
        print "Inband IPMI[USB]: SEL List test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SEL_LIST)

    ##
    # @brief  It will execute and test the ipmi sel elist functionality
    #         If invoked as elist (extended list) it will also use the
    #         Sensor Data Record entries to display the sensor ID for
    #           the sensor that caused each event.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_elist(self):
        print "Inband IPMI[USB]: SEL elist test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SEL_ELIST)

    ##
    # @brief  It will execute and test the ipmi sel time get functionality
    #         Displays the SEL clock's current time.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_time_get(self):
        print "Inband IPMI[USB]: SEL Time get test"
        l_res = self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SEL_TIME_GET)
        return l_res

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @param i_time @type string: the value to be set as a sel time
    #               <time string> is of the form "MM/DD/YYYY HH:MM:SS"
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_time_set(self, i_time):
        print "Inband IPMI[USB]: SEL Time set test"
        l_cmd = "sel time set \'%s\'; echo $?" % i_time
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list first <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_first_n_entries(self, i_num):
        l_cmd = "sel list first %i; echo $?" % int(i_num)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list last <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_last_n_entries(self, i_num):
        l_cmd = "sel list last %i; echo $?" % int(i_num)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)


    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @param i_sel_id @type string: for example 0x05, 0x06..
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_get_byid(self, i_sel_id):
        l_cmd = "sel get %s; echo $?" % i_sel_id
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute the ipmi sel clear command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_clear(self):
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SEL_CLEAR)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_get_functionality(self):
        l_res = self.cv_HOST.host_run_command(BMC_CONST.IPMITOOL_USB + "sel list first 3 | awk '{print $1}'")
        if l_res.__contains__("SEL has no entries"):
            print "IPMI: There are no sel entries to fetch"
            pass
        else:
            l_list = l_res.splitlines()
            del l_list[0]
            for l in l_list:
                l_id = "0x" + l
                self.test_sel_get_byid(l_id)

    ##
    # @brief  It will execute and test the ipmi sel clear functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_clear_functionality(self):
        self.test_sel_clear(self)
        l_res = self.cv_HOST.host_run_command("ipmitool -I usb sel list; echo $?")
        l_list = l_res.splitlines()
        for l_line in l_list:
            if l_line.__contains__("SEL has no entries"):
                print "Sel clear function got cleared event entries"
                break
        else:
            l_msg = "Inband IPMI[USB]: sel clear function failing in clearing entries"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi sensor list functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_list(self):
        print "Inband IPMI[USB]: Sensor tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SENSOR_LIST)

    ##
    # @brief  It will execute and test the ipmi sensor get <id> functionality
    #
    # @param i_sensor @type string:sensor id to retrieve the data
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sensor_byid(self, i_sensor):
        l_cmd = BMC_CONST.IPMITOOL_USB + "sensor get \"%s\"; echo $?" % i_sensor
        self.run_ipmi_cmd_on_host(l_cmd)

    ##
    # @brief  It will execute and test the dcmi related ipmi commands.
    #         discover-This command is used to discover supported capabilities in DCMI
    #         Power reading-Get power related readings from the system.
    #               get_limit-Get the configured power limits.
    #         sensors-Prints the available DCMI sensors.
    #         get_mc_id_string-Get management controller identifier string
    #         get_temp_reading-Get Temperature Sensor Readings.
    #         get_conf_param-Get DCMI Configuration Parameters.
    #         oob_discover-Ping/Pong Message for DCMI Discovery
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_dcmi(self):
        print "Inband IPMI[USB]: dcmi tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_POWER_READING)
        #self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)

    ##
    # @brief  It will execute and test the functionality of ipmi echo command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_echo(self):
        print "Inband IPMI[USB]: echo tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_ECHO_DONE)

    ##
    # @brief  It will execute and test event related commands to test sel functionality.
    #         Send a pre-defined test event to the System Event Log.  The following
    #         events are included as a means to test the functionality of  the  System
    #         Event Log component of the BMC (an entry will be added each time the
    #         event N command is executed)
    #         Currently supported values for N are:
    #         1    Temperature: Upper Critical: Going High
    #         2    Voltage Threshold: Lower Critical: Going Low
    #         3    Memory: Correctable ECC
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_event(self):
        print "Inband IPMI[USB]: event tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_EVENT_1)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_EVENT_2)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_EVENT_3)

    ##
    # @brief  It will execute and test ipmi exec command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_exec(self):
        print "Inband IPMI[USB]: exec tests"
        pass
        # TODO: need to execute ipmi commands from a file

    ##
    # @brief  It will execute and test firmware firewall info command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_firewall(self):
        print "Inband IPMI[USB]: Firewall test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_FIREWALL_INFO)

    ##
    # @brief  It will execute and test pef related commands:
    #         info:This command will query the BMC and print information about the PEF supported features.
    #         status: This command prints the current PEF status
    #         policy: This command lists the PEF policy table entries
    #         list: This  command  lists  the PEF table entries.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_pef(self):
        print "Inband IPMI[USB]: Pef tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_PEF_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_PEF_STATUS)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_PEF_POLICY)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_PEF_LIST)

    ##
    # @brief This will test raw IPMI commands. For example to query the POH counter with a raw command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_raw(self):
        print "Inband IPMI[USB]: raw command execution tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_RAW_POH)

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_set_time(self):
        l_res = self.test_sel_time_get(self)
        self.test_sel_time_set(l_res[-2])

    ##
    # @brief  It will execute and test the ipmi sel list first <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_first_3_entries(self):
        self.test_sel_list_first_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)

    ##
    # @brief  It will execute and test the ipmi sel list last <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_last_3_entries(self):
        self.test_sel_list_last_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)

    ##
    # @brief  It will execute and test the ipmi sensor get "Host Status" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_host_status(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_HOST_STATUS)

    ##
    # @brief  It will execute and test the ipmi sensor get "OS Boot" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_os_boot(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OS_BOOT)

    ##
    # @brief  It will execute and test the ipmi sensor get "OCC Active" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_occ_active(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OCC_ACTIVE)
Exemplo n.º 39
0
class OpTestNVRAM():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function tests nvram partition access, print/update
    #         the config data and dumping the partition's data. All
    #         these operations are done on supported partitions in both
    #         host OS and Petitboot.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_nvram_configuration(self):
        # Execute these tests in host OS
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        self.cv_HOST.host_run_command("uname -a")
        self.cv_HOST.host_run_command("cat /etc/os-release")
        self.cv_HOST.host_run_command("nvram -v")
        self.cv_HOST.host_run_command("nvram --print-config -p ibm,skiboot")
        self.cv_HOST.host_run_command("nvram --print-config -p common")
        self.cv_HOST.host_run_command("nvram --print-config -p lnx,oops-log")
        self.cv_HOST.host_run_command("nvram --print-config -p wwwwwwwwwwww")
        self.cv_HOST.host_run_command("nvram --print-vpd")
        self.cv_HOST.host_run_command("nvram --print-all-vpd")
        self.cv_HOST.host_run_command("nvram --print-err-log")
        self.cv_HOST.host_run_command("nvram --print-event-scan")
        self.cv_HOST.host_run_command("nvram --partitions")
        self.cv_HOST.host_run_command("nvram --dump common")
        self.cv_HOST.host_run_command("nvram --dump ibm,skiboot")
        self.cv_HOST.host_run_command("nvram --dump lnx,oops-log")
        self.cv_HOST.host_run_command("nvram --dump wwwwwwwwwwww")
        self.cv_HOST.host_run_command("nvram --ascii common")
        self.cv_HOST.host_run_command("nvram --ascii ibm,skiboot")
        self.cv_HOST.host_run_command("nvram --ascii lnx,oops-log")
        self.cv_HOST.host_run_command("nvram --ascii wwwwwwwwwwww")
        try:
            self.test_nvram_update_part_config_in_host("common")
            self.test_nvram_update_part_config_in_host("ibm,skiboot")
            self.test_nvram_update_part_config_in_host("lnx,oops-log")
            self.test_nvram_update_part_config_in_host("wwwwwwwwwwww")
        except OpTestError:
            print "There is a failure in updating one of NVRAM partitions"

        # Execute these tests in petitboot
        self.console = self.cv_SYSTEM.sys_get_ipmi_console()
        try:
            self.cv_SYSTEM.sys_ipmi_boot_system_to_petitboot(self.console)
            self.cv_IPMI.ipmi_host_set_unique_prompt(self.console)
            self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("cat /etc/os-release")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram -v")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-config -p ibm,skiboot")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-config -p common")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-config -p lnx,oops-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-config -p wwwwwwwwwwww")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-vpd")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-all-vpd")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-err-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-event-scan")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --partitions")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --dump common")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --dump ibm,skiboot")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --dump lnx,oops-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --dump wwwwwwwwwwww")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --ascii common")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --ascii ibm,skiboot")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --ascii lnx,oops-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --ascii wwwwwwwwwwww")
            try:
                self.test_nvram_update_part_config_in_petitboot("common")
                self.test_nvram_update_part_config_in_petitboot("ibm,skiboot")
                self.test_nvram_update_part_config_in_petitboot("lnx,oops-log")
                self.test_nvram_update_part_config_in_petitboot("wwwwwwwwwwww")
            except OpTestError:
                print "There is a failure in updating one of NVRAM partitions"
        except:
            self.cv_IPMI.ipmi_set_boot_to_disk()
        self.cv_IPMI.ipmi_set_boot_to_disk()

    ##
    # @brief This function tests nvram update/print config functions for partition i_part
    #        these functions will be tested in host OS
    #
    # @param i_part @type string:partition to access i.e common, ibm,skiboot etc
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_nvram_update_part_config_in_host(self, i_part):
        part = i_part
        self.cv_HOST.host_run_command("nvram -p %s --update-config 'test-cfg=test-value'" % part)
        res = self.cv_HOST.host_run_command("nvram -p %s --print-config=test-cfg" % part)
        if "test-value" in res:
            print "Update config to the partition %s works fine" % part
        else:
            msg = "failed to update nvram config into the partition %s" % part
            print msg
            raise OpTestError(msg)

    ##
    # @brief This function tests nvram update/print config functions for partition i_part
    #        these functions will be tested in Petitboot.
    #
    # @param i_part @type string:partition to access i.e common, ibm,skiboot etc
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_nvram_update_part_config_in_petitboot(self, i_part):
        part = i_part
        self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram -p %s --update-config 'test-cfg=test-value'" % part)
        res_list = self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram -p %s --print-config=test-cfg" % part)
        res = ''.join(res_list)
        if "test-value" in res:
            print "Update config to the partition %s works fine" % part
        else:
            msg = "failed to update nvram config into the partition %s" % part
            print msg
            raise OpTestError(msg)
    def objs(self):
        host = OpTestHost(self.args.host_ip,
                          self.args.host_user,
                          self.args.host_password,
                          self.args.bmc_ip,
                          self.output,
                          scratch_disk=self.args.host_scratch_disk,
                          proxy=self.args.proxy,
                          logfile=self.logfile,
                          check_ssh_keys=self.args.check_ssh_keys,
                          known_hosts_file=self.args.known_hosts_file)
        if self.args.bmc_type in ['AMI', 'SMC']:
            web = OpTestWeb(self.args.bmc_ip, self.args.bmc_usernameipmi,
                            self.args.bmc_passwordipmi)
            bmc = None
            if self.args.bmc_type in ['AMI']:
                ipmi = OpTestIPMI(
                    self.args.bmc_ip,
                    self.args.bmc_usernameipmi,
                    self.args.bmc_passwordipmi,
                    host=host,
                    logfile=self.logfile,
                )

                bmc = OpTestBMC(ip=self.args.bmc_ip,
                                username=self.args.bmc_username,
                                password=self.args.bmc_password,
                                logfile=self.logfile,
                                ipmi=ipmi,
                                web=web,
                                check_ssh_keys=self.args.check_ssh_keys,
                                known_hosts_file=self.args.known_hosts_file)
            elif self.args.bmc_type in ['SMC']:
                ipmi = OpTestSMCIPMI(
                    self.args.bmc_ip,
                    self.args.bmc_usernameipmi,
                    self.args.bmc_passwordipmi,
                    logfile=self.logfile,
                    host=host,
                )
                bmc = OpTestSMC(ip=self.args.bmc_ip,
                                username=self.args.bmc_username,
                                password=self.args.bmc_password,
                                ipmi=ipmi,
                                web=web,
                                check_ssh_keys=self.args.check_ssh_keys,
                                known_hosts_file=self.args.known_hosts_file)
            self.op_system = OpTestSystem(
                state=self.startState,
                bmc=bmc,
                host=host,
            )
            ipmi.set_system(self.op_system)
        elif self.args.bmc_type in ['FSP']:
            ipmi = OpTestIPMI(self.args.bmc_ip,
                              self.args.bmc_usernameipmi,
                              self.args.bmc_passwordipmi,
                              host=host,
                              logfile=self.logfile)
            bmc = OpTestFSP(
                self.args.bmc_ip,
                self.args.bmc_username,
                self.args.bmc_password,
                ipmi=ipmi,
            )
            self.op_system = OpTestFSPSystem(
                state=self.startState,
                bmc=bmc,
                host=host,
            )
            ipmi.set_system(self.op_system)
        elif self.args.bmc_type in ['OpenBMC']:
            ipmi = OpTestIPMI(self.args.bmc_ip,
                              self.args.bmc_usernameipmi,
                              self.args.bmc_passwordipmi,
                              host=host,
                              logfile=self.logfile)
            rest_api = HostManagement(self.args.bmc_ip, self.args.bmc_username,
                                      self.args.bmc_password)
            bmc = OpTestOpenBMC(self.args.bmc_ip,
                                self.args.bmc_username,
                                self.args.bmc_password,
                                logfile=self.logfile,
                                ipmi=ipmi,
                                rest_api=rest_api,
                                check_ssh_keys=self.args.check_ssh_keys,
                                known_hosts_file=self.args.known_hosts_file)
            self.op_system = OpTestOpenBMCSystem(
                host=host,
                bmc=bmc,
                state=self.startState,
            )
            bmc.set_system(self.op_system)
        elif self.args.bmc_type in ['qemu']:
            print repr(self.args)
            bmc = OpTestQemu(self.args.qemu_binary,
                             self.args.flash_skiboot,
                             self.args.flash_kernel,
                             self.args.flash_initramfs,
                             cdrom=self.args.os_cdrom,
                             logfile=self.logfile,
                             hda=self.args.host_scratch_disk)
            self.op_system = OpTestQemuSystem(host=host, bmc=bmc)
        # Check that the bmc_type exists in our loaded addons then create our objects
        elif self.args.bmc_type in optAddons:
            (bmc, self.op_system) = optAddons[self.args.bmc_type].createSystem(
                self, host)
        else:
            raise Exception("Unsupported BMC Type")

        host.set_system(self.op_system)
        return
Exemplo n.º 41
0
class OpTestI2Cdriver():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                         i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                         i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function has following test steps
    #         1. Getting host information(OS and kernel info)
    #         2. Checking the required utilites are present on host or not
    #         3. Loading the necessary modules to test I2C device driver functionalites
    #            (i2c_dev, i2c_opal and at24)
    #         4. Getting the list of i2c buses
    #         5. Querying the i2c bus for devices
    #         3. Getting the list of i2c buses and eeprom chip addresses
    #         4. Accessing the registers visible through the i2cbus using i2cdump utility
    #         5. Listing the i2c adapter conetents and i2c bus entries to make sure sysfs entries
    #            created for each bus.
    #         6. Testing i2cget functionality for limited samples
    #            Avoiding i2cset functionality, it may damage the system.
    #
    # @return BMC_CONST.FW_SUCCESS-success or raise OpTestError-fail
    #
    def testI2Cdriver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        self.cv_HOST.host_get_OS_Level()

        # make sure install "i2c-tools" package in-order to run the test

        # Check whether i2cdump, i2cdetect and hexdump commands are available on host
        self.cv_HOST.host_check_command("i2cdump", "i2cdetect", "hexdump",
                                        "i2cget", "i2cset")

        # Get Kernel Version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # loading i2c_opal module based on config option
        l_config = "CONFIG_I2C_OPAL"
        l_module = "i2c_opal"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # loading i2c_dev module based on config option
        l_config = "CONFIG_I2C_CHARDEV"
        l_module = "i2c_dev"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # loading at24 module based on config option
        l_config = "CONFIG_EEPROM_AT24"
        l_module = "at24"
        self.cv_HOST.host_load_module_based_on_config(l_kernel, l_config, l_module)

        # Get information of EEPROM chips
        self.cv_HOST.host_get_info_of_eeprom_chips()

        # Get list of i2c buses available on host,
        # l_list=["0","1"....]
        # l_list1=["i2c-0","i2c-1","i2c-2"....]
        l_list, l_list1 = self.cv_HOST.host_get_list_of_i2c_buses()

        # Scanning i2c bus for devices attached to it.
        for l_bus in l_list:
            try:
                self.query_i2c_bus(l_bus)
            except OpTestI2CDetectUnsupported:
                print "Unsupported i2cdetect on bus %s" % l_bus

        # Get list of pairs of i2c bus and EEPROM device addresses in the host
        l_chips = self.cv_HOST.host_get_list_of_eeprom_chips()
        for l_args in l_chips:
            # Accessing the registers visible through the i2cbus using i2cdump utility
            # l_args format: "0 0x51","1 0x53",.....etc
            self.i2c_dump(l_args)

        # list i2c adapter conetents
        l_res = self.cv_HOST.host_run_command("ls -l /sys/class/i2c-adapter; echo $?")
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            pass
        else:
            l_msg = "listing i2c adapter contents through the sysfs entry failed"
            print l_msg
            raise OpTestError(l_msg)

        # Checking the sysfs entry of each i2c bus
        for l_bus in l_list1:
            l_res = self.cv_HOST.host_run_command("ls -l /sys/class/i2c-adapter/%s; echo $?" % l_bus)
            l_res = l_res.splitlines()
            if int(l_res[-1]) == 0:
                pass
            else:
                l_msg = "listing i2c bus contents through the sysfs entry failed"
                print l_msg
                raise OpTestError(l_msg)

        # Currently testing only getting the data from a data address, avoiding setting data.
        # Only four samples are gathered to check whether reading eeprom  data is working or not.
        # Setting eeprom data is dangerous and make your system UNBOOTABLE
        l_addrs = ["0x00", "0x10", "0x20", "0x30", "0x40", "0x50", "0x60", "0x70", "0x80", "0x90", "0xa0", "0xb0", "0xc0", "0xd0", "0xe0", "0xf0"]
        for l_addr in l_addrs:
            l_val = self.i2c_get(l_chips[1], l_addr)
            # self.i2c_set(l_list2[1], l_addr, "0x50")
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function query's the i2c bus for devices attached to it.
    #        i2cdetect is a utility to scan an I2C bus for devices
    #
    # @param i_bus @type string: i2c bus numer
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def query_i2c_bus(self, i_bus):
        print "Querying the i2c bus %s for devices attached to it" % i_bus
        l_res = self.cv_HOST.host_run_command("i2cdetect -y %i; echo $?" % int(i_bus))
        l_res = l_res.splitlines()

        if int(l_res[-1]) != 0:
            l_res = self.cv_HOST.host_run_command("i2cdetect -F %i|egrep '(Send|Receive) Bytes'|grep yes; echo $?" % int(i_bus))
            l_res = l_res.splitlines()
            if int(l_res[-1]) != 0:
                print "i2c bus %i doesn't support query" % int(i_bus)
                raise OpTestI2CDetectUnsupported;
            else:
                l_res = self.cv_HOST.host_run_command("i2cdetect -y -r %i; echo $?" % int(i_bus))
                l_res = l_res.splitlines()

        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Querying the i2cbus for devices failed:%s" % i_bus
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This i2cdump function takes arguments in pair of a string like "i2cbus address".
    #        i2cbus indicates the number or name of the I2C bus to be scanned. This number should
    #        correspond  to  one  of  the busses listed by i2cdetect -l. address indicates
    #        the address to be scanned on that bus, and is an integer between 0x03 and 0x77
    #        i2cdump is a program to examine registers visible through the I2C bus
    #
    # @param i_args @type string: this is the argument to i2cdump utility
    #                             args are in the form of "i2c-bus-number eeprom-chip-address"
    #                             Ex: "0 0x51","3 0x52" ....etc
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def i2c_dump(self, i_args):
        l_res = self.cv_HOST.host_run_command("i2cdump -f -y %s; echo $?" % i_args)
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "i2cdump failed for the device: %s" % i_args
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function i2cget read from I2C/SMBus chip registers
    #        command usage: i2cget [-f] [-y] i2cbus chip-address [data-address [mode]]
    #
    # @param i_args @type string: this is the argument to i2cget utility
    #                             args are in the form of "i2c-bus-number eeprom-chip-address"
    #                             Ex: "0 0x51","3 0x52" ....etc
    # @param i_addr @type string: this is the data-address on chip, from where data will be read
    #                             Ex: "0x00","0x10","0x20"...
    #
    # @return l_res @type string: data present on data-address or raise OpTestError
    #
    def i2c_get(self, i_args, i_addr):
        l_res = self.cv_HOST.host_run_command("i2cget -f -y %s %s;echo $?" % (i_args, i_addr))
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return l_res
        else:
            l_msg = "i2cget: Getting data from address %s failed" % i_addr
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This function i2cset will be used for setting I2C registers
    #        command usage: i2cset [-f] [-y] [-m mask] [-r] i2cbus chip-address data-address [value] ...  [mode]
    #
    # @param i_args @type string: this is the argument to i2cset utility
    #                             args are in the form of "i2c-bus-number eeprom-chip-address"
    #                             Ex: "0 0x51","3 0x52" ....etc
    # @param i_addr @type string: this is the data-address on chip, where data will be set
    #                             Ex: "0x00","0x10","0x20"...
    # @param i_val @type string: this is the value which will be set into data-address i_addr
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def i2c_set(self, i_args, i_addr, i_val):
        l_res = self.cv_HOST.host_run_command("i2cset -f -y %s %s %s;echo $?" % (i_args, i_addr, i_val))
        l_res = l_res.splitlines()
        if int(l_res[-1]) == 0:
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "i2cset: Setting the data to a address %s failed" % i_addr
            print l_msg
            raise OpTestError(l_msg)
Exemplo n.º 42
0
class OpTestMCColdResetEffects():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP,
                                  i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

        self.opTestSensors = OpTestSensors(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                           i_bmcUserIpmi, i_bmcPasswdIpmi,
                                           i_ffdcDir, i_hostip, i_hostuser,
                                           i_hostPasswd)

    ##
    # @brief  This function will test BMC Cold reset vs Host FW status
    #         1. When system is in runtime issue BMC Cold reset.
    #         2. Check Host FW services and drivers.
    #         3. Run sensors command
    #         4. Get list of chips
    #         5. This is expected to fail.
    #           https://github.com/open-power/op-build/issues/482
    #         6. Reboot the system at the end of test.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_bmc_cold_reset_effects(self):
        print "Test BMC Cold reset effects versus Host Firmware Status"
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        print "Issue BMC Cold reset"
        result = True
        try:
            self.cv_SYSTEM.sys_cold_reset_bmc()
            l_dir = BMC_CONST.SKIBOOT_WORKING_DIR
            self.cv_HOST.host_clone_skiboot_source(l_dir)
            self.cv_HOST.host_compile_xscom_utilities(l_dir)
            l_con = self.cv_SYSTEM.sys_get_ipmi_console()
            self.cv_IPMI.ipmi_host_login(l_con)
            self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
            self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "cd %s/external/xscom-utils/; ./getscom -l" % l_dir)
            self.opTestSensors.test_hwmon_driver()
            self.cv_SYSTEM.sys_ipmi_close_console(l_con)
        except:
            result = False
            pass
        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        self.cv_IPMI.ipmi_power_off()
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        if result is False:
            raise OpTestError("MC Cold reset vs Host FW Test failed")
Exemplo n.º 43
0
class OpTestFWTS():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP,
                                  i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()
        self.user = i_hostuser
        self.ip = i_hostip
        self.passwd = i_hostPasswd

    ##
    # @brief This function just brings the system to host OS.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_system_reboot(self):
        print "Testing FWTS: Booting system to OS"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(
                self.cv_SYSTEM.sys_wait_for_standby_state(
                    BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)
        ) == BMC_CONST.FW_SUCCESS:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function just executes the fwts_execution.sh on host OS
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_fwts(self):
        l_oslevel = self.cv_HOST.host_get_OS_Level()
        if not "Ubuntu" in l_oslevel:
            return
        # Copy the fwts execution file to the tmp folder in the host
        base_path = (os.path.dirname(
            os.path.abspath(__file__))).split('testcases')[0]
        fwts_script = base_path + "/testcases/fwts_execution.sh"
        try:
            self.util.copyFilesToDest(fwts_script, self.user, self.ip, "/tmp/",
                                      self.passwd)
        except:
            l_msg = "Copying fwts file to host failed"
            print l_msg
            raise OpTestError(l_msg)

        l_res = self.cv_HOST.host_run_command("/tmp/fwts_execution.sh")
        print l_res
Exemplo n.º 44
0
class OpTestPrdDriver():
    ## Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function performs below steps
    #        1. Initially connecting to host and ipmi consoles for execution.
    #        2. check for IPOLL mask register value to see whether opal-prd is running or not
    #           if it is 0-->opal-prd is running-->continue
    #           else start opal-prd service again
    #        3. call test_prd_for_fir() function for each core FIR error and this function
    #           can be used for any number of errors, like it is a generic function
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def testPrdDriver(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        self.test_init()
        l_con = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_IPMI.ipmi_host_login(l_con)
        self.cv_IPMI.ipmi_host_set_unique_prompt(l_con)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("cd %s/external/xscom-utils/;" % BMC_CONST.CLONE_SKIBOOT_DIR)

        # check for IPOLL mask register value to check opal-prd is running or not
        l_cmd = "./getscom -c 0x0 %s" % BMC_CONST.IPOLL_MASK_REGISTER
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        if l_res[-1] == BMC_CONST.IPOLL_MASK_REGISTER_CONTENT:
            print "Opal-prd is running"
        else:
            self.cv_IPMI.run_host_cmd_on_ipmi_console("service opal-prd start")
            l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
            if l_res[-1] == BMC_CONST.IPOLL_MASK_REGISTER_CONTENT:
                print "Opal-prd is running"
            else:
                l_msg = "IPOLL MASK REGISTER is not getting cleared by opal-prd"
                raise OpTestError(l_msg)

        # test for PBA FIR with different core errors
        # 1.PBAFIR_OCI_APAR_ERR-->OCI Address Parity Error
        print "PRD: Test for PBAFIR_OCI_APAR_ERR-->OCI Address Parity Error"
        self.test_prd_for_fir(BMC_CONST.PBA_FAULT_ISOLATION_REGISTER,
                              BMC_CONST.PBA_FAULT_ISOLATION_MASK_REGISTER,
                              BMC_CONST.PBAFIR_OCI_APAR_ERR)
        # 2.PBAFIR_PB_CE_FW-->PB Read Data CE Error for Forwarded Request
        print "PRD: Test for PBAFIR_PB_CE_FW-->PB Read Data CE Error for Forwarded Request"
        self.test_prd_for_fir(BMC_CONST.PBA_FAULT_ISOLATION_REGISTER,
                              BMC_CONST.PBA_FAULT_ISOLATION_MASK_REGISTER,
                              BMC_CONST.PBAFIR_PB_CE_FW)
        # 3.PBAFIR_PB_RDDATATO_FW-->PB Read Data Timeout for Forwarded Request
        print "PRD: Test for PBAFIR_PB_RDDATATO_FW-->PB Read Data Timeout for Forwarded Request"
        self.test_prd_for_fir(BMC_CONST.PBA_FAULT_ISOLATION_REGISTER,
                              BMC_CONST.PBA_FAULT_ISOLATION_MASK_REGISTER,
                              BMC_CONST.PBAFIR_PB_RDDATATO_FW)
        # 4.PBAFIR_PB_RDADRERR_FW-->PB CRESP Addr Error Received for Forwarded Read Request
        print "PRD: Test for PBAFIR_PB_RDADRERR_FW-->PB CRESP Addr Error Received for Forwarded Read Request"
        self.test_prd_for_fir(BMC_CONST.PBA_FAULT_ISOLATION_REGISTER,
                              BMC_CONST.PBA_FAULT_ISOLATION_MASK_REGISTER,
                              BMC_CONST.PBAFIR_PB_RDADRERR_FW)
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function injects some core FIR errors and verifies whether opal-prd clears the errors.
    #        and also this function injects errors on random chip.
    #
    # @param FIR @type str: Local Fault Isolation register
    # @param FIMR @type str: Local Fault Isolation mask register
    # @param ERROR @type int: Core FIR error, this error will be written to FIR.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_prd_for_fir(self, FIR, FIMR, ERROR):
        chip_id = "0x" + self.random_chip
        print chip_id
        print "OPAL-PRD: Injecting error 0x%x on FIR: %s" % (ERROR, FIR)
        # Read Local Fault Isolation register
        l_cmd = "./getscom -c %s %s" % (chip_id, FIR)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)

        # Reading Local Fault Isolation mask register
        l_cmd = "./getscom -c %s %s" % (chip_id, FIMR)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        print l_res

        # Changing the FIMR value to un-masked value.
        LEN = 16
        l_len = len(l_res[-1])
        l_val = hex(int(("0x" + "0"*(LEN - l_len) + l_res[-1]), 16)& (ERROR ^ 0xffffffffffffffff))

        # Writing the same value to Local Fault Isolation mask register again
        l_cmd = "./putscom -c %s %s %s" % (chip_id, BMC_CONST.PBA_FAULT_ISOLATION_MASK_REGISTER, l_val)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)

        # Inject a core error on FIR
        l_cmd = "./putscom -c %s %s %s" % (chip_id, FIR, hex(ERROR))
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)

        time.sleep(30)

        # Read Local Fault Isolation register again
        l_cmd = "./getscom -c %s %s" % (chip_id, FIR)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        print l_res

        # Check FIR got cleared by opal-prd
        if l_res[-1] == BMC_CONST.FAULT_ISOLATION_REGISTER_CONTENT:
            print "Opal-prd handles core hardware error"
        else:
            l_msg = "Opal-prd not clearing hardware errors in runtime"
            print l_msg
            raise OpTestError(l_msg)

        # Reading the Local Fault Isolation Mask Register again
        l_cmd = "./getscom -c %s %s" % (chip_id, FIMR)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        print l_res

        # check for IPOLL mask register value to see opal-prd cleared the value
        l_cmd = "./getscom -c %s %s" % (chip_id, BMC_CONST.IPOLL_MASK_REGISTER)
        l_res = self.cv_IPMI.run_host_cmd_on_ipmi_console(l_cmd)
        if l_res[-1] == BMC_CONST.IPOLL_MASK_REGISTER_CONTENT:
            print "Opal-prd cleared the IPOLL MASK REGISTER"
            return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Opal-prd is not clearing the IPOLL MASK REGISTER after injecting core FIR error"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief This is a common function for all the PRD test cases. This will be executed before
    #        any test case starts. Basically this provides below requirements.
    #        1. Validates all required host commands
    #        2. It will clone skiboot source repository
    #        3. Compile the necessary tools -xscom-utils(getscom and putscom)
    #        4. Get the list Of Chips.
    #           Ex: ['00000000', '00000001', '00000010']
    #        5. generate a random chip.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_init(self):
        # Get OS level
        self.cv_HOST.host_get_OS_Level()

        # Check whether git and gcc commands are available on host
        self.cv_HOST.host_check_command("git", "gcc")

        # It will clone skiboot source repository 
        self.cv_HOST.host_clone_skiboot_source(BMC_CONST.CLONE_SKIBOOT_DIR)

        # Compile the necessary tools xscom-utils and gard utility
        self.cv_HOST.host_compile_xscom_utilities(BMC_CONST.CLONE_SKIBOOT_DIR)

        # Getting list of processor chip Id's(executing getscom -l to get chip id's)
        l_res = self.cv_HOST.host_run_command("cd %s/external/xscom-utils/; ./getscom -l" % BMC_CONST.CLONE_SKIBOOT_DIR)
        l_res = l_res.splitlines()
        l_chips = []
        for line in l_res:
            matchObj = re.search("(\d{8}).*processor", line)
            if matchObj:
                l_chips.append(matchObj.group(1))
        if not l_chips:
            l_msg = "Getscom failed to list processor chip id's"
            raise OpTestError(l_msg)
        l_chips.sort()
        print l_chips # ['00000000', '00000001', '00000010']
        self.random_chip = random.choice(l_chips)

        # Below will be useful for debug purposes to compare chip information
        l_res = self.cv_HOST.host_read_msglog_core()
        print l_res
Exemplo n.º 45
0
class OpTestNVRAM():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief  This function tests nvram partition access, print/update
    #         the config data and dumping the partition's data. All
    #         these operations are done on supported partitions in both
    #         host OS and Petitboot.
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_nvram_configuration(self):
        # Execute these tests in host OS
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        self.cv_HOST.host_run_command("uname -a")
        self.cv_HOST.host_run_command("cat /etc/os-release")
        self.cv_HOST.host_run_command("nvram -v")
        self.cv_HOST.host_run_command("nvram --print-config -p ibm,skiboot")
        self.cv_HOST.host_run_command("nvram --print-config -p common")
        self.cv_HOST.host_run_command("nvram --print-config -p lnx,oops-log")
        self.cv_HOST.host_run_command("nvram --print-config -p wwwwwwwwwwww")
        self.cv_HOST.host_run_command("nvram --print-vpd")
        self.cv_HOST.host_run_command("nvram --print-all-vpd")
        self.cv_HOST.host_run_command("nvram --print-err-log")
        self.cv_HOST.host_run_command("nvram --print-event-scan")
        self.cv_HOST.host_run_command("nvram --partitions")
        self.cv_HOST.host_run_command("nvram --dump common")
        self.cv_HOST.host_run_command("nvram --dump ibm,skiboot")
        self.cv_HOST.host_run_command("nvram --dump lnx,oops-log")
        self.cv_HOST.host_run_command("nvram --dump wwwwwwwwwwww")
        self.cv_HOST.host_run_command("nvram --ascii common")
        self.cv_HOST.host_run_command("nvram --ascii ibm,skiboot")
        self.cv_HOST.host_run_command("nvram --ascii lnx,oops-log")
        self.cv_HOST.host_run_command("nvram --ascii wwwwwwwwwwww")
        try:
            self.test_nvram_update_part_config_in_host("common")
            self.test_nvram_update_part_config_in_host("ibm,skiboot")
            self.test_nvram_update_part_config_in_host("lnx,oops-log")
            self.test_nvram_update_part_config_in_host("wwwwwwwwwwww")
        except OpTestError:
            print "There is a failure in updating one of NVRAM partitions"

        # Execute these tests in petitboot
        self.console = self.cv_SYSTEM.sys_get_ipmi_console()
        try:
            self.cv_SYSTEM.sys_ipmi_boot_system_to_petitboot(self.console)
            self.cv_IPMI.ipmi_host_set_unique_prompt(self.console)
            self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("cat /etc/os-release")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram -v")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --print-config -p ibm,skiboot")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --print-config -p common")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --print-config -p lnx,oops-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --print-config -p wwwwwwwwwwww")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-vpd")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-all-vpd")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --print-err-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --print-event-scan")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --partitions")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --dump common")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --dump ibm,skiboot")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --dump lnx,oops-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --dump wwwwwwwwwwww")
            self.cv_IPMI.run_host_cmd_on_ipmi_console("nvram --ascii common")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --ascii ibm,skiboot")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --ascii lnx,oops-log")
            self.cv_IPMI.run_host_cmd_on_ipmi_console(
                "nvram --ascii wwwwwwwwwwww")
            try:
                self.test_nvram_update_part_config_in_petitboot("common")
                self.test_nvram_update_part_config_in_petitboot("ibm,skiboot")
                self.test_nvram_update_part_config_in_petitboot("lnx,oops-log")
                self.test_nvram_update_part_config_in_petitboot("wwwwwwwwwwww")
            except OpTestError:
                print "There is a failure in updating one of NVRAM partitions"
        except:
            self.cv_IPMI.ipmi_set_boot_to_disk()
        self.cv_IPMI.ipmi_set_boot_to_disk()

    ##
    # @brief This function tests nvram update/print config functions for partition i_part
    #        these functions will be tested in host OS
    #
    # @param i_part @type string:partition to access i.e common, ibm,skiboot etc
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_nvram_update_part_config_in_host(self, i_part):
        part = i_part
        self.cv_HOST.host_run_command(
            "nvram -p %s --update-config 'test-cfg=test-value'" % part)
        res = self.cv_HOST.host_run_command(
            "nvram -p %s --print-config=test-cfg" % part)
        if "test-value" in res:
            print "Update config to the partition %s works fine" % part
        else:
            msg = "failed to update nvram config into the partition %s" % part
            print msg
            raise OpTestError(msg)

    ##
    # @brief This function tests nvram update/print config functions for partition i_part
    #        these functions will be tested in Petitboot.
    #
    # @param i_part @type string:partition to access i.e common, ibm,skiboot etc
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_nvram_update_part_config_in_petitboot(self, i_part):
        part = i_part
        self.cv_IPMI.run_host_cmd_on_ipmi_console(
            "nvram -p %s --update-config 'test-cfg=test-value'" % part)
        res_list = self.cv_IPMI.run_host_cmd_on_ipmi_console(
            "nvram -p %s --print-config=test-cfg" % part)
        res = ''.join(res_list)
        if "test-value" in res:
            print "Update config to the partition %s works fine" % part
        else:
            msg = "failed to update nvram config into the partition %s" % part
            print msg
            raise OpTestError(msg)
Exemplo n.º 46
0
class OpTestFWTS():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self, i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir=None, i_hostip=None,
                 i_hostuser=None, i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser, i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP, i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                 i_bmcUserIpmi, i_bmcPasswdIpmi, i_ffdcDir, i_hostip,
                 i_hostuser, i_hostPasswd)
        self.util = OpTestUtil()
        self.user = i_hostuser
        self.ip = i_hostip
        self.passwd = i_hostPasswd


    ##
    # @brief This function just brings the system to host OS.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_system_reboot(self):
        print "Testing FWTS: Booting system to OS"
        print "Performing a IPMI Power OFF Operation"
        # Perform a IPMI Power OFF Operation(Immediate Shutdown)
        self.cv_IPMI.ipmi_power_off()
        if int(self.cv_SYSTEM.sys_wait_for_standby_state(BMC_CONST.SYSTEM_STANDBY_STATE_DELAY)) == BMC_CONST.FW_SUCCESS:
            print "System is in standby/Soft-off state"
        else:
            l_msg = "System failed to reach standby/Soft-off state"
            raise OpTestError(l_msg)

        self.cv_IPMI.ipmi_power_on()
        self.cv_SYSTEM.sys_check_host_status()
        self.util.PingFunc(self.cv_HOST.ip, BMC_CONST.PING_RETRY_POWERCYCLE)
        self.cv_IPMI.clear_ssh_keys(self.cv_HOST.ip)

        print "Gathering the OPAL msg logs"
        self.cv_HOST.host_gather_opal_msg_log()
        return BMC_CONST.FW_SUCCESS

    ##
    # @brief This function just executes the fwts_execution.sh on host OS
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_fwts(self):
        l_oslevel = self.cv_HOST.host_get_OS_Level()
        if not "Ubuntu" in l_oslevel:
            return
        # Copy the fwts execution file to the tmp folder in the host
        base_path = (os.path.dirname(os.path.abspath(__file__))).split('testcases')[0]
        fwts_script = base_path + "/testcases/fwts_execution.sh"
        try:
            self.util.copyFilesToDest(fwts_script, self.user,
                                             self.ip, "/tmp/", self.passwd)
        except:
            l_msg = "Copying fwts file to host failed"
            print l_msg
            raise OpTestError(l_msg)

        l_res = self.cv_HOST.host_run_command("/tmp/fwts_execution.sh")
        print l_res
Exemplo n.º 47
0
class OpTestInbandUsbInterface():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the host
    # @param i_hostUser The userid to log into the host
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostIP=None,
                 i_hostUser=None,
                 i_hostPasswd=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir)
        self.cv_HOST = OpTestHost(i_hostIP, i_hostUser, i_hostPasswd, i_bmcIP)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostIP, i_hostUser,
                                      i_hostPasswd)
        self.util = OpTestUtil()

    ##
    # @brief This function will cover following test steps
    #        1. It will get the OS level installed on powernv platform
    #        2. It will check for kernel version installed on the Open Power Machine
    #        3. It will check for ipmitool command existence and ipmitool package
    #        4. Checking Inband ipmitool command functionality with different options
    #           using ipmitool usb interface.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_ipmi_inband_usb_interface(self):
        self.cv_SYSTEM.sys_bmc_power_on_validate_host()
        # Get OS level
        l_oslevel = self.cv_HOST.host_get_OS_Level()

        # Get kernel version
        l_kernel = self.cv_HOST.host_get_kernel_version()

        # Checking for ipmitool command and lm_sensors package
        self.cv_HOST.host_check_command("ipmitool")

        l_pkg = self.cv_HOST.host_check_pkg_for_utility(l_oslevel, "ipmitool")
        print "Installed package: %s" % l_pkg

        # loading below ipmi modules based on config option
        # ipmi_devintf, ipmi_powernv and ipmi_masghandler
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_DEVICE_INTERFACE,
            BMC_CONST.IPMI_DEV_INTF)
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_POWERNV, BMC_CONST.IPMI_POWERNV)
        self.cv_HOST.host_load_module_based_on_config(
            l_kernel, BMC_CONST.CONFIG_IPMI_HANDLER,
            BMC_CONST.IPMI_MSG_HANDLER)

        fail_count = 0
        test_cases = [
            self.test_chassis, self.test_chassis_identifytests,
            self.test_chassis_bootdev, self.test_channel, self.test_Info,
            self.test_sdr_list_by_type, self.test_sdr_elist_by_type,
            self.test_sdr_type_list, self.test_sdr_get_id, self.test_fru_print,
            self.test_fru_read, self.test_sel_info, self.test_sel_list,
            self.test_sel_elist, self.test_sel_time_get,
            self.test_sel_set_time, self.test_sel_list_first_3_entries,
            self.test_sel_list_last_3_entries, self.test_sel_get_functionality,
            self.test_sel_clear_functionality, self.test_mc,
            self.test_sensor_list, self.test_sensor_get_host_status,
            self.test_sensor_get_os_boot, self.test_sensor_get_occ_active,
            self.test_dcmi, self.test_echo, self.test_event,
            self.test_firewall, self.test_pef, self.test_raw, self.test_exec
        ]

        for test in test_cases:
            try:
                print "In-band IPMI[USB]: test case %s" % test
                test(self)
            except:
                print "Test Fail: %s failed" % test
                fail_count += 1
                print sys.exc_info()
                continue

        print "Inband IPMI[USB]: Test case failure count %s" % fail_count

    ##
    # @brief  It will execute and test the return code of ipmi command.
    #
    # @param i_cmd @type string:The ipmitool command, for example: ipmitool -I usb chassis status; echo $?
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def run_ipmi_cmd_on_host(self, i_cmd):
        l_cmd = i_cmd
        print l_cmd
        l_res = self.cv_HOST.host_run_command(l_cmd)
        l_res = l_res.splitlines()
        if int(l_res[-1]):
            l_msg = "IPMI: command failed %c" % l_cmd
            raise OpTestError(l_msg)
        return l_res

    ##
    # @brief  It will execute and test the ipmitool -I usb chassis <cmd> commands
    #         cmd: status, poh, restart_cause, policy list and policy set
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassis(self):
        print "Inband IPMI[USB]: Chassis tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_POH)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_RESTART_CAUSE)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_POLICY_LIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_POLICY_ALWAYS_OFF)

    ##
    # @brief  It will execute and test the ipmi chassis identify commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_chassis_identifytests(self):
        print "Inband IPMI[USB]: Chassis Identify tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_IDENTIFY_5)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_IDENTIFY)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_IDENTIFY_FORCE)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_IDENTIFY)

    ##
    # @brief  It will execute and test the functionality of ipmi chassis bootdev <dev>
    #         dev: none,pxe,cdrom,disk,bios,safe,diag,floppy and none.
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    @staticmethod
    def test_chassis_bootdev(self):
        print "Inband IPMI[USB]: Chassis Bootdevice tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_PXE)
        self.verify_bootdev("pxe")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_CDROM)
        self.verify_bootdev("cdrom")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_DISK)
        self.verify_bootdev("disk")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_BIOS)
        self.verify_bootdev("bios")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_SAFE)
        self.verify_bootdev("safe")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_DIAG)
        self.verify_bootdev("diag")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_FLOPPY)
        self.verify_bootdev("floppy")
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHASSIS_BOOTDEV_NONE)
        self.verify_bootdev("none")

    ##
    # @brief  It will verify whether setting of given bootdevice is honoured or not
    #         by reading chassis bootparam get 5
    #
    # @param i_dev @type string: boot device name: Ex safe, disk and cdrom
    #
    # @return BMC_CONST.FW_SUCCESS on success or raise OpTestError
    #
    def verify_bootdev(self, i_dev):
        l_res = self.run_ipmi_cmd_on_host(
            BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHASSIS_BOOTPARAM_GET_5)
        if i_dev == "safe":
            l_msg = "Force Boot from default Hard-Drive, request Safe-Mode"
        elif i_dev == "disk":
            l_msg = "Force Boot from default Hard-Drive"
        elif i_dev == "diag":
            l_msg = "Force Boot from Diagnostic Partition"
        elif i_dev == "bios":
            l_msg = "Force Boot into BIOS Setup"
        elif i_dev == "pxe":
            l_msg = "Force PXE"
        elif i_dev == "cdrom":
            l_msg = "Force Boot from CD/DVD"
        elif i_dev == "none":
            l_msg = "No override"
        elif i_dev == "floppy":
            l_msg = "Force Boot from Floppy/primary removable media"
        else:
            print "pass proper bootdevice"

        for l_line in l_res:
            if l_line.__contains__(l_msg):
                print "Verifying bootdev is successfull for %s" % i_dev
                return BMC_CONST.FW_SUCCESS
        else:
            l_msg = "Boot device is not set to %s" % i_dev
            raise OpTestError(l_msg)

    ##
    # @brief  It will check basic channel functionalities: info and authentication capabilities.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_channel(self):
        print "Inband IPMI[USB]: Channel tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHANNEL_AUTHCAP)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_CHANNEL_INFO)

    ##
    # @brief  It will execute and test the ipmi <sdr/sel/mc/channel> info related commands.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_Info(self):
        print "Inband IPMI[USB]: Info tests"
        #self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_CHANNEL_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SEL_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_INFO)

    ##
    # @brief  It will execute and test the ipmi sdr list <all/fru/event/mcloc/compact/full/generic>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_list_by_type(self):
        print "Inband IPMI[USB]: SDR list tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_ALL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_FRU)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_EVENT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_MCLOC)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_COMPACT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_FULL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_LIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr elist <all/fru/event/mcloc/compact/full/generic>
    #         commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_elist_by_type(self):
        print "Inband IPMI[USB]: SDR elist tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_ALL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_FRU)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_EVENT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_MCLOC)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_COMPACT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_FULL)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_ELIST_GENERIC)

    ##
    # @brief  It will execute and test the ipmi sdr type <Temp/fan/Powersupply> commands
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_type_list(self):
        print "Inband IPMI[USB]: SDR type list tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_TYPE_LIST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_TYPE_TEMPERATURE)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_TYPE_FAN)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SDR_TYPE_POWER_SUPPLY)

    ##
    # @brief  It will execute and test the ipmi sdr get <sensor-id> command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sdr_get_id(self):
        print "Inband IPMI[USB]: SDR get tests"
        l_cmd = BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_SDR_GET_WATCHDOG + "; echo $?"
        self.run_ipmi_cmd_on_host(l_cmd)

    ##
    # @brief  It will execute and test the ipmi fru print command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_print(self):
        print "Inband IPMI[USB]: FRU Print Test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_FRU_PRINT)

    ##
    # @brief  It will execute and test the ipmi fru read command.
    #         then the output file is displayed by hexdump
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_fru_read(self):
        print "Inband IPMI[USB]: FRU Read Test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  "fru read 0 /tmp/file_fru; echo $?")
        l_res = self.cv_HOST.host_run_command(
            "hexdump -C /tmp/file_fru; echo $?")
        # TODO: Check for file output

    ##
    # @brief  It will execute and test the management controller(mc) commands functionality
    #         info-Displays information about the BMC hardware, including device revision,
    #              firmware revision, IPMI version supported, manufacturer ID,  and  information
    #               on additional device support
    #         watchdog get-Show current Watchdog Timer settings and countdown state.
    #         watchdog off-Turn off a currently running Watchdog countdown timer.
    #         watchdog reset-Reset the Watchdog Timer to its most recent state and restart the countdown timer.
    #         selftest- Check on the basic health of the BMC by executing the
    #                   Get Self Test results command and report the results.
    #         setenables-Enables  or disables the given option
    #         getenables-Displays a list of the currently enabled options for the BMC.
    #         getsysinfo-Retrieves system info from bmc for given argument
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_mc(self):
        print "Inband IPMI[USB]: MC tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_WATCHDOG_GET)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_SELFTEST)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_SETENABLES_OEM_0_OFF)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_SETENABLES_OEM_0_ON)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_GETENABLES)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_WATCHDOG_OFF)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_WATCHDOG_RESET)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_MC_GETSYS_INFO)

    ##
    # @brief  It will execute and test the ipmi sel info functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_info(self):
        print "Inband IPMI[USB]: SEL Info test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SEL_INFO)

    ##
    # @brief  It will execute and test ipmi sel list functionality.
    #         the entire contents of the System Event Log are displayed.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list(self):
        print "Inband IPMI[USB]: SEL List test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SEL_LIST)

    ##
    # @brief  It will execute and test the ipmi sel elist functionality
    #         If invoked as elist (extended list) it will also use the
    #         Sensor Data Record entries to display the sensor ID for
    #           the sensor that caused each event.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_elist(self):
        print "Inband IPMI[USB]: SEL elist test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SEL_ELIST)

    ##
    # @brief  It will execute and test the ipmi sel time get functionality
    #         Displays the SEL clock's current time.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_time_get(self):
        print "Inband IPMI[USB]: SEL Time get test"
        l_res = self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                          BMC_CONST.IPMI_SEL_TIME_GET)
        return l_res

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @param i_time @type string: the value to be set as a sel time
    #               <time string> is of the form "MM/DD/YYYY HH:MM:SS"
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_time_set(self, i_time):
        print "Inband IPMI[USB]: SEL Time set test"
        l_cmd = "sel time set \'%s\'; echo $?" % i_time
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list first <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_first_n_entries(self, i_num):
        l_cmd = "sel list first %i; echo $?" % int(i_num)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel list last <n entries>
    #
    # @param i_num @type string:The num of entries of sel to be listed
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_list_last_n_entries(self, i_num):
        l_cmd = "sel list last %i; echo $?" % int(i_num)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @param i_sel_id @type string: for example 0x05, 0x06..
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sel_get_byid(self, i_sel_id):
        l_cmd = "sel get %s; echo $?" % i_sel_id
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + l_cmd)

    ##
    # @brief  It will execute the ipmi sel clear command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_clear(self):
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SEL_CLEAR)

    ##
    # @brief  It will execute and test the ipmi sel get <id> functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_get_functionality(self):
        l_res = self.cv_HOST.host_run_command(
            BMC_CONST.IPMITOOL_USB + "sel list first 3 | awk '{print $1}'")
        if l_res.__contains__("SEL has no entries"):
            print "IPMI: There are no sel entries to fetch"
            pass
        else:
            l_list = l_res.splitlines()
            del l_list[0]
            for l in l_list:
                l_id = "0x" + l
                self.test_sel_get_byid(l_id)

    ##
    # @brief  It will execute and test the ipmi sel clear functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_clear_functionality(self):
        self.test_sel_clear(self)
        l_res = self.cv_HOST.host_run_command(
            "ipmitool -I usb sel list; echo $?")
        l_list = l_res.splitlines()
        for l_line in l_list:
            if l_line.__contains__("SEL has no entries"):
                print "Sel clear function got cleared event entries"
                break
        else:
            l_msg = "Inband IPMI[USB]: sel clear function failing in clearing entries"
            print l_msg
            raise OpTestError(l_msg)

    ##
    # @brief  It will execute and test the ipmi sensor list functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_list(self):
        print "Inband IPMI[USB]: Sensor tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_SENSOR_LIST)

    ##
    # @brief  It will execute and test the ipmi sensor get <id> functionality
    #
    # @param i_sensor @type string:sensor id to retrieve the data
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    def test_sensor_byid(self, i_sensor):
        l_cmd = BMC_CONST.IPMITOOL_USB + "sensor get \"%s\"; echo $?" % i_sensor
        self.run_ipmi_cmd_on_host(l_cmd)

    ##
    # @brief  It will execute and test the dcmi related ipmi commands.
    #         discover-This command is used to discover supported capabilities in DCMI
    #         Power reading-Get power related readings from the system.
    #               get_limit-Get the configured power limits.
    #         sensors-Prints the available DCMI sensors.
    #         get_mc_id_string-Get management controller identifier string
    #         get_temp_reading-Get Temperature Sensor Readings.
    #         get_conf_param-Get DCMI Configuration Parameters.
    #         oob_discover-Ping/Pong Message for DCMI Discovery
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_dcmi(self):
        print "Inband IPMI[USB]: dcmi tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_DCMI_DISCOVER)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_DCMI_POWER_READING)
        #self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_DCMI_POWER_GET_LIMIT)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_DCMI_SENSORS)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_DCMI_GET_MC_ID_STRING)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_DCMI_GET_TEMP_READING)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_DCMI_GET_CONF_PARAM)

    ##
    # @brief  It will execute and test the functionality of ipmi echo command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_echo(self):
        print "Inband IPMI[USB]: echo tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_ECHO_DONE)

    ##
    # @brief  It will execute and test event related commands to test sel functionality.
    #         Send a pre-defined test event to the System Event Log.  The following
    #         events are included as a means to test the functionality of  the  System
    #         Event Log component of the BMC (an entry will be added each time the
    #         event N command is executed)
    #         Currently supported values for N are:
    #         1    Temperature: Upper Critical: Going High
    #         2    Voltage Threshold: Lower Critical: Going Low
    #         3    Memory: Correctable ECC
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_event(self):
        print "Inband IPMI[USB]: event tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_EVENT_1)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_EVENT_2)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_EVENT_3)

    ##
    # @brief  It will execute and test ipmi exec command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_exec(self):
        print "Inband IPMI[USB]: exec tests"
        pass
        # TODO: need to execute ipmi commands from a file

    ##
    # @brief  It will execute and test firmware firewall info command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_firewall(self):
        print "Inband IPMI[USB]: Firewall test"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_FIREWALL_INFO)

    ##
    # @brief  It will execute and test pef related commands:
    #         info:This command will query the BMC and print information about the PEF supported features.
    #         status: This command prints the current PEF status
    #         policy: This command lists the PEF policy table entries
    #         list: This  command  lists  the PEF table entries.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_pef(self):
        print "Inband IPMI[USB]: Pef tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_PEF_INFO)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_PEF_STATUS)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_PEF_POLICY)
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_PEF_LIST)

    ##
    # @brief This will test raw IPMI commands. For example to query the POH counter with a raw command
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_raw(self):
        print "Inband IPMI[USB]: raw command execution tests"
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB +
                                  BMC_CONST.IPMI_RAW_POH)

    ##
    # @brief  It will execute and test the ipmi sel set <time string> functionality
    #         Sets the SEL clock.  Future SEL entries will use the time set by this command.
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_set_time(self):
        l_res = self.test_sel_time_get(self)
        self.test_sel_time_set(l_res[-2])

    ##
    # @brief  It will execute and test the ipmi sel list first <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_first_3_entries(self):
        self.test_sel_list_first_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)

    ##
    # @brief  It will execute and test the ipmi sel list last <3 entries>
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sel_list_last_3_entries(self):
        self.test_sel_list_last_n_entries(BMC_CONST.IPMI_SEL_LIST_ENTRIES)

    ##
    # @brief  It will execute and test the ipmi sensor get "Host Status" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_host_status(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_HOST_STATUS)

    ##
    # @brief  It will execute and test the ipmi sensor get "OS Boot" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_os_boot(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OS_BOOT)

    ##
    # @brief  It will execute and test the ipmi sensor get "OCC Active" functionality
    #
    # @return l_res @type list: output of command or raise OpTestError
    #
    @staticmethod
    def test_sensor_get_occ_active(self):
        self.test_sensor_byid(BMC_CONST.SENSOR_OCC_ACTIVE)
Exemplo n.º 48
0

def _config_read():
    """ returns bmc system and test config options """
    bmcConfig = ConfigParser.RawConfigParser()
    configFile = os.path.join(os.path.dirname(__file__), 'op_ci_tools.cfg')
    bmcConfig.read(configFile)
    return dict(bmcConfig.items('bmc')), dict(bmcConfig.items('test'))

''' Read the configuration settings into global space so they can be used by
    other functions '''

bmcCfg, testCfg = _config_read()
opTestSys = OpTestSystem(bmcCfg['ip'],bmcCfg['username'],
                         bmcCfg['password'],
                         bmcCfg['usernameipmi'],
                         bmcCfg['passwordipmi'],
                         testCfg['ffdcdir'])


def test_init():
    """This function validates the test config before running other functions
    """

    ''' create FFDC dir if it does not exist '''
    ffdcDir = testCfg['ffdcdir']
    if not os.path.exists(os.path.dirname(ffdcDir)):
        os.makedirs(os.path.dirname(ffdcDir))

    ''' make sure PNOR image exists '''
    pnorImg = testCfg['imagedir'] + testCfg['imagename']
Exemplo n.º 49
0
class OpTestPCI():
    ##  Initialize this object
    #  @param i_bmcIP The IP address of the BMC
    #  @param i_bmcUser The userid to log into the BMC with
    #  @param i_bmcPasswd The password of the userid to log into the BMC with
    #  @param i_bmcUserIpmi The userid to issue the BMC IPMI commands with
    #  @param i_bmcPasswdIpmi The password of BMC IPMI userid
    #  @param i_ffdcDir Optional param to indicate where to write FFDC
    #
    # "Only required for inband tests" else Default = None
    # @param i_hostIP The IP address of the HOST
    # @param i_hostuser The userid to log into the HOST
    # @param i_hostPasswd The password of the userid to log into the HOST with
    #
    def __init__(self,
                 i_bmcIP,
                 i_bmcUser,
                 i_bmcPasswd,
                 i_bmcUserIpmi,
                 i_bmcPasswdIpmi,
                 i_ffdcDir=None,
                 i_hostip=None,
                 i_hostuser=None,
                 i_hostPasswd=None,
                 i_hostLspci=None):
        self.cv_BMC = OpTestBMC(i_bmcIP, i_bmcUser, i_bmcPasswd, i_ffdcDir)
        self.cv_IPMI = OpTestIPMI(i_bmcIP, i_bmcUserIpmi, i_bmcPasswdIpmi,
                                  i_ffdcDir, i_hostip, i_hostuser,
                                  i_hostPasswd)
        self.cv_HOST = OpTestHost(i_hostip, i_hostuser, i_hostPasswd, i_bmcIP,
                                  i_ffdcDir)
        self.cv_SYSTEM = OpTestSystem(i_bmcIP, i_bmcUser, i_bmcPasswd,
                                      i_bmcUserIpmi, i_bmcPasswdIpmi,
                                      i_ffdcDir, i_hostip, i_hostuser,
                                      i_hostPasswd)
        self.util = OpTestUtil()
        self.lspci_file = i_hostLspci

    ##
    # @brief  This function will get the PCI and USB susbsytem Info
    #         And also this test compares known good data of
    #         "lspci -mm -n" which is stored in testcases/data directory
    #         with the current lspci data.
    #         User need to specify the corresponding file name into
    #         machines xml like lspci.txt which contains "lspci -mm -n"
    #         command output in a working good state of system.
    #         tools used are lspci and lsusb
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_host_pci_devices_info(self):
        if self.lspci_file == "empty.txt":
            print "Skipping the pci devices comparision as missing the lspci data file name in machines xml"
            return BMC_CONST.FW_SUCCESS
        filename = os.path.join(
            os.path.dirname(__file__).split('testcases')[0], self.lspci_file)
        if not os.path.isfile(filename):
            raise OpTestError(
                "lspci file %s not found in top level directory" % filename)
        self.pci_good_data_file = filename
        self.test_skiroot_pci_devices()
        self.cv_IPMI.ipmi_set_boot_to_disk()
        self.cv_IPMI.ipmi_power_off()
        self.cv_IPMI.ipmi_power_on()
        self.cv_IPMI.ipl_wait_for_working_state()
        self.test_host_pci_devices()

    ##
    # @brief  This function will get the "lspci -mm -n" output from the petitboot
    #         and compares it with known good lspci data
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_skiroot_pci_devices(self):
        cmd = "lspci -mm -n"
        self.console = self.cv_SYSTEM.sys_get_ipmi_console()
        self.cv_SYSTEM.sys_ipmi_boot_system_to_petitboot(self.console)
        self.cv_IPMI.ipmi_host_set_unique_prompt(self.console)
        self.cv_IPMI.run_host_cmd_on_ipmi_console("uname -a")
        self.cv_IPMI.run_host_cmd_on_ipmi_console("cat /etc/os-release")
        res = self.cv_IPMI.run_host_cmd_on_ipmi_console(cmd)
        self.cv_SYSTEM.sys_ipmi_close_console(self.console)
        self.pci_data_petitboot = '\n'.join(res[1:])
        diff_process = subprocess.Popen(
            ['diff', "-u", self.pci_good_data_file, "-"],
            stdin=subprocess.PIPE)
        diff_stdout, diff_stderr = diff_process.communicate(
            self.pci_data_petitboot + '\n')
        r = diff_process.wait()
        if r == 0:
            print "All the pci devices are detected at petitboot"
        else:
            print diff_stdout
            raise OpTestError(
                "There is a mismatch b/w known good output and tested petitboot lspci output"
            )

    ##
    # @brief  This function will get the "lspci -mm -n" output from the host OS
    #         and compares it with known good lspci data
    #
    # @return BMC_CONST.FW_SUCCESS or BMC_CONST.FW_FAILED
    #
    def test_host_pci_devices(self):
        self.cv_HOST.host_check_command("lspci", "lsusb")
        self.cv_HOST.host_list_pci_devices()
        self.cv_HOST.host_get_pci_verbose_info()
        self.cv_HOST.host_list_usb_devices()
        l_res = self.cv_HOST.host_run_command("lspci -mm -n")
        self.pci_data_hostos = l_res.replace("\r\n", "\n")
        diff_process = subprocess.Popen(
            ['diff', "-u", self.pci_good_data_file, "-"],
            stdin=subprocess.PIPE)
        diff_stdout, diff_stderr = diff_process.communicate(
            self.pci_data_hostos)
        r = diff_process.wait()
        if r == 0:
            print "All the pci devices are detected in host OS"
        else:
            print diff_stdout
            raise OpTestError(
                "There is a mismatch b/w known good output and tested host OS lspci output"
            )