blob: 030712f26dbeae20be1a2b15607e176540045f94 [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.
Prashanth Kattiae7c2282017-03-15 07:43:46 -050041 [Arguments] ${args}
42 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
43 ... Run External IPMI Standard Command ${args}
44 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
45 ... Run Inband IPMI Standard Command ${args}
46 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
47 ... Run Dbus IPMI Standard Command ${args}
48 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050049
Prashanth Kattiae7c2282017-03-15 07:43:46 -050050 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050051
52Run Dbus IPMI RAW Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050053 [Documentation] Run the raw IPMI command through dbus.
Gunnar Mills38032802016-12-12 13:43:40 -060054 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -060055 ${valueinBytes}= Byte Conversion ${args}
56 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
57 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050058 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
59 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050060 set test variable ${OUTPUT} "${output}"
61
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050062Run Dbus IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050063 [Documentation] Run the standard IPMI command through dbus.
Gunnar Mills38032802016-12-12 13:43:40 -060064 [Arguments] ${args}
George Keishing4d6c1da2016-07-15 05:51:22 -050065 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050066 ${stdout} ${stderr} ${output}= Execute Command
67 ... /tmp/ipmitool -I dbus ${args} return_stdout=True
68 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050069 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060070 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050071
Prashanth Kattiae7c2282017-03-15 07:43:46 -050072Run Inband IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050073 [Documentation] Run the raw IPMI command in-band.
Prashanth Kattiae7c2282017-03-15 07:43:46 -050074 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
75 ... ${os_password}=${OS_PASSWORD}
76
Gunnar Mills28e403b2017-10-25 16:16:38 -050077 # Description of arguments:
Prashanth Kattiae7c2282017-03-15 07:43:46 -050078 # ${args} parameters to IPMI command.
79 # ${os_host} IP address of the OS Host.
80 # ${os_username} OS Host Login user name.
81 # ${os_password} OS Host Login passwrd.
82
83 Login To OS Host ${os_host} ${os_username} ${os_password}
84 Check If IPMI Tool Exist
85
86 ${inband_raw_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${args}
87 ${stdout} ${stderr}= Execute Command ${inband_raw_cmd} return_stderr=True
88 Should Be Empty ${stderr} msg=${stdout}
89 [Return] ${stdout}
90
91Run Inband IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050092 [Documentation] Run the standard IPMI command in-band.
Prashanth Kattiae7c2282017-03-15 07:43:46 -050093 [Arguments] ${args} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
94 ... ${os_password}=${OS_PASSWORD}
95
Gunnar Mills28e403b2017-10-25 16:16:38 -050096 # Description of arguments:
Prashanth Kattiae7c2282017-03-15 07:43:46 -050097 # ${args} parameters to IPMI command.
98 # ${os_host} IP address of the OS Host.
99 # ${os_username} OS Host Login user name.
100 # ${os_password} OS Host Login passwrd.
101
102 Login To OS Host ${os_host} ${os_username} ${os_password}
103 Check If IPMI Tool Exist
104
105 ${inband_std_cmd}= Catenate ${IPMI_INBAND_CMD} ${args}
106 ${stdout} ${stderr}= Execute Command ${inband_std_cmd} return_stderr=True
107 Should Be Empty ${stderr} msg=${stdout}
108 [Return] ${stdout}
109
George Keishingb4d4a4a2018-08-27 13:35:39 -0500110Run External IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500111 [Documentation] Run the raw IPMI command externally.
Gunnar Mills38032802016-12-12 13:43:40 -0600112 [Arguments] ${args}
Michael Walsh19621ba2018-12-03 17:16:02 -0600113
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500114 ${ipmi_raw_cmd}= Catenate SEPARATOR=
Michael Walsha7913892017-04-20 16:29:01 -0500115 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500116 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${RAW}${SPACE}${args}
117 ${rc} ${output}= Run and Return RC and Output ${ipmi_raw_cmd}
118 Should Be Equal ${rc} ${0} msg=${output}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600119 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500120
121Run External IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500122 [Documentation] Run the standard IPMI command in-band.
George Keishing02651f02018-04-11 02:07:16 -0500123 [Arguments] ${args} ${fail_on_err}=${1}
124
125 # Description of argument(s):
126 # args IPMI command to be executed.
127 # fail_on_err Fail if keyword the IPMI command fails
Michael Walsha7913892017-04-20 16:29:01 -0500128
129 ${ipmi_cmd}= Catenate SEPARATOR=
130 ... ${IPMI_EXT_CMD} ${IPMI_USER_OPTIONS} -P${SPACE}${IPMI_PASSWORD}
131 ... ${SPACE}${HOST}${SPACE}${OPENBMC_HOST}${SPACE}${args}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500132 ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd}
George Keishing02651f02018-04-11 02:07:16 -0500133 Return From Keyword If ${fail_on_err} == ${0} ${output}
Michael Walsha7913892017-04-20 16:29:01 -0500134 Should Be Equal ${rc} ${0} msg=${output}
135 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500136
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500137Check If IPMI Tool Exist
138 [Documentation] Check if IPMI Tool installed or not.
139 ${output}= Execute Command which ipmitool
140 Should Not Be Empty ${output} msg=ipmitool not installed.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500141
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500142
143Activate SOL Via IPMI
144 [Documentation] Start SOL using IPMI and route output to a file.
145 [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST}
146 # Description of argument(s):
147 # file_path The file path on the local machine (vs OBMC) to collect SOL
148 # output. By default SOL output is collected at
149 # /tmp/sol_<BMC_IP> else user input location.
150
151 ${ipmi_cmd}= Catenate SEPARATOR=
Rahul Maheshwaric8470882017-08-30 05:41:16 -0500152 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}${HOST}
153 ... ${SPACE}${OPENBMC_HOST}${SPACE}sol activate usesolkeepalive
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500154
George Keishing2102f6b2017-06-06 08:30:10 -0500155 Start Process ${ipmi_cmd} shell=True stdout=${file_path}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500156 ... alias=sol_proc
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500157
158
159Deactivate SOL Via IPMI
160 [Documentation] Stop SOL using IPMI and return SOL output.
161 [Arguments] ${file_path}=/tmp/sol_${OPENBMC_HOST}
162 # Description of argument(s):
163 # file_path The file path on the local machine to copy SOL output
164 # collected by above "Activate SOL Via IPMI" keyword.
165 # By default it copies log from /tmp/sol_<BMC_IP>.
166
167 ${ipmi_cmd}= Catenate SEPARATOR=
168 ... ${IPMI_EXT_CMD} -P${SPACE}${IPMI_PASSWORD}${SPACE}
169 ... ${HOST}${SPACE}${OPENBMC_HOST}${SPACE}sol deactivate
170
171 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500172 Run Keyword If ${rc} > 0 Run Keywords
Rahul Maheshwari7f48a2c2017-06-16 04:00:26 -0500173 ... Run Keyword And Ignore Error Terminate Process sol_proc
174 ... AND Return From Keyword ${output}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500175
176 ${rc} ${output}= Run and Return RC and Output cat ${file_path}
177 Should Be Equal ${rc} ${0} msg=${output}
178
179 # Logging SOL output for debug purpose.
180 Log ${output}
181
182 [Return] ${output}
183
184
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500185Byte Conversion
186 [Documentation] Byte Conversion method receives IPMI RAW commands as
187 ... argument in string format.
188 ... Sample argument is as follows
189 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
190 ... 0x00"
191 ... IPMI RAW command format is as follows
192 ... <netfn Byte> <cmd Byte> <Data Bytes..>
193 ... This method converts IPMI command format into
194 ... dbus command format as follows
195 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
196 ... <array:byte:data>
197 ... Sample dbus Host IPMI Received Message argument
198 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30
199 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
Gunnar Mills38032802016-12-12 13:43:40 -0600200 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600201 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500202 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600203 @{listargs}= Split String ${args}
204 ${index}= Set Variable ${0}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500205 :FOR ${word} in @{listargs}
206 \ Run Keyword if ${index} == 0 Set NetFn Byte ${word}
207 \ Run Keyword if ${index} == 1 Set Cmd Byte ${word}
208 \ Run Keyword if ${index} > 1 Set Array Byte ${word}
Gunnar Mills59204d22016-12-06 11:05:19 -0600209 \ ${index}= Set Variable ${index + 1}
210 ${length}= Get Length ${arrayByte}
211 ${length}= Evaluate ${length} - 1
212 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500213 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600214 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
215 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte}
216 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte}
217 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
218 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500219# To Check scenario for smaller IPMI raw commands with only 2 arguments
220# instead of usual 12 arguments.
221# Sample small IPMI raw command: Run IPMI command 0x06 0x36
222# If IPMI raw argument length is only 9 then return value in bytes without
223# array population.
224# Equivalent dbus-send argument for smaller IPMI raw command:
225# byte:0x00 byte:0x06 byte:0x00 byte:0x36
226 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600227 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500228
229
230Set NetFn Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500231 [Documentation] Set the network function byte.
232 [Arguments] ${word}
233 ${netfnByteLocal}= Catenate byte:${word}
234 Set Global Variable ${netfnByte} ${netfnByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500235
236Set Cmd Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500237 [Documentation] Set the command byte.
238 [Arguments] ${word}
239 ${cmdByteLocal}= Catenate byte:${word}
240 Set Global Variable ${cmdByte} ${cmdByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500241
242Set Array Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500243 [Documentation] Set the array byte.
244 [Arguments] ${word}
245 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
246 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
247 Set Global Variable ${arrayByte} ${arrayByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500248
Chris Austenb29d2e82016-06-07 12:25:35 -0500249Copy ipmitool
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500250 [Documentation] Copy the ipmitool to the BMC.
251 ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory.
252 ... It is not part of the automation code by default. You must manually copy or link the correct openbmc
253 ... version of the tool in to the tools directory in order to run this test suite.
254
255 OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error}
Chris Austenb29d2e82016-06-07 12:25:35 -0500256
257 Import Library SCPLibrary WITH NAME scp
258 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD}
259 scp.Put File tools/ipmitool /tmp
260 SSHLibrary.Open Connection ${OPENBMC_HOST}
261 Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
262 Execute Command chmod +x /tmp/ipmitool
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500263
264Initiate Host Boot Via External IPMI
265 [Documentation] Initiate host power on using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500266 [Arguments] ${wait}=${1}
267 # Description of argument(s):
268 # wait Indicates that this keyword should wait for host running state.
269
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500270 ${output}= Run External IPMI Standard Command chassis power on
271 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500272
273 Run Keyword If '${wait}' == '${0}' Return From Keyword
274 Wait Until Keyword Succeeds 10 min 10 sec Is Host Running
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500275
276Initiate Host PowerOff Via External IPMI
277 [Documentation] Initiate host power off using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500278 [Arguments] ${wait}=${1}
279 # Description of argument(s):
280 # wait Indicates that this keyword should wait for host off state.
281
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500282 ${output}= Run External IPMI Standard Command chassis power off
283 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500284
285 Run Keyword If '${wait}' == '${0}' Return From Keyword
286 Wait Until Keyword Succeeds 3 min 10 sec Is Host Off
287
288Get Host State Via External IPMI
289 [Documentation] Returns host state using external IPMI.
290
291 ${output}= Run External IPMI Standard Command chassis power status
292 Should Not Contain ${output} Error
293 ${output}= Fetch From Right ${output} ${SPACE}
294
295 [Return] ${output}
George Keishingb4d4a4a2018-08-27 13:35:39 -0500296
297
298Set BMC Network From Host
299 [Documentation] Set BMC network from host.
300 [Arguments] ${nw_info}
301
302 # Description of argument(s):
303 # nw_info A dictionary containing the network information to apply.
304
305 Run Inband IPMI Standard Command
306 ... lan set 1 ipaddr ${nw_info['IP Address']}
307
308 Run Inband IPMI Standard Command
309 ... lan set 1 netmask ${nw_info['Subnet Mask']}
310
311 Run Inband IPMI Standard Command
312 ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}