Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | *** Settings *** |
George Keishing | 4d6c1da | 2016-07-15 05:51:22 -0500 | [diff] [blame] | 2 | Documentation This module is for IPMI client for copying ipmitool to |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 3 | ... openbmc box and execute ipmitool IPMI standard |
| 4 | ... command. IPMI raw command will use dbus-send command |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 5 | Resource ../lib/resource.txt |
George Keishing | 4d6c1da | 2016-07-15 05:51:22 -0500 | [diff] [blame] | 6 | Resource ../lib/connection_client.robot |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 7 | Library String |
| 8 | |
| 9 | *** Variables *** |
| 10 | ${dbusHostIpmicmd1} = dbus-send --system /org/openbmc/HostIpmi/1 |
| 11 | ${dbusHostIpmiCmdReceivedMsg} = org.openbmc.HostIpmi.ReceivedMessage |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 12 | ${netfnByte} = ${EMPTY} |
| 13 | ${cmdByte} = ${EMPTY} |
| 14 | ${arrayByte} = array:byte: |
| 15 | ${IPMI_EXT_CMD} = ipmitool -I lanplus -C 1 -P |
| 16 | ${HOST} = -H |
| 17 | ${RAW} = raw |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 18 | |
| 19 | *** Keywords *** |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 20 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 21 | Run IPMI Command |
| 22 | [arguments] ${args} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 23 | ${resp}= Run Keyword If '${IPMI_COMMAND}'=='External' |
| 24 | ... Run External IPMI RAW Command ${args} |
| 25 | ... ELSE IF '${IPMI_COMMAND}'=='Dbus' |
| 26 | ... Run Dbus IPMI RAW Command ${args} |
| 27 | ... ELSE Fail |
| 28 | ... msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} |
| 29 | [return] ${resp} |
| 30 | |
| 31 | Run IPMI Standard Command |
| 32 | [arguments] ${args} |
| 33 | ${resp}= Run Keyword If '${IPMI_COMMAND}'=='External' |
| 34 | ... Run External IPMI Standard Command ${args} |
| 35 | ... ELSE IF '${IPMI_COMMAND}'=='Dbus' |
| 36 | ... Run Dbus IPMI Standard Command ${args} |
| 37 | ... ELSE Fail |
| 38 | ... msg=Invalid IPMI Command type provided : ${IPMI_COMMAND} |
| 39 | |
| 40 | [return] ${resp} |
| 41 | |
| 42 | Run Dbus IPMI RAW Command |
| 43 | [arguments] ${args} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 44 | ${valueinBytes} = Byte Conversion ${args} |
| 45 | ${cmd} = Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg} |
| 46 | ${cmd} = Catenate ${cmd} ${valueinBytes} |
| 47 | ${output} ${stderr}= Execute Command ${cmd} return_stderr=True |
| 48 | Should Be Empty ${stderr} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 49 | set test variable ${OUTPUT} "${output}" |
| 50 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 51 | Run Dbus IPMI Standard Command |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 52 | [arguments] ${args} |
George Keishing | 4d6c1da | 2016-07-15 05:51:22 -0500 | [diff] [blame] | 53 | Copy ipmitool |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 54 | ${stdout} ${stderr} ${output}= Execute Command |
| 55 | ... /tmp/ipmitool -I dbus ${args} return_stdout=True |
| 56 | ... return_stderr= True return_rc=True |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 57 | Should Be Equal ${output} ${0} msg=${stderr} |
| 58 | [return] ${stdout} |
| 59 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 60 | Run External IPMI RAW Command |
| 61 | [arguments] ${args} |
| 62 | ${ipmi_raw_cmd}= Catenate SEPARATOR= |
| 63 | ... ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE} |
| 64 | ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args} |
| 65 | ${rc} ${output}= Run and Return RC and Output ${ipmi_raw_cmd} |
| 66 | Should Be Equal ${rc} ${0} msg=${output} |
| 67 | [return] ${output} |
| 68 | |
| 69 | Run External IPMI Standard Command |
| 70 | [arguments] ${args} |
| 71 | ${ipmi_cmd}= Catenate SEPARATOR= |
| 72 | ... ${IPMI_EXT_CMD}${SPACE}${IPMI_PASSWORD}${SPACE} |
| 73 | ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args} |
| 74 | ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd} |
| 75 | Should Be Equal ${rc} ${0} msg=${output} |
| 76 | [return] ${output} |
| 77 | |
| 78 | |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 79 | Byte Conversion |
| 80 | [Documentation] Byte Conversion method receives IPMI RAW commands as |
| 81 | ... argument in string format. |
| 82 | ... Sample argument is as follows |
| 83 | ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00 |
| 84 | ... 0x00" |
| 85 | ... IPMI RAW command format is as follows |
| 86 | ... <netfn Byte> <cmd Byte> <Data Bytes..> |
| 87 | ... This method converts IPMI command format into |
| 88 | ... dbus command format as follows |
| 89 | ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd> |
| 90 | ... <array:byte:data> |
| 91 | ... Sample dbus Host IPMI Received Message argument |
| 92 | ... byte:0x00 byte:0x04 byte:0x00 byte:0x30 |
| 93 | ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00 |
| 94 | [arguments] ${args} |
| 95 | ${argLength} = Get Length ${args} |
| 96 | Set Global Variable ${arrayByte} array:byte: |
| 97 | @{listargs} = Split String ${args} |
| 98 | ${index} = Set Variable ${0} |
| 99 | :FOR ${word} in @{listargs} |
| 100 | \ Run Keyword if ${index} == 0 Set NetFn Byte ${word} |
| 101 | \ Run Keyword if ${index} == 1 Set Cmd Byte ${word} |
| 102 | \ Run Keyword if ${index} > 1 Set Array Byte ${word} |
| 103 | \ ${index} = Set Variable ${index + 1} |
| 104 | ${length} = Get Length ${arrayByte} |
| 105 | ${length} = Evaluate ${length} - 1 |
| 106 | ${arrayByteLocal} = Get Substring ${arrayByte} 0 ${length} |
| 107 | Set Global Variable ${arrayByte} ${arrayByteLocal} |
| 108 | ${valueinBytesWithArray} = Catenate byte:0x00 ${netfnByte} byte:0x00 |
| 109 | ${valueinBytesWithArray} = Catenate ${valueinBytesWithArray} ${cmdByte} |
| 110 | ${valueinBytesWithArray} = Catenate ${valueinBytesWithArray} ${arrayByte} |
| 111 | ${valueinBytesWithoutArray} = Catenate byte:0x00 ${netfnByte} byte:0x00 |
| 112 | ${valueinBytesWithoutArray} = Catenate ${valueinBytesWithoutArray} ${cmdByte} |
| 113 | # To Check scenario for smaller IPMI raw commands with only 2 arguments |
| 114 | # instead of usual 12 arguments. |
| 115 | # Sample small IPMI raw command: Run IPMI command 0x06 0x36 |
| 116 | # If IPMI raw argument length is only 9 then return value in bytes without |
| 117 | # array population. |
| 118 | # Equivalent dbus-send argument for smaller IPMI raw command: |
| 119 | # byte:0x00 byte:0x06 byte:0x00 byte:0x36 |
| 120 | Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray} |
| 121 | [return] ${valueinBytesWithArray} |
| 122 | |
| 123 | |
| 124 | Set NetFn Byte |
| 125 | [arguments] ${word} |
| 126 | ${netfnByteLocal} = Catenate byte:${word} |
| 127 | Set Global Variable ${netfnByte} ${netfnByteLocal} |
| 128 | |
| 129 | Set Cmd Byte |
| 130 | [arguments] ${word} |
| 131 | ${cmdByteLocal} = Catenate byte:${word} |
| 132 | Set Global Variable ${cmdByte} ${cmdByteLocal} |
| 133 | |
| 134 | Set Array Byte |
| 135 | [arguments] ${word} |
| 136 | ${arrayByteLocal} = Catenate SEPARATOR= ${arrayByte} ${word} |
| 137 | ${arrayByteLocal} = Catenate SEPARATOR= ${arrayByteLocal} , |
| 138 | Set Global Variable ${arrayByte} ${arrayByteLocal} |
| 139 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 140 | Copy ipmitool |
| 141 | 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. |
| 142 | |
| 143 | Import Library SCPLibrary WITH NAME scp |
| 144 | scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD} |
| 145 | scp.Put File tools/ipmitool /tmp |
| 146 | SSHLibrary.Open Connection ${OPENBMC_HOST} |
| 147 | Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD} |
| 148 | Execute Command chmod +x /tmp/ipmitool |