xref: /openbmc/openbmc-test-automation/lib/ipmi_client.robot (revision a2dab3c84abc2e751119b613752bd9b372971d5d)
1b29d2e84SChris Austen*** Settings ***
2b29d2e84SChris AustenDocumentation   This module is for IPMI client for copying ipmitool to
3*a2dab3c8SSivas SRR...             openbmc box and execute ipmitool IPMI standard
4*a2dab3c8SSivas SRR...             command. IPMI raw command will use dbus-send command
5b29d2e84SChris AustenResource        ../lib/resource.txt
64d6c1dabSGeorge KeishingResource        ../lib/connection_client.robot
7*a2dab3c8SSivas SRRLibrary         String
8*a2dab3c8SSivas SRR
9*a2dab3c8SSivas SRR*** Variables ***
10*a2dab3c8SSivas SRR${dbusHostIpmicmd1} =   dbus-send --system  /org/openbmc/HostIpmi/1
11*a2dab3c8SSivas SRR${dbusHostIpmiCmdReceivedMsg} =   org.openbmc.HostIpmi.ReceivedMessage
12*a2dab3c8SSivas SRR${netfnByte} =    ${EMPTY}
13*a2dab3c8SSivas SRR${cmdByte}   =    ${EMPTY}
14*a2dab3c8SSivas SRR${arrayByte} =       array:byte:
15b29d2e84SChris Austen
16b29d2e84SChris Austen*** Keywords ***
17b29d2e84SChris AustenRun IPMI Command
18b29d2e84SChris Austen    [arguments]    ${args}
19*a2dab3c8SSivas SRR    ${valueinBytes} =   Byte Conversion  ${args}
20*a2dab3c8SSivas SRR    ${cmd} =   Catenate   ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
21*a2dab3c8SSivas SRR    ${cmd} =   Catenate   ${cmd} ${valueinBytes}
22*a2dab3c8SSivas SRR    ${output}   ${stderr}=  Execute Command  ${cmd}  return_stderr=True
23b29d2e84SChris Austen    Should Be Empty      ${stderr}
24b29d2e84SChris Austen    set test variable    ${OUTPUT}     "${output}"
25b29d2e84SChris Austen
26b29d2e84SChris AustenRun IPMI Standard Command
27b29d2e84SChris Austen    [arguments]    ${args}
284d6c1dabSGeorge Keishing    Copy ipmitool
29b29d2e84SChris Austen    ${stdout}    ${stderr}    ${output}=  Execute Command    /tmp/ipmitool -I dbus ${args}    return_stdout=True    return_stderr= True    return_rc=True
30b29d2e84SChris Austen    Should Be Equal    ${output}    ${0}    msg=${stderr}
31b29d2e84SChris Austen    [return]    ${stdout}
32b29d2e84SChris Austen
33*a2dab3c8SSivas SRRByte Conversion
34*a2dab3c8SSivas SRR    [Documentation]   Byte Conversion method receives IPMI RAW commands as
35*a2dab3c8SSivas SRR    ...               argument in string format.
36*a2dab3c8SSivas SRR    ...               Sample argument is as follows
37*a2dab3c8SSivas SRR    ...               "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
38*a2dab3c8SSivas SRR    ...               0x00"
39*a2dab3c8SSivas SRR    ...               IPMI RAW command format is as follows
40*a2dab3c8SSivas SRR    ...               <netfn Byte> <cmd Byte> <Data Bytes..>
41*a2dab3c8SSivas SRR    ...               This method converts IPMI command format into
42*a2dab3c8SSivas SRR    ...               dbus command format  as follows
43*a2dab3c8SSivas SRR    ...               <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
44*a2dab3c8SSivas SRR    ...               <array:byte:data>
45*a2dab3c8SSivas SRR    ...               Sample dbus  Host IPMI Received Message argument
46*a2dab3c8SSivas SRR    ...               byte:0x00 byte:0x04 byte:0x00 byte:0x30
47*a2dab3c8SSivas SRR    ...               array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
48*a2dab3c8SSivas SRR    [arguments]     ${args}
49*a2dab3c8SSivas SRR    ${argLength} =   Get Length  ${args}
50*a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   array:byte:
51*a2dab3c8SSivas SRR    @{listargs} =   Split String  ${args}
52*a2dab3c8SSivas SRR    ${index} =   Set Variable   ${0}
53*a2dab3c8SSivas SRR    :FOR   ${word}   in   @{listargs}
54*a2dab3c8SSivas SRR    \    Run Keyword if   ${index} == 0   Set NetFn Byte  ${word}
55*a2dab3c8SSivas SRR    \    Run Keyword if   ${index} == 1   Set Cmd Byte    ${word}
56*a2dab3c8SSivas SRR    \    Run Keyword if   ${index} > 1    Set Array Byte  ${word}
57*a2dab3c8SSivas SRR    \    ${index} =    Set Variable    ${index + 1}
58*a2dab3c8SSivas SRR    ${length} =   Get Length  ${arrayByte}
59*a2dab3c8SSivas SRR    ${length} =   Evaluate  ${length} - 1
60*a2dab3c8SSivas SRR    ${arrayByteLocal} =  Get Substring  ${arrayByte}  0   ${length}
61*a2dab3c8SSivas SRR    Set Global Variable  ${arrayByte}   ${arrayByteLocal}
62*a2dab3c8SSivas SRR    ${valueinBytesWithArray} =   Catenate  byte:0x00   ${netfnByte}  byte:0x00
63*a2dab3c8SSivas SRR    ${valueinBytesWithArray} =   Catenate  ${valueinBytesWithArray}  ${cmdByte}
64*a2dab3c8SSivas SRR    ${valueinBytesWithArray} =   Catenate  ${valueinBytesWithArray} ${arrayByte}
65*a2dab3c8SSivas SRR    ${valueinBytesWithoutArray} =   Catenate  byte:0x00 ${netfnByte}  byte:0x00
66*a2dab3c8SSivas SRR    ${valueinBytesWithoutArray} =   Catenate  ${valueinBytesWithoutArray} ${cmdByte}
67*a2dab3c8SSivas SRR#   To Check scenario for smaller IPMI raw commands with only 2 arguments
68*a2dab3c8SSivas SRR#   instead of usual 12 arguments.
69*a2dab3c8SSivas SRR#   Sample small IPMI raw command: Run IPMI command 0x06 0x36
70*a2dab3c8SSivas SRR#   If IPMI raw argument length is only 9 then return value in bytes without
71*a2dab3c8SSivas SRR#   array population.
72*a2dab3c8SSivas SRR#   Equivalent dbus-send argument for smaller IPMI raw command:
73*a2dab3c8SSivas SRR#   byte:0x00 byte:0x06 byte:0x00 byte:0x36
74*a2dab3c8SSivas SRR    Run Keyword if   ${argLength} == 9     Return from Keyword    ${valueinBytesWithoutArray}
75*a2dab3c8SSivas SRR    [return]    ${valueinBytesWithArray}
76*a2dab3c8SSivas SRR
77*a2dab3c8SSivas SRR
78*a2dab3c8SSivas SRRSet NetFn Byte
79*a2dab3c8SSivas SRR   [arguments]    ${word}
80*a2dab3c8SSivas SRR   ${netfnByteLocal} =  Catenate   byte:${word}
81*a2dab3c8SSivas SRR   Set Global Variable  ${netfnByte}  ${netfnByteLocal}
82*a2dab3c8SSivas SRR
83*a2dab3c8SSivas SRRSet Cmd Byte
84*a2dab3c8SSivas SRR   [arguments]    ${word}
85*a2dab3c8SSivas SRR   ${cmdByteLocal} =  Catenate   byte:${word}
86*a2dab3c8SSivas SRR   Set Global Variable  ${cmdByte}  ${cmdByteLocal}
87*a2dab3c8SSivas SRR
88*a2dab3c8SSivas SRRSet Array Byte
89*a2dab3c8SSivas SRR   [arguments]    ${word}
90*a2dab3c8SSivas SRR   ${arrayByteLocal} =   Catenate   SEPARATOR=  ${arrayByte}  ${word}
91*a2dab3c8SSivas SRR   ${arrayByteLocal} =   Catenate   SEPARATOR=  ${arrayByteLocal}   ,
92*a2dab3c8SSivas SRR   Set Global Variable  ${arrayByte}   ${arrayByteLocal}
93*a2dab3c8SSivas SRR
94b29d2e84SChris AustenCopy ipmitool
95b29d2e84SChris 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.
96b29d2e84SChris Austen
97b29d2e84SChris Austen    Import Library      SCPLibrary      WITH NAME       scp
98b29d2e84SChris Austen    scp.Open connection     ${OPENBMC_HOST}     username=${OPENBMC_USERNAME}      password=${OPENBMC_PASSWORD}
99b29d2e84SChris Austen    scp.Put File    tools/ipmitool   /tmp
100b29d2e84SChris Austen    SSHLibrary.Open Connection     ${OPENBMC_HOST}
101b29d2e84SChris Austen    Login   ${OPENBMC_USERNAME}    ${OPENBMC_PASSWORD}
102b29d2e84SChris Austen    Execute Command     chmod +x /tmp/ipmitool
103