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)
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.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):
         # 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)
        print "Inband IPMI[USB]: Chassis tests"
        self.test_chassis()
        print "Inband IPMI[USB]: Chassis Identify tests"
        self.test_chassis_identifytests()
        print "Inband IPMI[USB]: Chassis Bootdevice tests"
        self.test_chassis_bootdev()
        print "Inband IPMI[USB]: Channel tests"
        #self.test_channel()
        print "Inband IPMI[USB]: Info tests"
        self.test_Info()
        print "Inband IPMI[USB]: SDR list tests"
        self.test_sdr_list_by_type()
        print "Inband IPMI[USB]: SDR elist tests"
        self.test_sdr_elist_by_type()
        print "Inband IPMI[USB]: SDR type list tests"
        self.test_sdr_type_list()
        print "Inband IPMI[USB]: SDR get tests"
        self.test_sdr_get_id()
        print "Inband IPMI[USB]: FRU Tests"
        self.test_fru_print()
        self.test_fru_read()
        print "Inband IPMI[USB]: SEL tests"
        self.test_sel_info()
        self.test_sel_list()
        self.test_sel_elist()
        l_res = self.test_sel_time_get()
        self.test_sel_time_set(l_res[-2])
        i_num = "3"
        self.test_sel_list_first_n_entries(i_num)
        self.test_sel_list_last_n_entries(i_num)
        self.test_sel_get_functionality()
        self.test_sel_clear_functionality()
        print "Inband IPMI[USB]: MC tests"
        self.test_mc()
        print "Inband IPMI[USB]: Sensor tests"
        self.test_sensor_list()
        self.test_sensor_byid("Host Status")
        self.test_sensor_byid("OS Boot")
        self.test_sensor_byid("OCC Active")
        print "Inband IPMI[USB]: dcmi tests"
        self.test_dcmi()
        print "Inband IPMI[USB]: echo tests"
        self.test_echo()
        print "Inband IPMI[USB]: event tests"
        self.test_event()
        print "Inband IPMI[USB]: Firewall test"
        self.test_firewall()
        print "Inband IPMI[USB]: Pef tests"
        self.test_pef()
        print "Inband IPMI[USB]: raw command execution tests"
        self.test_raw()
        print "Inband IPMI[USB]: exec tests"
        self.test_exec()

    ##
    # @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
    #
    def test_chassis(self):
        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
    #
    def test_chassis_identifytests(self):
        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
    #
    def test_chassis_bootdev(self):
        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
    #
    def test_channel(self):
        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
    #
    def test_Info(self):
        #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
    #
    def test_sdr_list_by_type(self):
        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
    #
    def test_sdr_elist_by_type(self):
        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
    #
    def test_sdr_type_list(self):
        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
    #
    def test_sdr_get_id(self):
        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
    #
    def test_fru_print(self):
        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
    #
    def test_fru_read(self):
        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
    #
    def test_mc(self):
        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
    #
    def test_sel_info(self):
        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
    #
    def test_sel_list(self):
        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
    #
    def test_sel_elist(self):
        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
    #
    def test_sel_time_get(self):
        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):
        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
    #
    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
    #
    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
    #
    def test_sel_clear_functionality(self):
        self.test_sel_clear()
        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
    #
    def test_sensor_list(self):
        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
    #
    def test_dcmi(self):
        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
    #
    def test_echo(self):
        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
    #
    def test_event(self):
        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
    #
    def test_exec(self):
        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
    #
    def test_firewall(self):
        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
    #
    def test_pef(self):
        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
    #
    def test_raw(self):
        self.run_ipmi_cmd_on_host(BMC_CONST.IPMITOOL_USB + BMC_CONST.IPMI_RAW_POH)
class OpTestInbandIPMI():
    ##  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.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.
    #
    # @return BMC_CONST.FW_SUCCESS or raise OpTestError
    #
    def test_ipmi_inband_functionality(self):

        # 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


        # Checking Inband ipmitool command functionality with different options
        l_cmd = "ipmitool sdr; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool sdr not working,exiting...."
            raise OpTestError(l_msg)

        l_cmd = "ipmitool sdr elist full; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool sdr elist full not working,exiting...."
            raise OpTestError(l_msg)

        l_cmd = "ipmitool sdr type temperature; echo $?"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        if l_res.__contains__("Temp"):
            print "ipmitool sdr type temperature is working"
        else:
            l_msg = "ipmitool sdr type temperature is not working"
            raise OpTestError(l_msg)


        l_cmd = "ipmitool lan print 1; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool lan print command is not working,exiting...."
            raise OpTestError(l_msg)


        l_cmd = "ipmitool fru print; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool fru print is not working,exiting...."
            raise OpTestError(l_msg)


        l_cmd = "ipmitool chassis status | grep \"System Power\""
        l_res = self.cv_HOST.host_run_command(l_cmd)
        if l_res.__contains__("System Power         : on"):
            print "ipmitool Chassis status is working"
        else:
            l_msg = "ipmitool chassis status is not working"
            raise OpTestError(l_msg)

        l_cmd = "ipmitool chassis identify 1; echo $?"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        if l_res.__contains__("Chassis identify interval: 1 seconds"):
            print "ipmitool Chassis identify interval is working"
        else:
            l_msg = "ipmitool Chassis identify interval is not working,exiting...."
            raise OpTestError(l_msg)

        l_cmd = "ipmitool chassis identify force; echo $?"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        if l_res.__contains__("Chassis identify interval: indefinite"):
            print "ipmitool Chassis identify interval is working"
        else:
            l_msg = "ipmitool Chassis identify interval is not working"
            raise OpTestError(l_msg)


        l_cmd = "ipmitool sensor list; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool sensor list is not working,exiting...."
            raise OpTestError(l_msg)


        l_cmd = "ipmitool mc info; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool mc info is not working,exiting...."
            raise OpTestError(l_msg)

        l_cmd = "ipmitool mc selftest; echo $?"
        l_res = self.cv_HOST.host_run_command(l_cmd)
        if l_res.__contains__("Selftest: passed"):
            print "ipmitool mc selftest is passed"
        else:
            l_msg = "ipmitool mc selftest is failing"
            raise OpTestError(l_msg)

        l_cmd = "ipmitool mc getenables; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool mc getenables is not working,exiting...."
            raise OpTestError(l_msg)

        l_cmd = "ipmitool mc watchdog get; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool mc watchdog get is not working,exiting...."
            raise OpTestError(l_msg)



        l_cmd = "ipmitool sel info; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool sel info is not working,exiting...."
            raise OpTestError(l_msg)

        l_cmd = "ipmitool sel list; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool sel list is not working,exiting...."
            raise OpTestError(l_msg)


        l_cmd = "ipmitool sel list last 3 | grep \"PCI resource configuration\" | awk \'{ print $1 }\'"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        l_cmd = "ipmitool sel get 0x" + response[1] + "; echo $?"
        output = self.cv_HOST.host_run_command(l_cmd)
        response = output.splitlines()
        if int(response[-1]):
            l_msg = "ipmitool sel get is not working,exiting...."
            raise OpTestError(l_msg)
        
        return BMC_CONST.FW_SUCCESS
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)
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
Exemple #6
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)
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.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):

        # 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 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)
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)