xref: /openbmc/openbmc-test-automation/lib/ipmi_client.robot (revision c9ea936869d1dd90f80e4c20763cdecc8c7f60e1)
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
5b29d2e84SChris AustenResource        ../lib/resource.txt
64d6c1dabSGeorge KeishingResource        ../lib/connection_client.robot
7a2dab3c8SSivas SRRLibrary         String
8a2dab3c8SSivas SRR
9a2dab3c8SSivas SRR*** Variables ***
10a2dab3c8SSivas SRR${dbusHostIpmicmd1}=   dbus-send --system  /org/openbmc/HostIpmi/1
11a2dab3c8SSivas SRR${dbusHostIpmiCmdReceivedMsg}=   org.openbmc.HostIpmi.ReceivedMessage
12a2dab3c8SSivas SRR${netfnByte}=          ${EMPTY}
13a2dab3c8SSivas SRR${cmdByte}   =          ${EMPTY}
14a2dab3c8SSivas SRR${arrayByte}=          array:byte:
157a212a09SRahul Maheshwari${IPMI_EXT_CMD}=       ipmitool -I lanplus -C 1 -P
167a212a09SRahul Maheshwari${HOST}=               -H
177a212a09SRahul Maheshwari${RAW}=                raw
18b29d2e84SChris Austen
19b29d2e84SChris Austen*** Keywords ***
207a212a09SRahul Maheshwari
21b29d2e84SChris AustenRun IPMI Command
2238032805SGunnar Mills    [Arguments]    ${args}
237a212a09SRahul Maheshwari    ${resp}=     Run Keyword If   '${IPMI_COMMAND}'=='External'
247a212a09SRahul Maheshwari    ...    Run External IPMI RAW Command   ${args}
257a212a09SRahul Maheshwari    ...          ELSE IF          '${IPMI_COMMAND}'=='Dbus'
267a212a09SRahul Maheshwari    ...    Run Dbus IPMI RAW Command   ${args}
277a212a09SRahul Maheshwari    ...          ELSE             Fail
287a212a09SRahul Maheshwari    ...    msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
29*c9ea9368SGunnar Mills    [Return]    ${resp}
307a212a09SRahul Maheshwari
317a212a09SRahul MaheshwariRun IPMI Standard Command
3238032805SGunnar Mills    [Arguments]    ${args}
337a212a09SRahul Maheshwari    ${resp}=     Run Keyword If   '${IPMI_COMMAND}'=='External'
347a212a09SRahul Maheshwari    ...    Run External IPMI Standard Command   ${args}
357a212a09SRahul Maheshwari    ...          ELSE IF          '${IPMI_COMMAND}'=='Dbus'
367a212a09SRahul Maheshwari    ...    Run Dbus IPMI Standard Command   ${args}
377a212a09SRahul Maheshwari    ...          ELSE             Fail
387a212a09SRahul Maheshwari    ...    msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
397a212a09SRahul Maheshwari
40*c9ea9368SGunnar Mills    [Return]    ${resp}
417a212a09SRahul Maheshwari
427a212a09SRahul MaheshwariRun Dbus IPMI RAW Command
4338032805SGunnar Mills    [Arguments]    ${args}
44a2dab3c8SSivas SRR    ${valueinBytes}=   Byte Conversion  ${args}
45a2dab3c8SSivas SRR    ${cmd}=   Catenate   ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
46a2dab3c8SSivas SRR    ${cmd}=   Catenate   ${cmd} ${valueinBytes}
47a2dab3c8SSivas SRR    ${output}   ${stderr}=  Execute Command  ${cmd}  return_stderr=True
48b29d2e84SChris Austen    Should Be Empty      ${stderr}
49b29d2e84SChris Austen    set test variable    ${OUTPUT}     "${output}"
50b29d2e84SChris Austen
517a212a09SRahul MaheshwariRun Dbus IPMI Standard Command
5238032805SGunnar Mills    [Arguments]    ${args}
534d6c1dabSGeorge Keishing    Copy ipmitool
547a212a09SRahul Maheshwari    ${stdout}    ${stderr}    ${output}=  Execute Command
557a212a09SRahul Maheshwari    ...    /tmp/ipmitool -I dbus ${args}    return_stdout=True
567a212a09SRahul Maheshwari    ...    return_stderr= True    return_rc=True
57b29d2e84SChris Austen    Should Be Equal    ${output}    ${0}    msg=${stderr}
58*c9ea9368SGunnar Mills    [Return]    ${stdout}
59b29d2e84SChris Austen
607a212a09SRahul MaheshwariRun External IPMI RAW Command
6138032805SGunnar Mills    [Arguments]    ${args}
627a212a09SRahul Maheshwari    ${ipmi_raw_cmd}=   Catenate  SEPARATOR=
637a212a09SRahul Maheshwari    ...    ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE}
647a212a09SRahul Maheshwari    ...    ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args}
657a212a09SRahul Maheshwari    ${rc}    ${output}=    Run and Return RC and Output    ${ipmi_raw_cmd}
667a212a09SRahul Maheshwari    Should Be Equal    ${rc}    ${0}    msg=${output}
67*c9ea9368SGunnar Mills    [Return]    ${output}
687a212a09SRahul Maheshwari
697a212a09SRahul MaheshwariRun External IPMI Standard Command
7038032805SGunnar Mills    [Arguments]    ${args}
717a212a09SRahul Maheshwari    ${ipmi_cmd}=   Catenate  SEPARATOR=
727a212a09SRahul Maheshwari    ...    ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE}
737a212a09SRahul Maheshwari    ...    ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args}
747a212a09SRahul Maheshwari    ${rc}    ${output}=    Run and Return RC and Output    ${ipmi_cmd}
757a212a09SRahul Maheshwari    Should Be Equal    ${rc}    ${0}    msg=${output}
76*c9ea9368SGunnar Mills    [Return]   ${output}
777a212a09SRahul Maheshwari
787a212a09SRahul Maheshwari
79a2dab3c8SSivas SRRByte Conversion
80a2dab3c8SSivas SRR    [Documentation]   Byte Conversion method receives IPMI RAW commands as
81a2dab3c8SSivas SRR    ...               argument in string format.
82a2dab3c8SSivas SRR    ...               Sample argument is as follows
83a2dab3c8SSivas SRR    ...               "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
84a2dab3c8SSivas SRR    ...               0x00"
85a2dab3c8SSivas SRR    ...               IPMI RAW command format is as follows
86a2dab3c8SSivas SRR    ...               <netfn Byte> <cmd Byte> <Data Bytes..>
87a2dab3c8SSivas SRR    ...               This method converts IPMI command format into
88a2dab3c8SSivas SRR    ...               dbus command format  as follows
89a2dab3c8SSivas SRR    ...               <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
90a2dab3c8SSivas SRR    ...               <array:byte:data>
91a2dab3c8SSivas SRR    ...               Sample dbus  Host IPMI Received Message argument
92a2dab3c8SSivas SRR    ...               byte:0x00 byte:0x04 byte:0x00 byte:0x30
93a2dab3c8SSivas SRR    ...               array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
9438032805SGunnar Mills    [Arguments]     ${args}
95a2dab3c8SSivas SRR    ${argLength}=   Get Length  ${args}
96a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   array:byte:
97a2dab3c8SSivas SRR    @{listargs}=   Split String  ${args}
98a2dab3c8SSivas SRR    ${index}=   Set Variable   ${0}
99a2dab3c8SSivas SRR    :FOR   ${word}   in   @{listargs}
100a2dab3c8SSivas SRR    \    Run Keyword if   ${index} == 0   Set NetFn Byte  ${word}
101a2dab3c8SSivas SRR    \    Run Keyword if   ${index} == 1   Set Cmd Byte    ${word}
102a2dab3c8SSivas SRR    \    Run Keyword if   ${index} > 1    Set Array Byte  ${word}
103a2dab3c8SSivas SRR    \    ${index}=    Set Variable    ${index + 1}
104a2dab3c8SSivas SRR    ${length}=   Get Length  ${arrayByte}
105a2dab3c8SSivas SRR    ${length}=   Evaluate  ${length} - 1
106a2dab3c8SSivas SRR    ${arrayByteLocal}=  Get Substring  ${arrayByte}  0   ${length}
107a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   ${arrayByteLocal}
108a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  byte:0x00   ${netfnByte}  byte:0x00
109a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  ${valueinBytesWithArray}  ${cmdByte}
110a2dab3c8SSivas SRR    ${valueinBytesWithArray}=   Catenate  ${valueinBytesWithArray} ${arrayByte}
111a2dab3c8SSivas SRR    ${valueinBytesWithoutArray}=   Catenate  byte:0x00 ${netfnByte}  byte:0x00
112a2dab3c8SSivas SRR    ${valueinBytesWithoutArray}=   Catenate  ${valueinBytesWithoutArray} ${cmdByte}
113a2dab3c8SSivas SRR#   To Check scenario for smaller IPMI raw commands with only 2 arguments
114a2dab3c8SSivas SRR#   instead of usual 12 arguments.
115a2dab3c8SSivas SRR#   Sample small IPMI raw command: Run IPMI command 0x06 0x36
116a2dab3c8SSivas SRR#   If IPMI raw argument length is only 9 then return value in bytes without
117a2dab3c8SSivas SRR#   array population.
118a2dab3c8SSivas SRR#   Equivalent dbus-send argument for smaller IPMI raw command:
119a2dab3c8SSivas SRR#   byte:0x00 byte:0x06 byte:0x00 byte:0x36
120a2dab3c8SSivas SRR    Run Keyword if   ${argLength} == 9     Return from Keyword    ${valueinBytesWithoutArray}
121*c9ea9368SGunnar Mills    [Return]    ${valueinBytesWithArray}
122a2dab3c8SSivas SRR
123a2dab3c8SSivas SRR
124a2dab3c8SSivas SRRSet NetFn Byte
12538032805SGunnar Mills   [Arguments]    ${word}
126a2dab3c8SSivas SRR   ${netfnByteLocal}=  Catenate   byte:${word}
127a2dab3c8SSivas SRR   Set Global Variable  ${netfnByte}  ${netfnByteLocal}
128a2dab3c8SSivas SRR
129a2dab3c8SSivas SRRSet Cmd Byte
13038032805SGunnar Mills   [Arguments]    ${word}
131a2dab3c8SSivas SRR   ${cmdByteLocal}=  Catenate   byte:${word}
132a2dab3c8SSivas SRR   Set Global Variable  ${cmdByte}  ${cmdByteLocal}
133a2dab3c8SSivas SRR
134a2dab3c8SSivas SRRSet Array Byte
13538032805SGunnar Mills   [Arguments]    ${word}
136a2dab3c8SSivas SRR   ${arrayByteLocal}=   Catenate   SEPARATOR=  ${arrayByte}  ${word}
137a2dab3c8SSivas SRR   ${arrayByteLocal}=   Catenate   SEPARATOR=  ${arrayByteLocal}   ,
138a2dab3c8SSivas SRR   Set Global Variable  ${arrayByte}   ${arrayByteLocal}
139a2dab3c8SSivas SRR
140b29d2e84SChris AustenCopy ipmitool
141b29d2e84SChris Austen    OperatingSystem.File Should Exist   tools/ipmitool      msg=The ipmitool program could not be found in the tools directory. It is not part of the automation code by default. You must manually copy or link the correct openbmc version of the tool in to the tools directory in order to run this test suite.
142b29d2e84SChris Austen
143b29d2e84SChris Austen    Import Library      SCPLibrary      WITH NAME       scp
144b29d2e84SChris Austen    scp.Open connection     ${OPENBMC_HOST}     username=${OPENBMC_USERNAME}      password=${OPENBMC_PASSWORD}
145b29d2e84SChris Austen    scp.Put File    tools/ipmitool   /tmp
146b29d2e84SChris Austen    SSHLibrary.Open Connection     ${OPENBMC_HOST}
147b29d2e84SChris Austen    Login   ${OPENBMC_USERNAME}    ${OPENBMC_PASSWORD}
148b29d2e84SChris Austen    Execute Command     chmod +x /tmp/ipmitool
149