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 *** |
George Keishing | d7f11f7 | 2017-01-04 10:58:19 -0600 | [diff] [blame] | 10 | ${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1 |
| 11 | ${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 12 | ${netfnByte}= ${EMPTY} |
George Keishing | d7f11f7 | 2017-01-04 10:58:19 -0600 | [diff] [blame] | 13 | ${cmdByte}= ${EMPTY} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 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 |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 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} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 29 | [Return] ${resp} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 30 | |
| 31 | Run IPMI Standard Command |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 32 | [Arguments] ${args} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 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 | |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 40 | [Return] ${resp} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 41 | |
| 42 | Run Dbus IPMI RAW Command |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 43 | [Arguments] ${args} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 44 | ${valueinBytes}= Byte Conversion ${args} |
| 45 | ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg} |
| 46 | ${cmd}= Catenate ${cmd} ${valueinBytes} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 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 |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [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} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 58 | [Return] ${stdout} |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 59 | |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 60 | Run External IPMI RAW Command |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 61 | [Arguments] ${args} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 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} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 67 | [Return] ${output} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 68 | |
| 69 | Run External IPMI Standard Command |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 70 | [Arguments] ${args} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 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} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 76 | [Return] ${output} |
Rahul Maheshwari | 7a212a0 | 2016-09-05 21:17:30 -0500 | [diff] [blame] | 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 |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 94 | [Arguments] ${args} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 95 | ${argLength}= Get Length ${args} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 96 | Set Global Variable ${arrayByte} array:byte: |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 97 | @{listargs}= Split String ${args} |
| 98 | ${index}= Set Variable ${0} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 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} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 103 | \ ${index}= Set Variable ${index + 1} |
| 104 | ${length}= Get Length ${arrayByte} |
| 105 | ${length}= Evaluate ${length} - 1 |
| 106 | ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 107 | Set Global Variable ${arrayByte} ${arrayByteLocal} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 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} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 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} |
Gunnar Mills | c9ea936 | 2016-12-13 16:21:13 -0600 | [diff] [blame] | 121 | [Return] ${valueinBytesWithArray} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 122 | |
| 123 | |
| 124 | Set NetFn Byte |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 125 | [Arguments] ${word} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 126 | ${netfnByteLocal}= Catenate byte:${word} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 127 | Set Global Variable ${netfnByte} ${netfnByteLocal} |
| 128 | |
| 129 | Set Cmd Byte |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 130 | [Arguments] ${word} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 131 | ${cmdByteLocal}= Catenate byte:${word} |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 132 | Set Global Variable ${cmdByte} ${cmdByteLocal} |
| 133 | |
| 134 | Set Array Byte |
Gunnar Mills | 3803280 | 2016-12-12 13:43:40 -0600 | [diff] [blame] | 135 | [Arguments] ${word} |
Gunnar Mills | 59204d2 | 2016-12-06 11:05:19 -0600 | [diff] [blame] | 136 | ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word} |
| 137 | ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} , |
Sivas SRR | a2dab3c | 2016-07-25 05:08:18 -0500 | [diff] [blame] | 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 |