xref: /openbmc/openbmc-test-automation/lib/ipmi_client.robot (revision 7a212a0938a5959d6314c947a7d355b307a1cc98)
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:
15*7a212a09SRahul Maheshwari${IPMI_EXT_CMD} =       ipmitool -I lanplus -C 1 -P
16*7a212a09SRahul Maheshwari${HOST} =               -H
17*7a212a09SRahul Maheshwari${RAW} =                raw
18b29d2e84SChris Austen
19b29d2e84SChris Austen*** Keywords ***
20*7a212a09SRahul Maheshwari
21b29d2e84SChris AustenRun IPMI Command
22b29d2e84SChris Austen    [arguments]    ${args}
23*7a212a09SRahul Maheshwari    ${resp}=     Run Keyword If   '${IPMI_COMMAND}'=='External'
24*7a212a09SRahul Maheshwari    ...    Run External IPMI RAW Command   ${args}
25*7a212a09SRahul Maheshwari    ...          ELSE IF          '${IPMI_COMMAND}'=='Dbus'
26*7a212a09SRahul Maheshwari    ...    Run Dbus IPMI RAW Command   ${args}
27*7a212a09SRahul Maheshwari    ...          ELSE             Fail
28*7a212a09SRahul Maheshwari    ...    msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
29*7a212a09SRahul Maheshwari    [return]    ${resp}
30*7a212a09SRahul Maheshwari
31*7a212a09SRahul MaheshwariRun IPMI Standard Command
32*7a212a09SRahul Maheshwari    [arguments]    ${args}
33*7a212a09SRahul Maheshwari    ${resp}=     Run Keyword If   '${IPMI_COMMAND}'=='External'
34*7a212a09SRahul Maheshwari    ...    Run External IPMI Standard Command   ${args}
35*7a212a09SRahul Maheshwari    ...          ELSE IF          '${IPMI_COMMAND}'=='Dbus'
36*7a212a09SRahul Maheshwari    ...    Run Dbus IPMI Standard Command   ${args}
37*7a212a09SRahul Maheshwari    ...          ELSE             Fail
38*7a212a09SRahul Maheshwari    ...    msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
39*7a212a09SRahul Maheshwari
40*7a212a09SRahul Maheshwari    [return]    ${resp}
41*7a212a09SRahul Maheshwari
42*7a212a09SRahul MaheshwariRun Dbus IPMI RAW Command
43*7a212a09SRahul Maheshwari    [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
51*7a212a09SRahul MaheshwariRun Dbus IPMI Standard Command
52b29d2e84SChris Austen    [arguments]    ${args}
534d6c1dabSGeorge Keishing    Copy ipmitool
54*7a212a09SRahul Maheshwari    ${stdout}    ${stderr}    ${output}=  Execute Command
55*7a212a09SRahul Maheshwari    ...    /tmp/ipmitool -I dbus ${args}    return_stdout=True
56*7a212a09SRahul Maheshwari    ...    return_stderr= True    return_rc=True
57b29d2e84SChris Austen    Should Be Equal    ${output}    ${0}    msg=${stderr}
58b29d2e84SChris Austen    [return]    ${stdout}
59b29d2e84SChris Austen
60*7a212a09SRahul MaheshwariRun External IPMI RAW Command
61*7a212a09SRahul Maheshwari    [arguments]    ${args}
62*7a212a09SRahul Maheshwari    ${ipmi_raw_cmd}=   Catenate  SEPARATOR=
63*7a212a09SRahul Maheshwari    ...    ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE}
64*7a212a09SRahul Maheshwari    ...    ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args}
65*7a212a09SRahul Maheshwari    ${rc}    ${output}=    Run and Return RC and Output    ${ipmi_raw_cmd}
66*7a212a09SRahul Maheshwari    Should Be Equal    ${rc}    ${0}    msg=${output}
67*7a212a09SRahul Maheshwari    [return]    ${output}
68*7a212a09SRahul Maheshwari
69*7a212a09SRahul MaheshwariRun External IPMI Standard Command
70*7a212a09SRahul Maheshwari    [arguments]    ${args}
71*7a212a09SRahul Maheshwari    ${ipmi_cmd}=   Catenate  SEPARATOR=
72*7a212a09SRahul Maheshwari    ...    ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE}
73*7a212a09SRahul Maheshwari    ...    ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args}
74*7a212a09SRahul Maheshwari    ${rc}    ${output}=    Run and Return RC and Output    ${ipmi_cmd}
75*7a212a09SRahul Maheshwari    Should Be Equal    ${rc}    ${0}    msg=${output}
76*7a212a09SRahul Maheshwari    [return]   ${output}
77*7a212a09SRahul Maheshwari
78*7a212a09SRahul 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
94a2dab3c8SSivas SRR    [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}
121a2dab3c8SSivas SRR    [return]    ${valueinBytesWithArray}
122a2dab3c8SSivas SRR
123a2dab3c8SSivas SRR
124a2dab3c8SSivas SRRSet NetFn Byte
125a2dab3c8SSivas SRR   [arguments]    ${word}
126a2dab3c8SSivas SRR   ${netfnByteLocal} =  Catenate   byte:${word}
127a2dab3c8SSivas SRR   Set Global Variable  ${netfnByte}  ${netfnByteLocal}
128a2dab3c8SSivas SRR
129a2dab3c8SSivas SRRSet Cmd Byte
130a2dab3c8SSivas SRR   [arguments]    ${word}
131a2dab3c8SSivas SRR   ${cmdByteLocal} =  Catenate   byte:${word}
132a2dab3c8SSivas SRR   Set Global Variable  ${cmdByte}  ${cmdByteLocal}
133a2dab3c8SSivas SRR
134a2dab3c8SSivas SRRSet Array Byte
135a2dab3c8SSivas SRR   [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