blob: cadae5e660d804a969b63281859447d7ee0ee832 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001*** Settings ***
George Keishing4d6c1da2016-07-15 05:51:22 -05002Documentation This module is for IPMI client for copying ipmitool to
Sivas SRRa2dab3c2016-07-25 05:08:18 -05003... openbmc box and execute ipmitool IPMI standard
4... command. IPMI raw command will use dbus-send command
Chris Austenb29d2e82016-06-07 12:25:35 -05005Resource ../lib/resource.txt
George Keishing4d6c1da2016-07-15 05:51:22 -05006Resource ../lib/connection_client.robot
Prashanth Kattiae7c2282017-03-15 07:43:46 -05007Resource ../lib/utils.robot
8Resource ../lib/state_manager.robot
9
Sivas SRRa2dab3c2016-07-25 05:08:18 -050010Library String
Michael Walsh19621ba2018-12-03 17:16:02 -060011Library ipmi_client.py
Sivas SRRa2dab3c2016-07-25 05:08:18 -050012
13*** Variables ***
George Keishingd7f11f72017-01-04 10:58:19 -060014${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1
15${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage
Gunnar Mills59204d22016-12-06 11:05:19 -060016${netfnByte}= ${EMPTY}
George Keishingd7f11f72017-01-04 10:58:19 -060017${cmdByte}= ${EMPTY}
Gunnar Mills59204d22016-12-06 11:05:19 -060018${arrayByte}= array:byte:
Michael Walsh19621ba2018-12-03 17:16:02 -060019${IPMI_EXT_CMD} ${EMPTY}
Michael Walsha7913892017-04-20 16:29:01 -050020${IPMI_USER_OPTIONS} ${EMPTY}
George Keishing39967eb2018-04-30 11:36:23 -050021${IPMI_INBAND_CMD}= ipmitool -C ${IPMI_CIPHER_LEVEL}
Gunnar Mills59204d22016-12-06 11:05:19 -060022${HOST}= -H
23${RAW}= raw
Chris Austenb29d2e82016-06-07 12:25:35 -050024
25*** Keywords ***
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050026
Chris Austenb29d2e82016-06-07 12:25:35 -050027Run IPMI Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050028 [Documentation] Run the given IPMI command.
Prashanth Kattiae7c2282017-03-15 07:43:46 -050029 [Arguments] ${args}
30 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
George Keishingb4d4a4a2018-08-27 13:35:39 -050031 ... Run External IPMI Raw Command ${args}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050032 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
George Keishingb4d4a4a2018-08-27 13:35:39 -050033 ... Run Inband IPMI Raw Command ${args}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050034 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
35 ... Run Dbus IPMI RAW Command ${args}
36 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
37 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050038
39Run IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050040 [Documentation] Run the standard IPMI command.
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060041 [Arguments] ${args} ${fail_on_err}=${1}
42
43 # Description of argument(s):
44 # args IPMI command to be executed.
45 # fail_on_err Fail if keyword the IPMI command fails
46
Prashanth Kattiae7c2282017-03-15 07:43:46 -050047 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060048 ... Run External IPMI Standard Command ${args} ${fail_on_err}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050049 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060050 ... Run Inband IPMI Standard Command ${args} ${fail_on_err}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050051 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
52 ... Run Dbus IPMI Standard Command ${args}
53 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050054
Prashanth Kattiae7c2282017-03-15 07:43:46 -050055 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050056
57Run Dbus IPMI RAW Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050058 [Documentation] Run the raw IPMI command through dbus.
Gunnar Mills38032802016-12-12 13:43:40 -060059 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -060060 ${valueinBytes}= Byte Conversion ${args}
61 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
62 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050063 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
64 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050065 set test variable ${OUTPUT} "${output}"
66
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050067Run Dbus IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050068 [Documentation] Run the standard IPMI command through dbus.
Gunnar Mills38032802016-12-12 13:43:40 -060069 [Arguments] ${args}
George Keishing4d6c1da2016-07-15 05:51:22 -050070 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050071 ${stdout} ${stderr} ${output}= Execute Command
72 ... /tmp/ipmitool -I dbus ${args} return_stdout=True
73 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050074 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060075 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050076
Prashanth Kattiae7c2282017-03-15 07:43:46 -050077Run Inband IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050078 [Documentation] Run the raw IPMI command in-band.
Prashanth Kattiae7c2282017-03-15 07:43:46 -050079 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
80 ... ${os_password}=${OS_PASSWORD}
81
Gunnar Mills28e403b2017-10-25 16:16:38 -050082 # Description of arguments:
Prashanth Kattiae7c2282017-03-15 07:43:46 -050083 # ${args} parameters to IPMI command.
84 # ${os_host} IP address of the OS Host.
85 # ${os_username} OS Host Login user name.
86 # ${os_password} OS Host Login passwrd.
87
88 Login To OS Host ${os_host} ${os_username} ${os_password}
89 Check If IPMI Tool Exist
90
91 ${inband_raw_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${args}
92 ${stdout} ${stderr}= Execute Command ${inband_raw_cmd} return_stderr=True
93 Should Be Empty ${stderr} msg=${stdout}
94 [Return] ${stdout}
95
96Run Inband IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050097 [Documentation] Run the standard IPMI command in-band.
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060098 [Arguments] ${args} ${fail_on_err}=${1} ${os_host}=${OS_HOST}
99 ... ${os_username}=${OS_USERNAME} ${os_password}=${OS_PASSWORD}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500100
Gunnar Mills28e403b2017-10-25 16:16:38 -0500101 # Description of arguments:
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500102 # ${args} parameters to IPMI command.
103 # ${os_host} IP address of the OS Host.
104 # ${os_username} OS Host Login user name.
105 # ${os_password} OS Host Login passwrd.
106
107 Login To OS Host ${os_host} ${os_username} ${os_password}
108 Check If IPMI Tool Exist
109
110 ${inband_std_cmd}= Catenate ${IPMI_INBAND_CMD} ${args}
111 ${stdout} ${stderr}= Execute Command ${inband_std_cmd} return_stderr=True
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600112 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500113 Should Be Empty ${stderr} msg=${stdout}
114 [Return] ${stdout}
115
George Keishingb4d4a4a2018-08-27 13:35:39 -0500116Run External IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500117 [Documentation] Run the raw IPMI command externally.
Gunnar Mills38032802016-12-12 13:43:40 -0600118 [Arguments] ${args}
Michael Walsh19621ba2018-12-03 17:16:02 -0600119
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500120 ${ipmi_raw_cmd}= Catenate SEPARATOR=
Michael Walsha7913892017-04-20 16:29:01 -0500121 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500122 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args}
123 ${rc} ${output}= Run and Return RC and Output ${ipmi_raw_cmd}
124 Should Be Equal ${rc} ${0} msg=${output}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600125 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500126
127Run External IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500128 [Documentation] Run the standard IPMI command in-band.
George Keishing02651f02018-04-11 02:07:16 -0500129 [Arguments] ${args} ${fail_on_err}=${1}
130
131 # Description of argument(s):
132 # args IPMI command to be executed.
133 # fail_on_err Fail if keyword the IPMI command fails
Michael Walsha7913892017-04-20 16:29:01 -0500134
135 ${ipmi_cmd}= Catenate SEPARATOR=
136 ... ${IPMI_EXT_CMD} ${IPMI_USER_OPTIONS} -P${SPACE}${IPMI_PASSWORD}
137 ... ${SPACE}${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500138 ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd}
George Keishing02651f02018-04-11 02:07:16 -0500139 Return From Keyword If ${fail_on_err} == ${0} ${output}
Michael Walsha7913892017-04-20 16:29:01 -0500140 Should Be Equal ${rc} ${0} msg=${output}
141 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500142
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500143Check If IPMI Tool Exist
144 [Documentation] Check if IPMI Tool installed or not.
145 ${output}= Execute Command which ipmitool
146 Should Not Be Empty ${output} msg=ipmitool not installed.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500147
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500148
149Activate SOL Via IPMI
150 [Documentation] Start SOL using IPMI and route output to a file.
151 [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST}
152 # Description of argument(s):
153 # file_path The file path on the local machine (vs OBMC) to collect SOL
154 # output. By default SOL output is collected at
155 # /tmp/sol_<BMC_IP> else user input location.
156
157 ${ipmi_cmd}= Catenate SEPARATOR=
Rahul Maheshwaric8470882017-08-30 05:41:16 -0500158 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}${HOST}
159 ... ${SPACE}${OPENBMC_HOST}${SPACE}sol activate usesolkeepalive
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500160
George Keishing2102f6b2017-06-06 08:30:10 -0500161 Start Process ${ipmi_cmd} shell=True stdout=${file_path}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500162 ... alias=sol_proc
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500163
164
165Deactivate SOL Via IPMI
166 [Documentation] Stop SOL using IPMI and return SOL output.
167 [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST}
168 # Description of argument(s):
169 # file_path The file path on the local machine to copy SOL output
170 # collected by above "Activate SOL Via IPMI" keyword.
171 # By default it copies log from /tmp/sol_<BMC_IP>.
172
173 ${ipmi_cmd}= Catenate SEPARATOR=
174 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
175 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}sol deactivate
176
177 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500178 Run Keyword If ${rc} > 0 Run Keywords
Rahul Maheshwari7f48a2c2017-06-16 04:00:26 -0500179 ... Run Keyword And Ignore Error Terminate Process sol_proc
180 ... AND Return From Keyword ${output}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500181
182 ${rc} ${output}= Run and Return RC and Output cat ${file_path}
183 Should Be Equal ${rc} ${0} msg=${output}
184
185 # Logging SOL output for debug purpose.
186 Log ${output}
187
188 [Return] ${output}
189
190
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500191Byte Conversion
192 [Documentation] Byte Conversion method receives IPMI RAW commands as
193 ... argument in string format.
194 ... Sample argument is as follows
195 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
196 ... 0x00"
197 ... IPMI RAW command format is as follows
198 ... <netfn Byte> <cmd Byte> <Data Bytes..>
199 ... This method converts IPMI command format into
200 ... dbus command format as follows
201 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
202 ... <array:byte:data>
203 ... Sample dbus Host IPMI Received Message argument
204 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30
205 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
Gunnar Mills38032802016-12-12 13:43:40 -0600206 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600207 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500208 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600209 @{listargs}= Split String ${args}
210 ${index}= Set Variable ${0}
George Keishing9a089442018-12-10 09:38:50 -0600211 :FOR ${word} IN @{listargs}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500212 \ Run Keyword if ${index} == 0 Set NetFn Byte ${word}
213 \ Run Keyword if ${index} == 1 Set Cmd Byte ${word}
214 \ Run Keyword if ${index} > 1 Set Array Byte ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600215 \ ${index}= Set Variable ${index + 1}
216 ${length}= Get Length ${arrayByte}
217 ${length}= Evaluate ${length} - 1
218 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500219 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600220 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
221 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte}
222 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte}
223 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
224 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500225# To Check scenario for smaller IPMI raw commands with only 2 arguments
226# instead of usual 12 arguments.
227# Sample small IPMI raw command: Run IPMI command 0x06 0x36
228# If IPMI raw argument length is only 9 then return value in bytes without
229# array population.
230# Equivalent dbus-send argument for smaller IPMI raw command:
231# byte:0x00 byte:0x06 byte:0x00 byte:0x36
232 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600233 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500234
235
236Set NetFn Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500237 [Documentation] Set the network function byte.
238 [Arguments] ${word}
239 ${netfnByteLocal}= Catenate byte:${word}
240 Set Global Variable ${netfnByte} ${netfnByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500241
242Set Cmd Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500243 [Documentation] Set the command byte.
244 [Arguments] ${word}
245 ${cmdByteLocal}= Catenate byte:${word}
246 Set Global Variable ${cmdByte} ${cmdByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500247
248Set Array Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500249 [Documentation] Set the array byte.
250 [Arguments] ${word}
251 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
252 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
253 Set Global Variable ${arrayByte} ${arrayByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500254
Chris Austenb29d2e82016-06-07 12:25:35 -0500255Copy ipmitool
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500256 [Documentation] Copy the ipmitool to the BMC.
257 ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory.
258 ... It is not part of the automation code by default. You must manually copy or link the correct openbmc
259 ... version of the tool in to the tools directory in order to run this test suite.
260
261 OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error}
Chris Austenb29d2e82016-06-07 12:25:35 -0500262
263 Import Library SCPLibrary WITH NAME scp
264 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD}
265 scp.Put File tools/ipmitool /tmp
266 SSHLibrary.Open Connection ${OPENBMC_HOST}
267 Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
268 Execute Command chmod +x /tmp/ipmitool
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500269
270Initiate Host Boot Via External IPMI
271 [Documentation] Initiate host power on using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500272 [Arguments] ${wait}=${1}
273 # Description of argument(s):
274 # wait Indicates that this keyword should wait for host running state.
275
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500276 ${output}= Run External IPMI Standard Command chassis power on
277 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500278
279 Run Keyword If '${wait}' == '${0}' Return From Keyword
280 Wait Until Keyword Succeeds 10 min 10 sec Is Host Running
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500281
282Initiate Host PowerOff Via External IPMI
283 [Documentation] Initiate host power off using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500284 [Arguments] ${wait}=${1}
285 # Description of argument(s):
286 # wait Indicates that this keyword should wait for host off state.
287
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500288 ${output}= Run External IPMI Standard Command chassis power off
289 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500290
291 Run Keyword If '${wait}' == '${0}' Return From Keyword
292 Wait Until Keyword Succeeds 3 min 10 sec Is Host Off
293
294Get Host State Via External IPMI
295 [Documentation] Returns host state using external IPMI.
296
297 ${output}= Run External IPMI Standard Command chassis power status
298 Should Not Contain ${output} Error
299 ${output}= Fetch From Right ${output} ${SPACE}
300
301 [Return] ${output}
George Keishingb4d4a4a2018-08-27 13:35:39 -0500302
303
304Set BMC Network From Host
305 [Documentation] Set BMC network from host.
306 [Arguments] ${nw_info}
307
308 # Description of argument(s):
309 # nw_info A dictionary containing the network information to apply.
310
311 Run Inband IPMI Standard Command
312 ... lan set 1 ipaddr ${nw_info['IP Address']}
313
314 Run Inband IPMI Standard Command
315 ... lan set 1 netmask ${nw_info['Subnet Mask']}
316
317 Run Inband IPMI Standard Command
318 ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}