xref: /openbmc/openbmc-test-automation/lib/ipmi_client.robot (revision 409df05d4b10b9a8c81e282da8fef0199db5bdea)
1b29d2e84SChris Austen*** Settings ***
2b29d2e84SChris AustenDocumentation   This module is for IPMI client for copying ipmitool to
3a2dab3c8SSivas SRR...             openbmc box and execute ipmitool IPMI standard
4a2dab3c8SSivas SRR...             command. IPMI raw command will use dbus-send command
5839a0c27SSandhya SomashekarResource        ../lib/resource.robot
64d6c1dabSGeorge KeishingResource        ../lib/connection_client.robot
7ae7c2281SPrashanth KattiResource        ../lib/utils.robot
8ae7c2281SPrashanth KattiResource        ../lib/state_manager.robot
9ae7c2281SPrashanth Katti
10a2dab3c8SSivas SRRLibrary         String
1134c79af0SMichael WalshLibrary         var_funcs.py
1219621bacSMichael WalshLibrary         ipmi_client.py
13b9a29a6bSleetLibrary         ../lib/bmc_ssh_utils.py
14a2dab3c8SSivas SRR
15a2dab3c8SSivas SRR*** Variables ***
16d7f11f70SGeorge Keishing${dbusHostIpmicmd1}=   dbus-send --system  ${OPENBMC_BASE_URI}HostIpmi/1
17d7f11f70SGeorge Keishing${dbusHostIpmiCmdReceivedMsg}=   ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage
18a2dab3c8SSivas SRR${netfnByte}=          ${EMPTY}
19a2dab3c8SSivas SRR${cmdByte}=            ${EMPTY}
20a2dab3c8SSivas SRR${arrayByte}=          array:byte:
21a7913898SMichael Walsh${IPMI_USER_OPTIONS}   ${EMPTY}
2275f55dc7SGeorge Keishing${IPMI_INBAND_CMD}=    ipmitool -C ${IPMI_CIPHER_LEVEL} -N ${IPMI_TIMEOUT} -p ${IPMI_PORT}
237a212a09SRahul Maheshwari${HOST}=               -H
247a212a09SRahul Maheshwari${RAW}=                raw
25b9a29a6bSleet${IPMITOOL_PATH}       /tmp/ipmitool
269e4481b8SRuud A. Haring${expected_max_ids}    15
279e4481b8SRuud A. Haring${empty_name_pattern}  ^User Name\\s.*\\s:\\s$
28b29d2e84SChris Austen
29b29d2e84SChris Austen*** Keywords ***
307a212a09SRahul Maheshwari
31b29d2e84SChris AustenRun IPMI Command
323ef2e92cSMichael Walsh    [Documentation]  Run the raw IPMI command.
333ef2e92cSMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  &{options}
343ef2e92cSMichael Walsh
353ef2e92cSMichael Walsh    # Description of argument(s):
363ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
373ef2e92cSMichael Walsh    #                               (e.g. "power status").
383ef2e92cSMichael Walsh    # fail_on_err                   Fail if the IPMI command execution fails.
393ef2e92cSMichael Walsh    # options                       Additional ipmitool command options (e.g.
403ef2e92cSMichael Walsh    #                               -C=3, -I=lanplus, etc.).  Currently, only
413ef2e92cSMichael Walsh    #                               used for external IPMI commands.
423ef2e92cSMichael Walsh
437a212a09SRahul Maheshwari    ${resp}=  Run Keyword If  '${IPMI_COMMAND}' == 'External'
443ef2e92cSMichael Walsh    ...    Run External IPMI Raw Command  ${command}  ${fail_on_err}  &{options}
45ae7c2281SPrashanth Katti    ...  ELSE IF  '${IPMI_COMMAND}' == 'Inband'
463ef2e92cSMichael Walsh    ...    Run Inband IPMI Raw Command  ${command}
477a212a09SRahul Maheshwari    ...  ELSE IF  '${IPMI_COMMAND}' == 'Dbus'
483ef2e92cSMichael Walsh    ...    Run Dbus IPMI RAW Command  ${command}
49ae7c2281SPrashanth Katti    ...  ELSE  Fail  msg=Invalid IPMI Command type provided: ${IPMI_COMMAND}
50*409df05dSGeorge Keishing    RETURN  ${resp}
517a212a09SRahul Maheshwari
523ef2e92cSMichael Walsh
537a212a09SRahul MaheshwariRun IPMI Standard Command
54f4a807bfSJoy Onyerikwu    [Documentation]  Run the standard IPMI command.
55d0e58e73SMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  ${expected_rc}=${0}  &{options}
5620f3bf73SRahul Maheshwari
5720f3bf73SRahul Maheshwari    # Description of argument(s):
583ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
593ef2e92cSMichael Walsh    #                               (e.g. "0x06 0x36").
603ef2e92cSMichael Walsh    # fail_on_err                   Fail if the IPMI command execution fails.
61d0e58e73SMichael Walsh    # expected_rc                   The expected return code from the ipmi
62d0e58e73SMichael Walsh    #                               command (e.g. ${0}, ${1}, etc.).
633ef2e92cSMichael Walsh    # options                       Additional ipmitool command options (e.g.
643ef2e92cSMichael Walsh    #                               -C=3, -I=lanplus, etc.).  Currently, only
653ef2e92cSMichael Walsh    #                               used for external IPMI commands.
6620f3bf73SRahul Maheshwari
677a212a09SRahul Maheshwari    ${resp}=  Run Keyword If  '${IPMI_COMMAND}' == 'External'
68d0e58e73SMichael Walsh    ...    Run External IPMI Standard Command  ${command}  ${fail_on_err}  ${expected_rc}  &{options}
69ae7c2281SPrashanth Katti    ...  ELSE IF  '${IPMI_COMMAND}' == 'Inband'
703ef2e92cSMichael Walsh    ...    Run Inband IPMI Standard Command  ${command}  ${fail_on_err}
717a212a09SRahul Maheshwari    ...  ELSE IF  '${IPMI_COMMAND}' == 'Dbus'
723ef2e92cSMichael Walsh    ...    Run Dbus IPMI Standard Command  ${command}
73ae7c2281SPrashanth Katti    ...  ELSE  Fail  msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
74*409df05dSGeorge Keishing    RETURN  ${resp}
757a212a09SRahul Maheshwari
763ef2e92cSMichael Walsh
777a212a09SRahul MaheshwariRun Dbus IPMI RAW Command
78f4a807bfSJoy Onyerikwu    [Documentation]  Run the raw IPMI command through dbus.
793ef2e92cSMichael Walsh    [Arguments]    ${command}
803ef2e92cSMichael Walsh    ${valueinBytes}=   Byte Conversion  ${command}
81a2dab3c8SSivas SRR    ${cmd}=   Catenate   ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
82a2dab3c8SSivas SRR    ${cmd}=   Catenate   ${cmd} ${valueinBytes}
83a2dab3c8SSivas SRR    ${output}   ${stderr}=  Execute Command  ${cmd}  return_stderr=True
84b29d2e84SChris Austen    Should Be Empty      ${stderr}
85b29d2e84SChris Austen    set test variable    ${OUTPUT}     "${output}"
86b29d2e84SChris Austen
873ef2e92cSMichael Walsh
887a212a09SRahul MaheshwariRun Dbus IPMI Standard Command
89f4a807bfSJoy Onyerikwu    [Documentation]  Run the standard IPMI command through dbus.
903ef2e92cSMichael Walsh    [Arguments]    ${command}
914d6c1dabSGeorge Keishing    Copy ipmitool
927a212a09SRahul Maheshwari    ${stdout}    ${stderr}    ${output}=  Execute Command
93b9a29a6bSleet    ...    ${IPMITOOL_PATH} -I dbus ${command}    return_stdout=True
947a212a09SRahul Maheshwari    ...    return_stderr= True    return_rc=True
95b29d2e84SChris Austen    Should Be Equal    ${output}    ${0}    msg=${stderr}
96*409df05dSGeorge Keishing    RETURN    ${stdout}
97b29d2e84SChris Austen
983ef2e92cSMichael Walsh
99ae7c2281SPrashanth KattiRun Inband IPMI Raw Command
100f4a807bfSJoy Onyerikwu    [Documentation]  Run the raw IPMI command in-band.
1014ad123acSchithrag    [Arguments]  ${command}  ${fail_on_err}=${1}  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
102ae7c2281SPrashanth Katti    ...          ${os_password}=${OS_PASSWORD}
103ae7c2281SPrashanth Katti
1043ef2e92cSMichael Walsh    # Description of argument(s):
1053ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
1063ef2e92cSMichael Walsh    #                               (e.g. "0x06 0x36").
1073ef2e92cSMichael Walsh    # os_host                       The host name or IP address of the OS Host.
1083ef2e92cSMichael Walsh    # os_username                   The OS host user name.
1093ef2e92cSMichael Walsh    # os_password                   The OS host passwrd.
110ae7c2281SPrashanth Katti
111ae7c2281SPrashanth Katti    Login To OS Host  ${os_host}  ${os_username}  ${os_password}
112ae7c2281SPrashanth Katti    Check If IPMI Tool Exist
113ae7c2281SPrashanth Katti
1143ef2e92cSMichael Walsh    ${ipmi_cmd}=  Catenate  ${IPMI_INBAND_CMD}  ${RAW}  ${command}
1153ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
1163ef2e92cSMichael Walsh    ${stdout}  ${stderr}=  Execute Command  ${ipmi_cmd}  return_stderr=True
1174ad123acSchithrag    Return From Keyword If  ${fail_on_err} == ${0}  ${stderr}
118ae7c2281SPrashanth Katti    Should Be Empty  ${stderr}  msg=${stdout}
119*409df05dSGeorge Keishing    RETURN  ${stdout}
120ae7c2281SPrashanth Katti
1213ef2e92cSMichael Walsh
122ae7c2281SPrashanth KattiRun Inband IPMI Standard Command
123f4a807bfSJoy Onyerikwu    [Documentation]  Run the standard IPMI command in-band.
1243ef2e92cSMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  ${os_host}=${OS_HOST}
12520f3bf73SRahul Maheshwari    ...          ${os_username}=${OS_USERNAME}  ${os_password}=${OS_PASSWORD}
1269e8c0d88SNaman Navin Hegde    ...          ${login_host}=${1}
127ae7c2281SPrashanth Katti
1283ef2e92cSMichael Walsh    # Description of argument(s):
1293ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
1303ef2e92cSMichael Walsh    #                               (e.g. "power status").
1313ef2e92cSMichael Walsh    # os_host                       The host name or IP address of the OS Host.
1323ef2e92cSMichael Walsh    # os_username                   The OS host user name.
1333ef2e92cSMichael Walsh    # os_password                   The OS host passwrd.
1349e8c0d88SNaman Navin Hegde    # login_host                    Indicates that this keyword should login to host OS.
135ae7c2281SPrashanth Katti
1369e8c0d88SNaman Navin Hegde    Run Keyword If  ${login_host} == ${1}
1379e8c0d88SNaman Navin Hegde    ...  Login To OS Host  ${os_host}  ${os_username}  ${os_password}
138ae7c2281SPrashanth Katti    Check If IPMI Tool Exist
139ae7c2281SPrashanth Katti
1403ef2e92cSMichael Walsh    ${ipmi_cmd}=  Catenate  ${IPMI_INBAND_CMD}  ${command}
1413ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
1423ef2e92cSMichael Walsh    ${stdout}  ${stderr}=  Execute Command  ${ipmi_cmd}  return_stderr=True
14320f3bf73SRahul Maheshwari    Return From Keyword If  ${fail_on_err} == ${0}  ${stderr}
144ae7c2281SPrashanth Katti    Should Be Empty  ${stderr}  msg=${stdout}
145*409df05dSGeorge Keishing    RETURN  ${stdout}
146ae7c2281SPrashanth Katti
1477a212a09SRahul Maheshwari
1487a212a09SRahul MaheshwariRun External IPMI Standard Command
1493ef2e92cSMichael Walsh    [Documentation]  Run the external IPMI standard command.
150d0e58e73SMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  ${expected_rc}=${0}  &{options}
15102651f0cSGeorge Keishing
15202651f0cSGeorge Keishing    # Description of argument(s):
1533ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
1543ef2e92cSMichael Walsh    #                               (e.g. "power status").  Note that if
1553ef2e92cSMichael Walsh    #                               ${IPMI_USER_OPTIONS} has a value (e.g.
1563ef2e92cSMichael Walsh    #                               "-vvv"), it will be pre-pended to this
1573ef2e92cSMichael Walsh    #                               command string.
1583ef2e92cSMichael Walsh    # fail_on_err                   Fail if the IPMI command execution fails.
159d0e58e73SMichael Walsh    # expected_rc                   The expected return code from the ipmi
160d0e58e73SMichael Walsh    #                               command (e.g. ${0}, ${1}, etc.).
1613ef2e92cSMichael Walsh    # options                       Additional ipmitool command options (e.g.
1623ef2e92cSMichael Walsh    #                               -C=3, -I=lanplus, etc.).
163a7913898SMichael Walsh
1643ef2e92cSMichael Walsh    ${command_string}=  Process IPMI User Options  ${command}
1653ef2e92cSMichael Walsh    ${ipmi_cmd}=  Create IPMI Ext Command String  ${command_string}  &{options}
1663ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
16704a2204bSRahul Maheshwari    ${rc}  ${output}=  Run And Return RC and Output  ${ipmi_cmd}
16802651f0cSGeorge Keishing    Return From Keyword If  ${fail_on_err} == ${0}  ${output}
169d0e58e73SMichael Walsh    Should Be Equal  ${rc}  ${expected_rc}  msg=${output}
170*409df05dSGeorge Keishing    RETURN  ${output}
1717a212a09SRahul Maheshwari
1723ef2e92cSMichael Walsh
1733ef2e92cSMichael WalshRun External IPMI Raw Command
1743ef2e92cSMichael Walsh    [Documentation]  Run the external IPMI raw command.
1753ef2e92cSMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  &{options}
1763ef2e92cSMichael Walsh
1773ef2e92cSMichael Walsh    # This keyword is a wrapper for 'Run External IPMI Standard Command'. See
1783ef2e92cSMichael Walsh    # that keyword's prolog for argument details.  This keyword will pre-pend
1793ef2e92cSMichael Walsh    # the word "raw" plus a space to command prior to calling 'Run External
1803ef2e92cSMichael Walsh    # IPMI Standard Command'.
1813ef2e92cSMichael Walsh
1823ef2e92cSMichael Walsh    ${output}=  Run External IPMI Standard Command
1833ef2e92cSMichael Walsh    ...  raw ${command}  ${fail_on_err}  &{options}
184*409df05dSGeorge Keishing    RETURN  ${output}
1853ef2e92cSMichael Walsh
1863ef2e92cSMichael Walsh
187ae7c2281SPrashanth KattiCheck If IPMI Tool Exist
188ae7c2281SPrashanth Katti    [Documentation]  Check if IPMI Tool installed or not.
189ae7c2281SPrashanth Katti    ${output}=  Execute Command  which ipmitool
190ae7c2281SPrashanth Katti    Should Not Be Empty  ${output}  msg=ipmitool not installed.
1917a212a09SRahul Maheshwari
19204a2204bSRahul Maheshwari
19304a2204bSRahul MaheshwariActivate SOL Via IPMI
19404a2204bSRahul Maheshwari    [Documentation]  Start SOL using IPMI and route output to a file.
19526206721SGeorge Keishing    [Arguments]  ${file_path}=${IPMI_SOL_LOG_FILE}
1963ef2e92cSMichael Walsh
19704a2204bSRahul Maheshwari    # Description of argument(s):
1983ef2e92cSMichael Walsh    # file_path                     The file path on the local machine (vs.
1993ef2e92cSMichael Walsh    #                               OBMC) to collect SOL output. By default
2003ef2e92cSMichael Walsh    #                               SOL output is collected at
20126206721SGeorge Keishing    #                               logs/sol_<BMC_IP> else user input location.
20204a2204bSRahul Maheshwari
2033ef2e92cSMichael Walsh    ${ipmi_cmd}=  Create IPMI Ext Command String  sol activate usesolkeepalive
2043ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
2052102f6bfSGeorge Keishing    Start Process  ${ipmi_cmd}  shell=True  stdout=${file_path}
2064f360843SRahul Maheshwari    ...  alias=sol_proc
20704a2204bSRahul Maheshwari
20804a2204bSRahul Maheshwari
20904a2204bSRahul MaheshwariDeactivate SOL Via IPMI
21004a2204bSRahul Maheshwari    [Documentation]  Stop SOL using IPMI and return SOL output.
21126206721SGeorge Keishing    [Arguments]  ${file_path}=${IPMI_SOL_LOG_FILE}
2123ef2e92cSMichael Walsh
21304a2204bSRahul Maheshwari    # Description of argument(s):
2143ef2e92cSMichael Walsh    # file_path                     The file path on the local machine to copy
2153ef2e92cSMichael Walsh    #                               SOL output collected by above "Activate
2163ef2e92cSMichael Walsh    #                               SOL Via IPMI" keyword.  By default it
21726206721SGeorge Keishing    #                               copies log from logs/sol_<BMC_IP>.
21804a2204bSRahul Maheshwari
2193ef2e92cSMichael Walsh    ${ipmi_cmd}=  Create IPMI Ext Command String  sol deactivate
2203ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
22104a2204bSRahul Maheshwari    ${rc}  ${output}=  Run and Return RC and Output  ${ipmi_cmd}
2224f360843SRahul Maheshwari    Run Keyword If  ${rc} > 0  Run Keywords
2237f48a2c6SRahul Maheshwari    ...  Run Keyword And Ignore Error  Terminate Process  sol_proc
2247f48a2c6SRahul Maheshwari    ...  AND  Return From Keyword  ${output}
22504a2204bSRahul Maheshwari
226aec8b879SGeorge Keishing    ${output}=  OperatingSystem.Get File  ${file_path}  encoding_errors=ignore
22704a2204bSRahul Maheshwari
22804a2204bSRahul Maheshwari    # Logging SOL output for debug purpose.
22904a2204bSRahul Maheshwari    Log  ${output}
23004a2204bSRahul Maheshwari
231*409df05dSGeorge Keishing    RETURN  ${output}
23204a2204bSRahul Maheshwari
23304a2204bSRahul Maheshwari
234a2dab3c8SSivas SRRByte Conversion
235a2dab3c8SSivas SRR    [Documentation]   Byte Conversion method receives IPMI RAW commands as
236a2dab3c8SSivas SRR    ...               argument in string format.
237a2dab3c8SSivas SRR    ...               Sample argument is as follows
238a2dab3c8SSivas SRR    ...               "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
239a2dab3c8SSivas SRR    ...               0x00"
240a2dab3c8SSivas SRR    ...               IPMI RAW command format is as follows
241a2dab3c8SSivas SRR    ...               <netfn Byte> <cmd Byte> <Data Bytes..>
242a2dab3c8SSivas SRR    ...               This method converts IPMI command format into
243a2dab3c8SSivas SRR    ...               dbus command format  as follows
244a2dab3c8SSivas SRR    ...               <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
245a2dab3c8SSivas SRR    ...               <array:byte:data>
246a2dab3c8SSivas SRR    ...               Sample dbus  Host IPMI Received Message argument
247a2dab3c8SSivas SRR    ...               byte:0x00 byte:0x04 byte:0x00 byte:0x30
248a2dab3c8SSivas SRR    ...               array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
24938032805SGunnar Mills    [Arguments]     ${args}
250a2dab3c8SSivas SRR    ${argLength}=   Get Length  ${args}
251a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   array:byte:
252a2dab3c8SSivas SRR    @{listargs}=   Split String  ${args}
253a2dab3c8SSivas SRR    ${index}=   Set Variable   ${0}
25420ccfc71SMarissa Garza    FOR  ${word}  IN  @{listargs}
25520ccfc71SMarissa Garza         Run Keyword if   ${index} == 0   Set NetFn Byte  ${word}
25620ccfc71SMarissa Garza         Run Keyword if   ${index} == 1   Set Cmd Byte    ${word}
25720ccfc71SMarissa Garza         Run Keyword if   ${index} > 1    Set Array Byte  ${word}
25820ccfc71SMarissa Garza         ${index}=    Set Variable    ${index + 1}
25920ccfc71SMarissa Garza    END
260a2dab3c8SSivas SRR    ${length}=   Get Length  ${arrayByte}
261a2dab3c8SSivas SRR    ${length}=   Evaluate  ${length} - 1
262a2dab3c8SSivas SRR    ${arrayByteLocal}=  Get Substring  ${arrayByte}  0   ${length}
263a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   ${arrayByteLocal}
264a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  byte:0x00   ${netfnByte}  byte:0x00
265a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  ${valueinBytesWithArray}  ${cmdByte}
266a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  ${valueinBytesWithArray} ${arrayByte}
267a2dab3c8SSivas SRR    ${valueinBytesWithoutArray}=   Catenate  byte:0x00 ${netfnByte}  byte:0x00
268a2dab3c8SSivas SRR    ${valueinBytesWithoutArray}=   Catenate  ${valueinBytesWithoutArray} ${cmdByte}
269a2dab3c8SSivas SRR    #   To Check scenario for smaller IPMI raw commands with only 2 arguments
270a2dab3c8SSivas SRR    #   instead of usual 12 arguments.
271a2dab3c8SSivas SRR    #   Sample small IPMI raw command: Run IPMI command 0x06 0x36
272a2dab3c8SSivas SRR    #   If IPMI raw argument length is only 9 then return value in bytes without
273a2dab3c8SSivas SRR    #   array population.
274a2dab3c8SSivas SRR    #   Equivalent dbus-send argument for smaller IPMI raw command:
275a2dab3c8SSivas SRR    #   byte:0x00 byte:0x06 byte:0x00 byte:0x36
276a2dab3c8SSivas SRR    Run Keyword if   ${argLength} == 9     Return from Keyword    ${valueinBytesWithoutArray}
277*409df05dSGeorge Keishing    RETURN    ${valueinBytesWithArray}
278a2dab3c8SSivas SRR
279a2dab3c8SSivas SRR
280a2dab3c8SSivas SRRSet NetFn Byte
281f4a807bfSJoy Onyerikwu    [Documentation]  Set the network function byte.
28238032805SGunnar Mills    [Arguments]    ${word}
283a2dab3c8SSivas SRR    ${netfnByteLocal}=  Catenate   byte:${word}
284a2dab3c8SSivas SRR    Set Global Variable  ${netfnByte}  ${netfnByteLocal}
285a2dab3c8SSivas SRR
2863ef2e92cSMichael Walsh
287a2dab3c8SSivas SRRSet Cmd Byte
288f4a807bfSJoy Onyerikwu    [Documentation]  Set the command byte.
28938032805SGunnar Mills    [Arguments]    ${word}
290a2dab3c8SSivas SRR    ${cmdByteLocal}=  Catenate   byte:${word}
291a2dab3c8SSivas SRR    Set Global Variable  ${cmdByte}  ${cmdByteLocal}
292a2dab3c8SSivas SRR
2933ef2e92cSMichael Walsh
294a2dab3c8SSivas SRRSet Array Byte
295f4a807bfSJoy Onyerikwu    [Documentation]  Set the array byte.
29638032805SGunnar Mills    [Arguments]    ${word}
297a2dab3c8SSivas SRR    ${arrayByteLocal}=   Catenate   SEPARATOR=  ${arrayByte}  ${word}
298a2dab3c8SSivas SRR    ${arrayByteLocal}=   Catenate   SEPARATOR=  ${arrayByteLocal}   ,
299a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   ${arrayByteLocal}
300a2dab3c8SSivas SRR
3013ef2e92cSMichael Walsh
302b29d2e84SChris AustenCopy ipmitool
303f4a807bfSJoy Onyerikwu    [Documentation]  Copy the ipmitool to the BMC.
304f4a807bfSJoy Onyerikwu    ${ipmitool_error}=  Catenate  The ipmitool program could not be found in the tools directory.
305f4a807bfSJoy Onyerikwu    ...  It is not part of the automation code by default. You must manually copy or link the correct openbmc
306f4a807bfSJoy Onyerikwu    ...  version of the tool in to the tools directory in order to run this test suite.
307f4a807bfSJoy Onyerikwu
308b9a29a6bSleet    ${response}  ${stderr}  ${rc}=  BMC Execute Command
309b9a29a6bSleet    ...  which ipmitool  ignore_err=${1}
310b9a29a6bSleet    ${installed}=  Get Regexp Matches  ${response}  ipmitool
311b9a29a6bSleet    Run Keyword If  ${installed} == ['ipmitool']
312b9a29a6bSleet    ...  Run Keywords  Set Suite Variable  ${IPMITOOL_PATH}  ${response}
313b9a29a6bSleet    ...  AND  SSHLibrary.Open Connection     ${OPENBMC_HOST}
314b9a29a6bSleet    ...  AND  SSHLibrary.Login   ${OPENBMC_USERNAME}    ${OPENBMC_PASSWORD}
315b9a29a6bSleet    ...  AND  Return From Keyword
316b29d2e84SChris Austen
317b9a29a6bSleet    OperatingSystem.File Should Exist  tools/ipmitool  msg=${ipmitool_error}
318b29d2e84SChris Austen    Import Library      SCPLibrary      WITH NAME       scp
319b29d2e84SChris Austen    scp.Open connection     ${OPENBMC_HOST}     username=${OPENBMC_USERNAME}      password=${OPENBMC_PASSWORD}
320b29d2e84SChris Austen    scp.Put File    tools/ipmitool   /tmp
321b29d2e84SChris Austen    SSHLibrary.Open Connection     ${OPENBMC_HOST}
322f94de719SGeorge Keishing    SSHLibrary.Login   ${OPENBMC_USERNAME}    ${OPENBMC_PASSWORD}
323b9a29a6bSleet    Execute Command     chmod +x ${IPMITOOL_PATH}
3240c34f69cSSridevi Ramesh
3253ef2e92cSMichael Walsh
3260c34f69cSSridevi RameshInitiate Host Boot Via External IPMI
3270c34f69cSSridevi Ramesh    [Documentation]  Initiate host power on using external IPMI.
328982fee42SRahul Maheshwari    [Arguments]  ${wait}=${1}
3293ef2e92cSMichael Walsh
330982fee42SRahul Maheshwari    # Description of argument(s):
3313ef2e92cSMichael Walsh    # wait                          Indicates that this keyword should wait
3323ef2e92cSMichael Walsh    #                               for host running state.
333982fee42SRahul Maheshwari
3340c34f69cSSridevi Ramesh    ${output}=  Run External IPMI Standard Command  chassis power on
3350c34f69cSSridevi Ramesh    Should Not Contain  ${output}  Error
336982fee42SRahul Maheshwari
337982fee42SRahul Maheshwari    Run Keyword If  '${wait}' == '${0}'  Return From Keyword
338982fee42SRahul Maheshwari    Wait Until Keyword Succeeds  10 min  10 sec  Is Host Running
3390c34f69cSSridevi Ramesh
3403ef2e92cSMichael Walsh
3410c34f69cSSridevi RameshInitiate Host PowerOff Via External IPMI
3420c34f69cSSridevi Ramesh    [Documentation]  Initiate host power off using external IPMI.
343982fee42SRahul Maheshwari    [Arguments]  ${wait}=${1}
3443ef2e92cSMichael Walsh
345982fee42SRahul Maheshwari    # Description of argument(s):
3463ef2e92cSMichael Walsh    # wait                          Indicates that this keyword should wait
3473ef2e92cSMichael Walsh    #                               for host off state.
348982fee42SRahul Maheshwari
3490c34f69cSSridevi Ramesh    ${output}=  Run External IPMI Standard Command  chassis power off
3500c34f69cSSridevi Ramesh    Should Not Contain  ${output}  Error
351982fee42SRahul Maheshwari
352982fee42SRahul Maheshwari    Run Keyword If  '${wait}' == '${0}'  Return From Keyword
353982fee42SRahul Maheshwari    Wait Until Keyword Succeeds  3 min  10 sec  Is Host Off
354982fee42SRahul Maheshwari
3553ef2e92cSMichael Walsh
356460778dcSRahul MaheshwariIs Host Off Via IPMI
357460778dcSRahul Maheshwari    [Documentation]  Verify if the Host is off using IPMI command.
358460778dcSRahul Maheshwari
359460778dcSRahul Maheshwari    ${status}=  Run External IPMI Standard Command  chassis power status
360460778dcSRahul Maheshwari    Should Contain  ${status}  off
361460778dcSRahul Maheshwari
362460778dcSRahul Maheshwari
363982fee42SRahul MaheshwariGet Host State Via External IPMI
364982fee42SRahul Maheshwari    [Documentation]  Returns host state using external IPMI.
365982fee42SRahul Maheshwari
366982fee42SRahul Maheshwari    ${output}=  Run External IPMI Standard Command  chassis power status
367982fee42SRahul Maheshwari    Should Not Contain  ${output}  Error
368982fee42SRahul Maheshwari    ${output}=  Fetch From Right  ${output}  ${SPACE}
369982fee42SRahul Maheshwari
370*409df05dSGeorge Keishing    RETURN  ${output}
371b4d4a4aeSGeorge Keishing
372b4d4a4aeSGeorge Keishing
373b4d4a4aeSGeorge KeishingSet BMC Network From Host
374b4d4a4aeSGeorge Keishing    [Documentation]  Set BMC network from host.
375b4d4a4aeSGeorge Keishing    [Arguments]  ${nw_info}
376b4d4a4aeSGeorge Keishing
377b4d4a4aeSGeorge Keishing    # Description of argument(s):
3783ef2e92cSMichael Walsh    # nw_info                       A dictionary containing the network
3793ef2e92cSMichael Walsh    #                               information to apply.
380b4d4a4aeSGeorge Keishing
381b4d4a4aeSGeorge Keishing    Run Inband IPMI Standard Command
382b4d4a4aeSGeorge Keishing    ...  lan set 1 ipaddr ${nw_info['IP Address']}
383b4d4a4aeSGeorge Keishing
384b4d4a4aeSGeorge Keishing    Run Inband IPMI Standard Command
385b4d4a4aeSGeorge Keishing    ...  lan set 1 netmask ${nw_info['Subnet Mask']}
386b4d4a4aeSGeorge Keishing
387b4d4a4aeSGeorge Keishing    Run Inband IPMI Standard Command
388b4d4a4aeSGeorge Keishing    ...  lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}
389c3d1e968SRahul Maheshwari
390c3d1e968SRahul Maheshwari
391c3d1e968SRahul MaheshwariVerify IPMI Username And Password
392c3d1e968SRahul Maheshwari    [Documentation]  Verify that user is able to run IPMI command
393c3d1e968SRahul Maheshwari    ...  with given username and password.
394c3d1e968SRahul Maheshwari    [Arguments]  ${username}  ${password}
395c3d1e968SRahul Maheshwari
396c3d1e968SRahul Maheshwari    # Description of argument(s):
397c3d1e968SRahul Maheshwari    # username    The user name (e.g. "root", "robert", etc.).
3987ac1f56fSGeorge Keishing    # password    The user password.
399c3d1e968SRahul Maheshwari
400f9379e88STony Lee    ${output}=  Wait Until Keyword Succeeds  15 sec  5 sec  Run External IPMI Standard Command
401c3d1e968SRahul Maheshwari    ...  sel info  U=${username}  P=${password}
402c3d1e968SRahul Maheshwari    Should Contain  ${output}  SEL Information  msg=SEL information not present
40375e91feaSRahul Maheshwari
40475e91feaSRahul Maheshwari
40575e91feaSRahul MaheshwariIPMI Create User
40675e91feaSRahul Maheshwari    [Documentation]  Create IPMI user with given userid and username.
40775e91feaSRahul Maheshwari    [Arguments]  ${userid}  ${username}
40875e91feaSRahul Maheshwari
40975e91feaSRahul Maheshwari    # Description of argument(s):
41075e91feaSRahul Maheshwari    # userid      The user ID (e.g. "1", "2", etc.).
41175e91feaSRahul Maheshwari    # username    The user name (e.g. "root", "robert", etc.).
41275e91feaSRahul Maheshwari
41375e91feaSRahul Maheshwari    ${ipmi_cmd}=  Catenate  user set name ${userid} ${username}
41475e91feaSRahul Maheshwari    ${resp}=  Run IPMI Standard Command  ${ipmi_cmd}
41526499145SNagarjun B    ${user_info}=  Get User Info  ${userid}  ${CHANNEL_NUMBER}
41675e91feaSRahul Maheshwari    Should Be Equal  ${user_info['user_name']}  ${username}
41775e91feaSRahul Maheshwari
41875e91feaSRahul Maheshwari
419a2255de5Snagarjunb22Enable IPMI User And Verify
420a2255de5Snagarjunb22    [Documentation]  Enable the userid and verify that it has been enabled.
421a2255de5Snagarjunb22    [Arguments]  ${userid}
422a2255de5Snagarjunb22
423a2255de5Snagarjunb22    # Description of argument(s):
424a2255de5Snagarjunb22    # userid   A numeric userid (e.g. "4").
425a2255de5Snagarjunb22
426a2255de5Snagarjunb22    Run IPMI Standard Command  user enable ${userid}
42726499145SNagarjun B    ${user_info}=  Get User Info  ${userid}  ${CHANNEL_NUMBER}
428a2255de5Snagarjunb22    Valid Value  user_info['enable_status']  ['enabled']
429a2255de5Snagarjunb22
430a2255de5Snagarjunb22
431a2255de5Snagarjunb22Create Random IPMI User
432a2255de5Snagarjunb22    [Documentation]  Create IPMI user with random username and userid and return those fields.
433a2255de5Snagarjunb22
434a2255de5Snagarjunb22    ${random_username}=  Generate Random String  8  [LETTERS]
4359e4481b8SRuud A. Haring    ${random_userid}=  Find Free User Id
436a2255de5Snagarjunb22    IPMI Create User  ${random_userid}  ${random_username}
4379e4481b8SRuud A. Haring    Wait And Confirm New User Entry  ${random_username}
438*409df05dSGeorge Keishing    RETURN  ${random_userid}  ${random_username}
439a2255de5Snagarjunb22
440a2255de5Snagarjunb22
4419e4481b8SRuud A. HaringFind Free User Id
4429e4481b8SRuud A. Haring    [Documentation]  Find a userid that is not being used.
4439e4481b8SRuud A. Haring
4449e4481b8SRuud A. Haring    Check Enabled User Count
4459e4481b8SRuud A. Haring    FOR    ${num}    IN RANGE    300
4469e4481b8SRuud A. Haring        ${random_userid}=  Evaluate  random.randint(1, ${expected_max_ids})  modules=random
4479e4481b8SRuud A. Haring        ${access}=  Run IPMI Standard Command  channel getaccess ${CHANNEL_NUMBER} ${random_userid}
4489e4481b8SRuud A. Haring
4499e4481b8SRuud A. Haring        ${name_line}=  Get Lines Containing String  ${access}  User Name
4509e4481b8SRuud A. Haring        Log To Console  For ID ${random_userid}: ${name_line}
4519e4481b8SRuud A. Haring        ${is_empty}=  Run Keyword And Return Status
4529e4481b8SRuud A. Haring        ...  Should Match Regexp  ${name_line}  ${empty_name_pattern}
4539e4481b8SRuud A. Haring
4549e4481b8SRuud A. Haring        Exit For Loop If  ${is_empty} == ${True}
4559e4481b8SRuud A. Haring    END
456*409df05dSGeorge Keishing    RETURN  ${random_userid}
4579e4481b8SRuud A. Haring
4589e4481b8SRuud A. Haring
4599e4481b8SRuud A. HaringCheck Enabled User Count
4609e4481b8SRuud A. Haring    [Documentation]  Ensure that there are available user IDs.
4619e4481b8SRuud A. Haring
4629e4481b8SRuud A. Haring    # Check for the enabled user count
4639e4481b8SRuud A. Haring    ${resp}=  Run IPMI Standard Command  user summary ${CHANNEL_NUMBER}
4649e4481b8SRuud A. Haring    ${enabled_user_count}=
4659e4481b8SRuud A. Haring    ...  Get Lines Containing String  ${resp}  Enabled User Count
4669e4481b8SRuud A. Haring
4679e4481b8SRuud A. Haring    Should not contain  ${enabled_user_count}  ${expected_max_ids}
4689e4481b8SRuud A. Haring    ...  msg=IPMI has reached maximum user count
4699e4481b8SRuud A. Haring
4709e4481b8SRuud A. Haring
4719e4481b8SRuud A. HaringWait And Confirm New User Entry
4729e4481b8SRuud A. Haring    [Documentation]  Wait in loop until new user appears with given username.
4739e4481b8SRuud A. Haring    [Arguments]  ${username}
4749e4481b8SRuud A. Haring
4759e4481b8SRuud A. Haring    # Description of argument(s):
4769e4481b8SRuud A. Haring    # username         The user name (e.g. "root", "robert", etc.).
4779e4481b8SRuud A. Haring
4789e4481b8SRuud A. Haring    Wait Until Keyword Succeeds  45 sec  1 sec  Verify IPMI Username Visible
4799e4481b8SRuud A. Haring    ...  ${username}
4809e4481b8SRuud A. Haring
4819e4481b8SRuud A. Haring
4829e4481b8SRuud A. HaringVerify IPMI Username Visible
4839e4481b8SRuud A. Haring    [Documentation]  Confirm that username is present in user list.
4849e4481b8SRuud A. Haring    [Arguments]  ${username}
4859e4481b8SRuud A. Haring
4869e4481b8SRuud A. Haring    # Description of argument(s):
4879e4481b8SRuud A. Haring    # username         The user name (e.g. "root", "robert", etc.).
4889e4481b8SRuud A. Haring
4899e4481b8SRuud A. Haring    ${resp}=  Run IPMI Standard Command  user list
4909e4481b8SRuud A. Haring    Should Contain  ${resp}  ${username}
4919e4481b8SRuud A. Haring
4929e4481b8SRuud A. Haring
493a2255de5Snagarjunb22Delete Created User
494a2255de5Snagarjunb22    [Documentation]  Delete created IPMI user.
495a2255de5Snagarjunb22    [Arguments]  ${userid}
496a2255de5Snagarjunb22    # Description of argument(s):
497a2255de5Snagarjunb22    # userid  The user ID (e.g. "1", "2", etc.).
498a2255de5Snagarjunb22
499a2255de5Snagarjunb22    Run IPMI Standard Command  user set name ${userid} ""
500a2255de5Snagarjunb22    Sleep  5s
501a2255de5Snagarjunb22
502a2255de5Snagarjunb22
50375e91feaSRahul MaheshwariSet Channel Access
50475e91feaSRahul Maheshwari    [Documentation]  Verify that user is able to run IPMI command
50575e91feaSRahul Maheshwari    ...  with given username and password.
5067c5f4b28STony Lee    [Arguments]  ${userid}  ${options}  ${channel_number}=${CHANNEL_NUMBER}
50775e91feaSRahul Maheshwari
50875e91feaSRahul Maheshwari    # Description of argument(s):
50975e91feaSRahul Maheshwari    # userid          The user ID (e.g. "1", "2", etc.).
51075e91feaSRahul Maheshwari    # options         Set channel command options (e.g.
51175e91feaSRahul Maheshwari    #                 "link=on", "ipmi=on", etc.).
51275e91feaSRahul Maheshwari    # channel_number  The user's channel number (e.g. "1").
51375e91feaSRahul Maheshwari
51475e91feaSRahul Maheshwari    ${ipmi_cmd}=  Catenate  SEPARATOR=
5157c5f4b28STony Lee    ...  channel setaccess${SPACE}${channel_number}${SPACE}${userid}
51675e91feaSRahul Maheshwari    ...  ${SPACE}${options}
51775e91feaSRahul Maheshwari    Run IPMI Standard Command  ${ipmi_cmd}
5183e61ce66SRahul Maheshwari
5193e61ce66SRahul Maheshwari
5203e61ce66SRahul MaheshwariDelete All Non Root IPMI User
5213e61ce66SRahul Maheshwari    [Documentation]  Delete all non-root IPMI user.
5223e61ce66SRahul Maheshwari
52334c79af0SMichael Walsh    # Get complete list of user info records.
52426499145SNagarjun B    ${user_info}=  Get User Info  ${EMPTY}  ${CHANNEL_NUMBER}
52534c79af0SMichael Walsh    # Remove header record.
52634c79af0SMichael Walsh    ${user_info}=  Filter Struct  ${user_info}  [('user_name', None)]  invert=1
52734c79af0SMichael Walsh    ${non_empty_user_info}=  Filter Struct  ${user_info}  [('user_name', '')]  invert=1
52834c79af0SMichael Walsh    ${non_root_user_info}=  Filter Struct  ${non_empty_user_info}  [('user_name', 'root')]  invert=1
52934c79af0SMichael Walsh
53034c79af0SMichael Walsh    FOR  ${user_record}  IN  @{non_root_user_info}
53134c79af0SMichael Walsh        Run IPMI Standard Command   user set name ${user_record['user_id']} ""
532bb3d21c0SRahul Maheshwari        Sleep  5s
5333e61ce66SRahul Maheshwari    END
5340a8c8787Schithrag
5350a8c8787Schithrag
5360a8c8787SchithragCreate SEL
5370a8c8787Schithrag    [Documentation]  Create a SEL.
5380a8c8787Schithrag    [Arguments]  ${sensor_type}  ${sensor_number}
5390a8c8787Schithrag
5400a8c8787Schithrag    # Create a SEL.
5410a8c8787Schithrag    # Example:
5420a8c8787Schithrag    # a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 |  | Asserted
5430a8c8787Schithrag    # Description of argument(s):
5440a8c8787Schithrag    #    ${sensor_type}            Type of the sensor used in hexadecimal (can be fan, temp etc.,),
5450a8c8787Schithrag    #                              obtained from Sensor Type field in - ipmitool sdr get "sensor_name".
5460a8c8787Schithrag    #                              Example: Sensor Type (Threshold) : Fan (0x04), here 0xHH is sensor type.
5470a8c8787Schithrag
5480a8c8787Schithrag    #    ${sensor_number}          Sensor number of the sensor in hexadecimal.
5490a8c8787Schithrag    #                              obtained from Sensor ID field in - ipmitool sdr get "sensor_name".
5500a8c8787Schithrag    #                              Example: Sensor ID : SENSOR_1 (0xHH), here 0xHH is sensor number.
5510a8c8787Schithrag
552a8aee234Sganesanb    ${cmd}=  Catenate  ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][0]} 0x${GEN_ID_BYTE_1} 0x${GEN_ID_BYTE_2}
553a8aee234Sganesanb    ...  ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][1]} 0x${sensor_type} 0x${sensor_number}
554a8aee234Sganesanb    ...  ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][2]}
555a8aee234Sganesanb
556a8aee234Sganesanb    ${resp}=  Run IPMI Command  ${cmd}
5570a8c8787Schithrag
558d7e009b6Schithrag    Should Not Contain  ${resp}  00 00  msg=SEL not created.
559d7e009b6Schithrag
56075379c97Smanimozhik    Sleep  5s
56175379c97Smanimozhik
562*409df05dSGeorge Keishing    RETURN  ${resp}
5630a8c8787Schithrag
5640a8c8787Schithrag
565ebea55fdSganesanbFetch One Threshold Sensor From Sensor List
566ebea55fdSganesanb    [Documentation]  Fetch one threshold sensor randomly from Sensor list.
567d282b56bSganesanb
568ebea55fdSganesanb    @{sensor_name_list}=  Create List
5690a8c8787Schithrag
5700a8c8787Schithrag    ${resp}=  Run IPMI Standard Command  sensor
571ebea55fdSganesanb    @{sensor_list}=  Split To Lines  ${resp}
5720a8c8787Schithrag
573d282b56bSganesanb    # Omit the discrete sensor and create an threshold sensor name list
574ebea55fdSganesanb    FOR  ${sensor}  IN  @{sensor_list}
575d282b56bSganesanb      ${discrete_sensor_status}=  Run Keyword And Return Status  Should Contain  ${sensor}  discrete
576d282b56bSganesanb      Continue For Loop If  '${discrete_sensor_status}' == 'True'
577d282b56bSganesanb      ${sensor_details}=  Split String  ${sensor}  |
578d282b56bSganesanb      ${get_sensor_name}=  Get From List  ${sensor_details}  0
579d282b56bSganesanb      ${sensor_name}=  Set Variable  ${get_sensor_name.strip()}
580ebea55fdSganesanb      Append To List  ${sensor_name_list}  ${sensor_name}
581d282b56bSganesanb    END
5820a8c8787Schithrag
583ebea55fdSganesanb    ${random_sensor_name}=  Evaluate  random.choice(${sensor_name_list})  random
5840a8c8787Schithrag
585*409df05dSGeorge Keishing    RETURN  ${random_sensor_name}
5860a8c8787Schithrag
5870a8c8787SchithragFetch Sensor Details From SDR
5880a8c8787Schithrag    [Documentation]  Identify the sensors from sdr get and fetch sensor details required.
5890a8c8787Schithrag    [Arguments]  ${sensor_name}  ${setting}
5900a8c8787Schithrag
5910a8c8787Schithrag    # Description of argument(s):
5920a8c8787Schithrag    #    ${sensor_number}        Sensor number of the sensor in hexadecimal.
5930a8c8787Schithrag    #                            obtained sensor name from - 'ipmitool sensor' command.
5940a8c8787Schithrag    #                            Example: a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 |  | Asserted
5950a8c8787Schithrag    #                            here, a is the sensor name.
5960a8c8787Schithrag
5970a8c8787Schithrag    #    ${setting}              Field to fetch data. Example : Sensor ID, Sensor Type (Threshold), etc,.
5980a8c8787Schithrag
5990a8c8787Schithrag    ${resp}=  Run IPMI Standard Command  sdr get "${sensor_name}"
6000a8c8787Schithrag
6010a8c8787Schithrag    ${setting_line}=  Get Lines Containing String  ${resp}  ${setting}
6020a8c8787Schithrag    ...  case-insensitive
6030a8c8787Schithrag    ${setting_status}=  Fetch From Right  ${setting_line}  :${SPACE}
6040a8c8787Schithrag
605*409df05dSGeorge Keishing    RETURN  ${setting_status}
6060a8c8787Schithrag
6070a8c8787Schithrag
60811fe27f3SganesanbGet Bytes From SDR Sensor
6090a8c8787Schithrag    [Documentation]  Fetch the Field Data and hexadecimal values from given details.
6100a8c8787Schithrag    [Arguments]  ${sensor_detail}
6110a8c8787Schithrag
6120a8c8787Schithrag    # Description of argument(s):
6130a8c8787Schithrag    #    ${sensor_detail}      Requested field and the value from the sdr get ipmi command.
6140a8c8787Schithrag    #                          Example : if Sensor ID is the requesting setting, then,
6150a8c8787Schithrag    #                          ${sensor_detail} will be "Sensor ID : SENSOR_1 (0xHH)"
6160a8c8787Schithrag
6170a8c8787Schithrag    ${sensor_detail}=  Split String  ${sensor_detail}  (0x
6180a8c8787Schithrag    ${sensor_hex}=  Replace String  ${sensor_detail[1]}  )  ${EMPTY}
6190a8c8787Schithrag    ${sensor_hex}=  Zfill Data  ${sensor_hex}  2
6200a8c8787Schithrag
621*409df05dSGeorge Keishing    RETURN  ${sensor_hex}
6220a8c8787Schithrag
6230a8c8787Schithrag
6240a8c8787SchithragGet Current Date from BMC
6250a8c8787Schithrag    [Documentation]  Runs the date command from BMC and returns current date and time
6260b29ed3fSAnusha Dathatri    [Arguments]  ${date_format}=%m/%d/%Y %H:%M:%S
6270b29ed3fSAnusha Dathatri
6280b29ed3fSAnusha Dathatri    # Description of argument(s):
6290b29ed3fSAnusha Dathatri    # date_format    Date format of the result. E.g. %Y-%m-%d %H:%M:%S etc.
6300a8c8787Schithrag
6310a8c8787Schithrag    # Get Current Date from BMC
6320a8c8787Schithrag    ${date}  ${stderr}  ${rc}=  BMC Execute Command   date
6330a8c8787Schithrag
6340a8c8787Schithrag    # Split the string and remove first and 2nd last value from the list and join to form %d %b %H:%M:%S %Y date format
6350a8c8787Schithrag    ${date}=  Split String  ${date}
6360a8c8787Schithrag    Remove From List  ${date}  0
6370a8c8787Schithrag    Remove From List  ${date}  -2
6380a8c8787Schithrag    ${date}=  Evaluate  " ".join(${date})
6390a8c8787Schithrag
6400b29ed3fSAnusha Dathatri    # Convert the date to specified format, default:%m/%d/%Y %H:%M:%S
6410b29ed3fSAnusha Dathatri    ${date}=  Convert Date  ${date}  date_format=%b %d %H:%M:%S %Y  result_format=${date_format}  exclude_millis=True
6420a8c8787Schithrag
643*409df05dSGeorge Keishing    RETURN   ${date}
644d7e009b6Schithrag
645d7e009b6Schithrag
646d7e009b6SchithragGet SEL Info Via IPMI
647d7e009b6Schithrag    [Documentation]  Get the SEL Info via IPMI raw command
648d7e009b6Schithrag
649d7e009b6Schithrag    # Get SEL Info response consist of 14 bytes of hexadecimal data.
650d7e009b6Schithrag
651d7e009b6Schithrag    # Byte 1 - SEL Version,
652d7e009b6Schithrag    # Byte 2 & 3 - Entry bytes - LSB MSB,
653d7e009b6Schithrag    # Byte 4 & 5 - Free Space in bytes, LS Byte first.
654d7e009b6Schithrag    # Byte 6 - 9 - Most recent addition timestamp,
655d7e009b6Schithrag    # Byte 10-13 - Most recent erase timestamp,
656d7e009b6Schithrag    # Byte 14 - Operation Support
657d7e009b6Schithrag
658d7e009b6Schithrag    # Example: ${resp} will be "51 XX XX XX XX ff ff ff ff ff ff ff ff XX"
659d7e009b6Schithrag
660372cd862Sishwaryamathim    ${resp}=  Run IPMI Command
661372cd862Sishwaryamathim    ...  ${IPMI_RAW_CMD['SEL_entry']['SEL_info'][0]}
662d7e009b6Schithrag    ${resp}=  Split String  ${resp}
663d7e009b6Schithrag
664*409df05dSGeorge Keishing    RETURN  ${resp}
6657fabf794Snagarjunb22
6667fabf794Snagarjunb22
6677fabf794Snagarjunb22Verify Invalid IPMI Command
6687fabf794Snagarjunb22    [Documentation]  Execute invalid IPMI command and verify with given response code.
6697fabf794Snagarjunb22    [Arguments]  ${ipmi_cmd}  ${error_code}=0xc9
6707fabf794Snagarjunb22
6717fabf794Snagarjunb22    #  Description Of Arguments.
6727fabf794Snagarjunb22    #  ${ipmi_cmd}   - IPMI raw cmd with invalid data length.
6737fabf794Snagarjunb22    #  ${error_code} - Expected error code e.g 0xc7, 0xcc.
6747fabf794Snagarjunb22
675372cd862Sishwaryamathim    ${resp}=  Run IPMI Command  ${ipmi_cmd}  fail_on_err=0
6767fabf794Snagarjunb22
6777fabf794Snagarjunb22    Should Contain  ${resp}  rsp=${error_code}
678c288affeSganesanb
679c288affeSganesanb
680c288affeSganesanbIdentify Request Data
681c288affeSganesanb    [Documentation]  Convert text from variable declared to request data.
682c288affeSganesanb    [Arguments]  ${string}
683c288affeSganesanb
684c288affeSganesanb    # Convert string to hexadecimal data for each character.
685c288affeSganesanb    # Return the hex data with prefix of 0x as string and list of hex data.
686c288affeSganesanb    # Description of argument(s):
687c288affeSganesanb    #    string             Any string to be converted to hex.
688c288affeSganesanb
689c288affeSganesanb    # Given a string, convert to hexadecimal and prefix with 0x
690c288affeSganesanb    ${hex1}=  Create List
691c288affeSganesanb    ${hex2}=  Create List
692c288affeSganesanb    ${resp_data}=  Split String With Index  ${string}  1
693c288affeSganesanb    FOR  ${data}  IN  @{resp_data}
694c288affeSganesanb        # prefixes 0x by default
695c288affeSganesanb        ${hex_value}=  Evaluate  hex(ord("${data}"))
696c288affeSganesanb        # prefixes string with bytes prefixed 0x by default
697c288affeSganesanb        Append To List  ${hex1}  ${hex_value}
698c288affeSganesanb        # provides only hexadecimal bytes
699c288affeSganesanb        ${hex}=  Evaluate  hex(ord("${data}"))[2:]
700c288affeSganesanb        # provides string with only hexadecimal bytes
701c288affeSganesanb        Append To List  ${hex2}  ${hex}
702c288affeSganesanb    END
703c288affeSganesanb    ${hex1}=  Evaluate  " ".join(${hex1})
704c288affeSganesanb
705c288affeSganesanb    # ${hex1} will contains the data to write for fru in list.
706c288affeSganesanb    # ${hex2} will contains the data to verify fru after write operation completed.
707c288affeSganesanb
708*409df05dSGeorge Keishing    RETURN  ${hex1}  ${hex2}
709