xref: /openbmc/openbmc-test-automation/lib/ipmi_client.robot (revision 7c5f4b28bf8d845828a0b7188d0458da0fd344b4)
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
1119621bacSMichael WalshLibrary         ipmi_client.py
12a2dab3c8SSivas SRR
13a2dab3c8SSivas SRR*** Variables ***
14d7f11f70SGeorge Keishing${dbusHostIpmicmd1}=   dbus-send --system  ${OPENBMC_BASE_URI}HostIpmi/1
15d7f11f70SGeorge Keishing${dbusHostIpmiCmdReceivedMsg}=   ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage
16a2dab3c8SSivas SRR${netfnByte}=          ${EMPTY}
17a2dab3c8SSivas SRR${cmdByte}=            ${EMPTY}
18a2dab3c8SSivas SRR${arrayByte}=          array:byte:
19a7913898SMichael Walsh${IPMI_USER_OPTIONS}   ${EMPTY}
2039967ebcSGeorge Keishing${IPMI_INBAND_CMD}=    ipmitool -C ${IPMI_CIPHER_LEVEL}
217a212a09SRahul Maheshwari${HOST}=               -H
227a212a09SRahul Maheshwari${RAW}=                raw
23b29d2e84SChris Austen
24b29d2e84SChris Austen*** Keywords ***
257a212a09SRahul Maheshwari
26b29d2e84SChris AustenRun IPMI Command
273ef2e92cSMichael Walsh    [Documentation]  Run the raw IPMI command.
283ef2e92cSMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  &{options}
293ef2e92cSMichael Walsh
303ef2e92cSMichael Walsh    # Description of argument(s):
313ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
323ef2e92cSMichael Walsh    #                               (e.g. "power status").
333ef2e92cSMichael Walsh    # fail_on_err                   Fail if the IPMI command execution fails.
343ef2e92cSMichael Walsh    # options                       Additional ipmitool command options (e.g.
353ef2e92cSMichael Walsh    #                               -C=3, -I=lanplus, etc.).  Currently, only
363ef2e92cSMichael Walsh    #                               used for external IPMI commands.
373ef2e92cSMichael Walsh
387a212a09SRahul Maheshwari    ${resp}=  Run Keyword If  '${IPMI_COMMAND}' == 'External'
393ef2e92cSMichael Walsh    ...    Run External IPMI Raw Command  ${command}  ${fail_on_err}  &{options}
40ae7c2281SPrashanth Katti    ...  ELSE IF  '${IPMI_COMMAND}' == 'Inband'
413ef2e92cSMichael Walsh    ...    Run Inband IPMI Raw Command  ${command}
427a212a09SRahul Maheshwari    ...  ELSE IF  '${IPMI_COMMAND}' == 'Dbus'
433ef2e92cSMichael Walsh    ...    Run Dbus IPMI RAW Command  ${command}
44ae7c2281SPrashanth Katti    ...  ELSE  Fail  msg=Invalid IPMI Command type provided: ${IPMI_COMMAND}
45c9ea9368SGunnar Mills    [Return]  ${resp}
467a212a09SRahul Maheshwari
473ef2e92cSMichael Walsh
487a212a09SRahul MaheshwariRun IPMI Standard Command
49f4a807bfSJoy Onyerikwu    [Documentation]  Run the standard IPMI command.
50d0e58e73SMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  ${expected_rc}=${0}  &{options}
5120f3bf73SRahul Maheshwari
5220f3bf73SRahul Maheshwari    # Description of argument(s):
533ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
543ef2e92cSMichael Walsh    #                               (e.g. "0x06 0x36").
553ef2e92cSMichael Walsh    # fail_on_err                   Fail if the IPMI command execution fails.
56d0e58e73SMichael Walsh    # expected_rc                   The expected return code from the ipmi
57d0e58e73SMichael Walsh    #                               command (e.g. ${0}, ${1}, etc.).
583ef2e92cSMichael Walsh    # options                       Additional ipmitool command options (e.g.
593ef2e92cSMichael Walsh    #                               -C=3, -I=lanplus, etc.).  Currently, only
603ef2e92cSMichael Walsh    #                               used for external IPMI commands.
6120f3bf73SRahul Maheshwari
627a212a09SRahul Maheshwari    ${resp}=  Run Keyword If  '${IPMI_COMMAND}' == 'External'
63d0e58e73SMichael Walsh    ...    Run External IPMI Standard Command  ${command}  ${fail_on_err}  ${expected_rc}  &{options}
64ae7c2281SPrashanth Katti    ...  ELSE IF  '${IPMI_COMMAND}' == 'Inband'
653ef2e92cSMichael Walsh    ...    Run Inband IPMI Standard Command  ${command}  ${fail_on_err}
667a212a09SRahul Maheshwari    ...  ELSE IF  '${IPMI_COMMAND}' == 'Dbus'
673ef2e92cSMichael Walsh    ...    Run Dbus IPMI Standard Command  ${command}
68ae7c2281SPrashanth Katti    ...  ELSE  Fail  msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
69c9ea9368SGunnar Mills    [Return]  ${resp}
707a212a09SRahul Maheshwari
713ef2e92cSMichael Walsh
727a212a09SRahul MaheshwariRun Dbus IPMI RAW Command
73f4a807bfSJoy Onyerikwu    [Documentation]  Run the raw IPMI command through dbus.
743ef2e92cSMichael Walsh    [Arguments]    ${command}
753ef2e92cSMichael Walsh    ${valueinBytes}=   Byte Conversion  ${command}
76a2dab3c8SSivas SRR    ${cmd}=   Catenate   ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
77a2dab3c8SSivas SRR    ${cmd}=   Catenate   ${cmd} ${valueinBytes}
78a2dab3c8SSivas SRR    ${output}   ${stderr}=  Execute Command  ${cmd}  return_stderr=True
79b29d2e84SChris Austen    Should Be Empty      ${stderr}
80b29d2e84SChris Austen    set test variable    ${OUTPUT}     "${output}"
81b29d2e84SChris Austen
823ef2e92cSMichael Walsh
837a212a09SRahul MaheshwariRun Dbus IPMI Standard Command
84f4a807bfSJoy Onyerikwu    [Documentation]  Run the standard IPMI command through dbus.
853ef2e92cSMichael Walsh    [Arguments]    ${command}
864d6c1dabSGeorge Keishing    Copy ipmitool
877a212a09SRahul Maheshwari    ${stdout}    ${stderr}    ${output}=  Execute Command
883ef2e92cSMichael Walsh    ...    /tmp/ipmitool -I dbus ${command}    return_stdout=True
897a212a09SRahul Maheshwari    ...    return_stderr= True    return_rc=True
90b29d2e84SChris Austen    Should Be Equal    ${output}    ${0}    msg=${stderr}
91c9ea9368SGunnar Mills    [Return]    ${stdout}
92b29d2e84SChris Austen
933ef2e92cSMichael Walsh
94ae7c2281SPrashanth KattiRun Inband IPMI Raw Command
95f4a807bfSJoy Onyerikwu    [Documentation]  Run the raw IPMI command in-band.
963ef2e92cSMichael Walsh    [Arguments]  ${command}  ${os_host}=${OS_HOST}  ${os_username}=${OS_USERNAME}
97ae7c2281SPrashanth Katti    ...          ${os_password}=${OS_PASSWORD}
98ae7c2281SPrashanth Katti
993ef2e92cSMichael Walsh    # Description of argument(s):
1003ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
1013ef2e92cSMichael Walsh    #                               (e.g. "0x06 0x36").
1023ef2e92cSMichael Walsh    # os_host                       The host name or IP address of the OS Host.
1033ef2e92cSMichael Walsh    # os_username                   The OS host user name.
1043ef2e92cSMichael Walsh    # os_password                   The OS host passwrd.
105ae7c2281SPrashanth Katti
106ae7c2281SPrashanth Katti    Login To OS Host  ${os_host}  ${os_username}  ${os_password}
107ae7c2281SPrashanth Katti    Check If IPMI Tool Exist
108ae7c2281SPrashanth Katti
1093ef2e92cSMichael Walsh    ${ipmi_cmd}=  Catenate  ${IPMI_INBAND_CMD}  ${RAW}  ${command}
1103ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
1113ef2e92cSMichael Walsh    ${stdout}  ${stderr}=  Execute Command  ${ipmi_cmd}  return_stderr=True
112ae7c2281SPrashanth Katti    Should Be Empty  ${stderr}  msg=${stdout}
113ae7c2281SPrashanth Katti    [Return]  ${stdout}
114ae7c2281SPrashanth Katti
1153ef2e92cSMichael Walsh
116ae7c2281SPrashanth KattiRun Inband IPMI Standard Command
117f4a807bfSJoy Onyerikwu    [Documentation]  Run the standard IPMI command in-band.
1183ef2e92cSMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  ${os_host}=${OS_HOST}
11920f3bf73SRahul Maheshwari    ...          ${os_username}=${OS_USERNAME}  ${os_password}=${OS_PASSWORD}
1209e8c0d88SNaman Navin Hegde    ...          ${login_host}=${1}
121ae7c2281SPrashanth Katti
1223ef2e92cSMichael Walsh    # Description of argument(s):
1233ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
1243ef2e92cSMichael Walsh    #                               (e.g. "power status").
1253ef2e92cSMichael Walsh    # os_host                       The host name or IP address of the OS Host.
1263ef2e92cSMichael Walsh    # os_username                   The OS host user name.
1273ef2e92cSMichael Walsh    # os_password                   The OS host passwrd.
1289e8c0d88SNaman Navin Hegde    # login_host                    Indicates that this keyword should login to host OS.
129ae7c2281SPrashanth Katti
1309e8c0d88SNaman Navin Hegde    Run Keyword If  ${login_host} == ${1}
1319e8c0d88SNaman Navin Hegde    ...  Login To OS Host  ${os_host}  ${os_username}  ${os_password}
132ae7c2281SPrashanth Katti    Check If IPMI Tool Exist
133ae7c2281SPrashanth Katti
1343ef2e92cSMichael Walsh    ${ipmi_cmd}=  Catenate  ${IPMI_INBAND_CMD}  ${command}
1353ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
1363ef2e92cSMichael Walsh    ${stdout}  ${stderr}=  Execute Command  ${ipmi_cmd}  return_stderr=True
13720f3bf73SRahul Maheshwari    Return From Keyword If  ${fail_on_err} == ${0}  ${stderr}
138ae7c2281SPrashanth Katti    Should Be Empty  ${stderr}  msg=${stdout}
139ae7c2281SPrashanth Katti    [Return]  ${stdout}
140ae7c2281SPrashanth Katti
1417a212a09SRahul Maheshwari
1427a212a09SRahul MaheshwariRun External IPMI Standard Command
1433ef2e92cSMichael Walsh    [Documentation]  Run the external IPMI standard command.
144d0e58e73SMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  ${expected_rc}=${0}  &{options}
14502651f0cSGeorge Keishing
14602651f0cSGeorge Keishing    # Description of argument(s):
1473ef2e92cSMichael Walsh    # command                       The IPMI command string to be executed
1483ef2e92cSMichael Walsh    #                               (e.g. "power status").  Note that if
1493ef2e92cSMichael Walsh    #                               ${IPMI_USER_OPTIONS} has a value (e.g.
1503ef2e92cSMichael Walsh    #                               "-vvv"), it will be pre-pended to this
1513ef2e92cSMichael Walsh    #                               command string.
1523ef2e92cSMichael Walsh    # fail_on_err                   Fail if the IPMI command execution fails.
153d0e58e73SMichael Walsh    # expected_rc                   The expected return code from the ipmi
154d0e58e73SMichael Walsh    #                               command (e.g. ${0}, ${1}, etc.).
1553ef2e92cSMichael Walsh    # options                       Additional ipmitool command options (e.g.
1563ef2e92cSMichael Walsh    #                               -C=3, -I=lanplus, etc.).
157a7913898SMichael Walsh
1583ef2e92cSMichael Walsh    ${command_string}=  Process IPMI User Options  ${command}
1593ef2e92cSMichael Walsh    ${ipmi_cmd}=  Create IPMI Ext Command String  ${command_string}  &{options}
1603ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
16104a2204bSRahul Maheshwari    ${rc}  ${output}=  Run And Return RC and Output  ${ipmi_cmd}
16202651f0cSGeorge Keishing    Return From Keyword If  ${fail_on_err} == ${0}  ${output}
163d0e58e73SMichael Walsh    Should Be Equal  ${rc}  ${expected_rc}  msg=${output}
164c9ea9368SGunnar Mills    [Return]  ${output}
1657a212a09SRahul Maheshwari
1663ef2e92cSMichael Walsh
1673ef2e92cSMichael WalshRun External IPMI Raw Command
1683ef2e92cSMichael Walsh    [Documentation]  Run the external IPMI raw command.
1693ef2e92cSMichael Walsh    [Arguments]  ${command}  ${fail_on_err}=${1}  &{options}
1703ef2e92cSMichael Walsh
1713ef2e92cSMichael Walsh    # This keyword is a wrapper for 'Run External IPMI Standard Command'. See
1723ef2e92cSMichael Walsh    # that keyword's prolog for argument details.  This keyword will pre-pend
1733ef2e92cSMichael Walsh    # the word "raw" plus a space to command prior to calling 'Run External
1743ef2e92cSMichael Walsh    # IPMI Standard Command'.
1753ef2e92cSMichael Walsh
1763ef2e92cSMichael Walsh    ${output}=  Run External IPMI Standard Command
1773ef2e92cSMichael Walsh    ...  raw ${command}  ${fail_on_err}  &{options}
1783ef2e92cSMichael Walsh    [Return]  ${output}
1793ef2e92cSMichael Walsh
1803ef2e92cSMichael Walsh
181ae7c2281SPrashanth KattiCheck If IPMI Tool Exist
182ae7c2281SPrashanth Katti    [Documentation]  Check if IPMI Tool installed or not.
183ae7c2281SPrashanth Katti    ${output}=  Execute Command  which ipmitool
184ae7c2281SPrashanth Katti    Should Not Be Empty  ${output}  msg=ipmitool not installed.
1857a212a09SRahul Maheshwari
18604a2204bSRahul Maheshwari
18704a2204bSRahul MaheshwariActivate SOL Via IPMI
18804a2204bSRahul Maheshwari    [Documentation]  Start SOL using IPMI and route output to a file.
18904a2204bSRahul Maheshwari    [Arguments]  ${file_path}=/tmp/sol_${OPENBMC_HOST}
1903ef2e92cSMichael Walsh
19104a2204bSRahul Maheshwari    # Description of argument(s):
1923ef2e92cSMichael Walsh    # file_path                     The file path on the local machine (vs.
1933ef2e92cSMichael Walsh    #                               OBMC) to collect SOL output. By default
1943ef2e92cSMichael Walsh    #                               SOL output is collected at
19504a2204bSRahul Maheshwari    #                               /tmp/sol_<BMC_IP> else user input location.
19604a2204bSRahul Maheshwari
1973ef2e92cSMichael Walsh    ${ipmi_cmd}=  Create IPMI Ext Command String  sol activate usesolkeepalive
1983ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
1992102f6bfSGeorge Keishing    Start Process  ${ipmi_cmd}  shell=True  stdout=${file_path}
2004f360843SRahul Maheshwari    ...  alias=sol_proc
20104a2204bSRahul Maheshwari
20204a2204bSRahul Maheshwari
20304a2204bSRahul MaheshwariDeactivate SOL Via IPMI
20404a2204bSRahul Maheshwari    [Documentation]  Stop SOL using IPMI and return SOL output.
20504a2204bSRahul Maheshwari    [Arguments]  ${file_path}=/tmp/sol_${OPENBMC_HOST}
2063ef2e92cSMichael Walsh
20704a2204bSRahul Maheshwari    # Description of argument(s):
2083ef2e92cSMichael Walsh    # file_path                     The file path on the local machine to copy
2093ef2e92cSMichael Walsh    #                               SOL output collected by above "Activate
2103ef2e92cSMichael Walsh    #                               SOL Via IPMI" keyword.  By default it
2113ef2e92cSMichael Walsh    #                               copies log from /tmp/sol_<BMC_IP>.
21204a2204bSRahul Maheshwari
2133ef2e92cSMichael Walsh    ${ipmi_cmd}=  Create IPMI Ext Command String  sol deactivate
2143ef2e92cSMichael Walsh    Qprint Issuing  ${ipmi_cmd}
21504a2204bSRahul Maheshwari    ${rc}  ${output}=  Run and Return RC and Output  ${ipmi_cmd}
2164f360843SRahul Maheshwari    Run Keyword If  ${rc} > 0  Run Keywords
2177f48a2c6SRahul Maheshwari    ...  Run Keyword And Ignore Error  Terminate Process  sol_proc
2187f48a2c6SRahul Maheshwari    ...  AND  Return From Keyword  ${output}
21904a2204bSRahul Maheshwari
220aec8b879SGeorge Keishing    ${output}=  OperatingSystem.Get File  ${file_path}  encoding_errors=ignore
22104a2204bSRahul Maheshwari
22204a2204bSRahul Maheshwari    # Logging SOL output for debug purpose.
22304a2204bSRahul Maheshwari    Log  ${output}
22404a2204bSRahul Maheshwari
22504a2204bSRahul Maheshwari    [Return]  ${output}
22604a2204bSRahul Maheshwari
22704a2204bSRahul Maheshwari
228a2dab3c8SSivas SRRByte Conversion
229a2dab3c8SSivas SRR    [Documentation]   Byte Conversion method receives IPMI RAW commands as
230a2dab3c8SSivas SRR    ...               argument in string format.
231a2dab3c8SSivas SRR    ...               Sample argument is as follows
232a2dab3c8SSivas SRR    ...               "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
233a2dab3c8SSivas SRR    ...               0x00"
234a2dab3c8SSivas SRR    ...               IPMI RAW command format is as follows
235a2dab3c8SSivas SRR    ...               <netfn Byte> <cmd Byte> <Data Bytes..>
236a2dab3c8SSivas SRR    ...               This method converts IPMI command format into
237a2dab3c8SSivas SRR    ...               dbus command format  as follows
238a2dab3c8SSivas SRR    ...               <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
239a2dab3c8SSivas SRR    ...               <array:byte:data>
240a2dab3c8SSivas SRR    ...               Sample dbus  Host IPMI Received Message argument
241a2dab3c8SSivas SRR    ...               byte:0x00 byte:0x04 byte:0x00 byte:0x30
242a2dab3c8SSivas SRR    ...               array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
24338032805SGunnar Mills    [Arguments]     ${args}
244a2dab3c8SSivas SRR    ${argLength}=   Get Length  ${args}
245a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   array:byte:
246a2dab3c8SSivas SRR    @{listargs}=   Split String  ${args}
247a2dab3c8SSivas SRR    ${index}=   Set Variable   ${0}
2489a08944dSGeorge Keishing    :FOR  ${word}  IN  @{listargs}
249a2dab3c8SSivas SRR    \    Run Keyword if   ${index} == 0   Set NetFn Byte  ${word}
250a2dab3c8SSivas SRR    \    Run Keyword if   ${index} == 1   Set Cmd Byte    ${word}
251a2dab3c8SSivas SRR    \    Run Keyword if   ${index} > 1    Set Array Byte  ${word}
252a2dab3c8SSivas SRR    \    ${index}=    Set Variable    ${index + 1}
253a2dab3c8SSivas SRR    ${length}=   Get Length  ${arrayByte}
254a2dab3c8SSivas SRR    ${length}=   Evaluate  ${length} - 1
255a2dab3c8SSivas SRR    ${arrayByteLocal}=  Get Substring  ${arrayByte}  0   ${length}
256a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   ${arrayByteLocal}
257a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  byte:0x00   ${netfnByte}  byte:0x00
258a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  ${valueinBytesWithArray}  ${cmdByte}
259a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  ${valueinBytesWithArray} ${arrayByte}
260a2dab3c8SSivas SRR    ${valueinBytesWithoutArray}=   Catenate  byte:0x00 ${netfnByte}  byte:0x00
261a2dab3c8SSivas SRR    ${valueinBytesWithoutArray}=   Catenate  ${valueinBytesWithoutArray} ${cmdByte}
262a2dab3c8SSivas SRR    #   To Check scenario for smaller IPMI raw commands with only 2 arguments
263a2dab3c8SSivas SRR    #   instead of usual 12 arguments.
264a2dab3c8SSivas SRR    #   Sample small IPMI raw command: Run IPMI command 0x06 0x36
265a2dab3c8SSivas SRR    #   If IPMI raw argument length is only 9 then return value in bytes without
266a2dab3c8SSivas SRR    #   array population.
267a2dab3c8SSivas SRR    #   Equivalent dbus-send argument for smaller IPMI raw command:
268a2dab3c8SSivas SRR    #   byte:0x00 byte:0x06 byte:0x00 byte:0x36
269a2dab3c8SSivas SRR    Run Keyword if   ${argLength} == 9     Return from Keyword    ${valueinBytesWithoutArray}
270c9ea9368SGunnar Mills    [Return]    ${valueinBytesWithArray}
271a2dab3c8SSivas SRR
272a2dab3c8SSivas SRR
273a2dab3c8SSivas SRRSet NetFn Byte
274f4a807bfSJoy Onyerikwu    [Documentation]  Set the network function byte.
27538032805SGunnar Mills    [Arguments]    ${word}
276a2dab3c8SSivas SRR    ${netfnByteLocal}=  Catenate   byte:${word}
277a2dab3c8SSivas SRR    Set Global Variable  ${netfnByte}  ${netfnByteLocal}
278a2dab3c8SSivas SRR
2793ef2e92cSMichael Walsh
280a2dab3c8SSivas SRRSet Cmd Byte
281f4a807bfSJoy Onyerikwu    [Documentation]  Set the command byte.
28238032805SGunnar Mills    [Arguments]    ${word}
283a2dab3c8SSivas SRR    ${cmdByteLocal}=  Catenate   byte:${word}
284a2dab3c8SSivas SRR    Set Global Variable  ${cmdByte}  ${cmdByteLocal}
285a2dab3c8SSivas SRR
2863ef2e92cSMichael Walsh
287a2dab3c8SSivas SRRSet Array Byte
288f4a807bfSJoy Onyerikwu    [Documentation]  Set the array byte.
28938032805SGunnar Mills    [Arguments]    ${word}
290a2dab3c8SSivas SRR    ${arrayByteLocal}=   Catenate   SEPARATOR=  ${arrayByte}  ${word}
291a2dab3c8SSivas SRR    ${arrayByteLocal}=   Catenate   SEPARATOR=  ${arrayByteLocal}   ,
292a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   ${arrayByteLocal}
293a2dab3c8SSivas SRR
2943ef2e92cSMichael Walsh
295b29d2e84SChris AustenCopy ipmitool
296f4a807bfSJoy Onyerikwu    [Documentation]  Copy the ipmitool to the BMC.
297f4a807bfSJoy Onyerikwu    ${ipmitool_error}=  Catenate  The ipmitool program could not be found in the tools directory.
298f4a807bfSJoy Onyerikwu    ...  It is not part of the automation code by default. You must manually copy or link the correct openbmc
299f4a807bfSJoy Onyerikwu    ...  version of the tool in to the tools directory in order to run this test suite.
300f4a807bfSJoy Onyerikwu
301f4a807bfSJoy Onyerikwu    OperatingSystem.File Should Exist  tools/ipmitool  msg=${ipmitool_error}
302b29d2e84SChris Austen
303b29d2e84SChris Austen    Import Library      SCPLibrary      WITH NAME       scp
304b29d2e84SChris Austen    scp.Open connection     ${OPENBMC_HOST}     username=${OPENBMC_USERNAME}      password=${OPENBMC_PASSWORD}
305b29d2e84SChris Austen    scp.Put File    tools/ipmitool   /tmp
306b29d2e84SChris Austen    SSHLibrary.Open Connection     ${OPENBMC_HOST}
307b29d2e84SChris Austen    Login   ${OPENBMC_USERNAME}    ${OPENBMC_PASSWORD}
308b29d2e84SChris Austen    Execute Command     chmod +x /tmp/ipmitool
3090c34f69cSSridevi Ramesh
3103ef2e92cSMichael Walsh
3110c34f69cSSridevi RameshInitiate Host Boot Via External IPMI
3120c34f69cSSridevi Ramesh    [Documentation]  Initiate host power on using external IPMI.
313982fee42SRahul Maheshwari    [Arguments]  ${wait}=${1}
3143ef2e92cSMichael Walsh
315982fee42SRahul Maheshwari    # Description of argument(s):
3163ef2e92cSMichael Walsh    # wait                          Indicates that this keyword should wait
3173ef2e92cSMichael Walsh    #                               for host running state.
318982fee42SRahul Maheshwari
3190c34f69cSSridevi Ramesh    ${output}=  Run External IPMI Standard Command  chassis power on
3200c34f69cSSridevi Ramesh    Should Not Contain  ${output}  Error
321982fee42SRahul Maheshwari
322982fee42SRahul Maheshwari    Run Keyword If  '${wait}' == '${0}'  Return From Keyword
323982fee42SRahul Maheshwari    Wait Until Keyword Succeeds  10 min  10 sec  Is Host Running
3240c34f69cSSridevi Ramesh
3253ef2e92cSMichael Walsh
3260c34f69cSSridevi RameshInitiate Host PowerOff Via External IPMI
3270c34f69cSSridevi Ramesh    [Documentation]  Initiate host power off 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 off state.
333982fee42SRahul Maheshwari
3340c34f69cSSridevi Ramesh    ${output}=  Run External IPMI Standard Command  chassis power off
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  3 min  10 sec  Is Host Off
339982fee42SRahul Maheshwari
3403ef2e92cSMichael Walsh
341982fee42SRahul MaheshwariGet Host State Via External IPMI
342982fee42SRahul Maheshwari    [Documentation]  Returns host state using external IPMI.
343982fee42SRahul Maheshwari
344982fee42SRahul Maheshwari    ${output}=  Run External IPMI Standard Command  chassis power status
345982fee42SRahul Maheshwari    Should Not Contain  ${output}  Error
346982fee42SRahul Maheshwari    ${output}=  Fetch From Right  ${output}  ${SPACE}
347982fee42SRahul Maheshwari
348982fee42SRahul Maheshwari    [Return]  ${output}
349b4d4a4aeSGeorge Keishing
350b4d4a4aeSGeorge Keishing
351b4d4a4aeSGeorge KeishingSet BMC Network From Host
352b4d4a4aeSGeorge Keishing    [Documentation]  Set BMC network from host.
353b4d4a4aeSGeorge Keishing    [Arguments]  ${nw_info}
354b4d4a4aeSGeorge Keishing
355b4d4a4aeSGeorge Keishing    # Description of argument(s):
3563ef2e92cSMichael Walsh    # nw_info                       A dictionary containing the network
3573ef2e92cSMichael Walsh    #                               information to apply.
358b4d4a4aeSGeorge Keishing
359b4d4a4aeSGeorge Keishing    Run Inband IPMI Standard Command
360b4d4a4aeSGeorge Keishing    ...  lan set 1 ipaddr ${nw_info['IP Address']}
361b4d4a4aeSGeorge Keishing
362b4d4a4aeSGeorge Keishing    Run Inband IPMI Standard Command
363b4d4a4aeSGeorge Keishing    ...  lan set 1 netmask ${nw_info['Subnet Mask']}
364b4d4a4aeSGeorge Keishing
365b4d4a4aeSGeorge Keishing    Run Inband IPMI Standard Command
366b4d4a4aeSGeorge Keishing    ...  lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}
367c3d1e968SRahul Maheshwari
368c3d1e968SRahul Maheshwari
369c3d1e968SRahul MaheshwariVerify IPMI Username And Password
370c3d1e968SRahul Maheshwari    [Documentation]  Verify that user is able to run IPMI command
371c3d1e968SRahul Maheshwari    ...  with given username and password.
372c3d1e968SRahul Maheshwari    [Arguments]  ${username}  ${password}
373c3d1e968SRahul Maheshwari
374c3d1e968SRahul Maheshwari    # Description of argument(s):
375c3d1e968SRahul Maheshwari    # username    The user name (e.g. "root", "robert", etc.).
376c3d1e968SRahul Maheshwari    # password    The user password (e.g. "0penBmc", "0penBmc1", etc.).
377c3d1e968SRahul Maheshwari
378c3d1e968SRahul Maheshwari    ${output}=  Run External IPMI Standard Command
379c3d1e968SRahul Maheshwari    ...  sel info  U=${username}  P=${password}
380c3d1e968SRahul Maheshwari    Should Contain  ${output}  SEL Information  msg=SEL information not present
38175e91feaSRahul Maheshwari
38275e91feaSRahul Maheshwari
38375e91feaSRahul MaheshwariIPMI Create User
38475e91feaSRahul Maheshwari    [Documentation]  Create IPMI user with given userid and username.
38575e91feaSRahul Maheshwari    [Arguments]  ${userid}  ${username}
38675e91feaSRahul Maheshwari
38775e91feaSRahul Maheshwari    # Description of argument(s):
38875e91feaSRahul Maheshwari    # userid      The user ID (e.g. "1", "2", etc.).
38975e91feaSRahul Maheshwari    # username    The user name (e.g. "root", "robert", etc.).
39075e91feaSRahul Maheshwari
39175e91feaSRahul Maheshwari    ${ipmi_cmd}=  Catenate  user set name ${userid} ${username}
39275e91feaSRahul Maheshwari    ${resp}=  Run IPMI Standard Command  ${ipmi_cmd}
39375e91feaSRahul Maheshwari    ${user_info}=  Get User Info  ${userid}
39475e91feaSRahul Maheshwari    Should Be Equal  ${user_info['user_name']}  ${username}
39575e91feaSRahul Maheshwari
39675e91feaSRahul Maheshwari
39775e91feaSRahul MaheshwariSet Channel Access
39875e91feaSRahul Maheshwari    [Documentation]  Verify that user is able to run IPMI command
39975e91feaSRahul Maheshwari    ...  with given username and password.
400*7c5f4b28STony Lee    [Arguments]  ${userid}  ${options}  ${channel_number}=${CHANNEL_NUMBER}
40175e91feaSRahul Maheshwari
40275e91feaSRahul Maheshwari    # Description of argument(s):
40375e91feaSRahul Maheshwari    # userid          The user ID (e.g. "1", "2", etc.).
40475e91feaSRahul Maheshwari    # options         Set channel command options (e.g.
40575e91feaSRahul Maheshwari    #                 "link=on", "ipmi=on", etc.).
40675e91feaSRahul Maheshwari    # channel_number  The user's channel number (e.g. "1").
40775e91feaSRahul Maheshwari
40875e91feaSRahul Maheshwari    ${ipmi_cmd}=  Catenate  SEPARATOR=
409*7c5f4b28STony Lee    ...  channel setaccess${SPACE}${channel_number}${SPACE}${userid}
41075e91feaSRahul Maheshwari    ...  ${SPACE}${options}
41175e91feaSRahul Maheshwari    Run IPMI Standard Command  ${ipmi_cmd}
4123e61ce66SRahul Maheshwari
4133e61ce66SRahul Maheshwari
4143e61ce66SRahul MaheshwariDelete All Non Root IPMI User
4153e61ce66SRahul Maheshwari    [Documentation]  Delete all non-root IPMI user.
4163e61ce66SRahul Maheshwari
4173e61ce66SRahul Maheshwari    FOR  ${userid}  IN RANGE  2  16
4183e61ce66SRahul Maheshwari      ${user_info}=  Get User Info  ${userid}
4193e61ce66SRahul Maheshwari      Run Keyword If  "${user_info['user_name']}" != ""
4203e61ce66SRahul Maheshwari      ...  Run IPMI Standard Command  user set name ${userid} ""
421bb3d21c0SRahul Maheshwari      Sleep  5s
4223e61ce66SRahul Maheshwari    END
423