blob: 87dd4110e1a0be8353cb687d14ef81d3967da632 [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
Sandhya Somashekar839a0c22019-01-31 05:05:43 -06005Resource ../lib/resource.robot
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 Walsh34c79af2019-12-09 11:46:48 -060011Library var_funcs.py
Michael Walsh19621ba2018-12-03 17:16:02 -060012Library ipmi_client.py
leetb9a29a62022-05-17 19:30:25 +000013Library ../lib/bmc_ssh_utils.py
Sivas SRRa2dab3c2016-07-25 05:08:18 -050014
15*** Variables ***
George Keishingd7f11f72017-01-04 10:58:19 -060016${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1
17${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage
Gunnar Mills59204d22016-12-06 11:05:19 -060018${netfnByte}= ${EMPTY}
George Keishingd7f11f72017-01-04 10:58:19 -060019${cmdByte}= ${EMPTY}
Gunnar Mills59204d22016-12-06 11:05:19 -060020${arrayByte}= array:byte:
Michael Walsha7913892017-04-20 16:29:01 -050021${IPMI_USER_OPTIONS} ${EMPTY}
George Keishing75f55dc2021-03-29 10:48:09 -050022${IPMI_INBAND_CMD}= ipmitool -C ${IPMI_CIPHER_LEVEL} -N ${IPMI_TIMEOUT} -p ${IPMI_PORT}
Gunnar Mills59204d22016-12-06 11:05:19 -060023${HOST}= -H
24${RAW}= raw
leetb9a29a62022-05-17 19:30:25 +000025${IPMITOOL_PATH} /tmp/ipmitool
Chris Austenb29d2e82016-06-07 12:25:35 -050026
27*** Keywords ***
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050028
Chris Austenb29d2e82016-06-07 12:25:35 -050029Run IPMI Command
Michael Walsh3ef2e922019-01-23 10:40:16 -060030 [Documentation] Run the raw IPMI command.
31 [Arguments] ${command} ${fail_on_err}=${1} &{options}
32
33 # Description of argument(s):
34 # command The IPMI command string to be executed
35 # (e.g. "power status").
36 # fail_on_err Fail if the IPMI command execution fails.
37 # options Additional ipmitool command options (e.g.
38 # -C=3, -I=lanplus, etc.). Currently, only
39 # used for external IPMI commands.
40
Prashanth Kattiae7c2282017-03-15 07:43:46 -050041 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Michael Walsh3ef2e922019-01-23 10:40:16 -060042 ... Run External IPMI Raw Command ${command} ${fail_on_err} &{options}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050043 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Michael Walsh3ef2e922019-01-23 10:40:16 -060044 ... Run Inband IPMI Raw Command ${command}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050045 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
Michael Walsh3ef2e922019-01-23 10:40:16 -060046 ... Run Dbus IPMI RAW Command ${command}
47 ... ELSE Fail msg=Invalid IPMI Command type provided: ${IPMI_COMMAND}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050048 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050049
Michael Walsh3ef2e922019-01-23 10:40:16 -060050
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050051Run IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050052 [Documentation] Run the standard IPMI command.
Michael Walshd0e58e72019-05-14 11:07:14 -050053 [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options}
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060054
55 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -060056 # command The IPMI command string to be executed
57 # (e.g. "0x06 0x36").
58 # fail_on_err Fail if the IPMI command execution fails.
Michael Walshd0e58e72019-05-14 11:07:14 -050059 # expected_rc The expected return code from the ipmi
60 # command (e.g. ${0}, ${1}, etc.).
Michael Walsh3ef2e922019-01-23 10:40:16 -060061 # options Additional ipmitool command options (e.g.
62 # -C=3, -I=lanplus, etc.). Currently, only
63 # used for external IPMI commands.
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060064
Prashanth Kattiae7c2282017-03-15 07:43:46 -050065 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Michael Walshd0e58e72019-05-14 11:07:14 -050066 ... Run External IPMI Standard Command ${command} ${fail_on_err} ${expected_rc} &{options}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050067 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Michael Walsh3ef2e922019-01-23 10:40:16 -060068 ... Run Inband IPMI Standard Command ${command} ${fail_on_err}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050069 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
Michael Walsh3ef2e922019-01-23 10:40:16 -060070 ... Run Dbus IPMI Standard Command ${command}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050071 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050072 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050073
Michael Walsh3ef2e922019-01-23 10:40:16 -060074
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050075Run Dbus IPMI RAW Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050076 [Documentation] Run the raw IPMI command through dbus.
Michael Walsh3ef2e922019-01-23 10:40:16 -060077 [Arguments] ${command}
78 ${valueinBytes}= Byte Conversion ${command}
Gunnar Mills59204d22016-12-06 11:05:19 -060079 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
80 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050081 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
82 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050083 set test variable ${OUTPUT} "${output}"
84
Michael Walsh3ef2e922019-01-23 10:40:16 -060085
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050086Run Dbus IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050087 [Documentation] Run the standard IPMI command through dbus.
Michael Walsh3ef2e922019-01-23 10:40:16 -060088 [Arguments] ${command}
George Keishing4d6c1da2016-07-15 05:51:22 -050089 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050090 ${stdout} ${stderr} ${output}= Execute Command
leetb9a29a62022-05-17 19:30:25 +000091 ... ${IPMITOOL_PATH} -I dbus ${command} return_stdout=True
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050092 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050093 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060094 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050095
Michael Walsh3ef2e922019-01-23 10:40:16 -060096
Prashanth Kattiae7c2282017-03-15 07:43:46 -050097Run Inband IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050098 [Documentation] Run the raw IPMI command in-band.
chithrag4ad123a2022-04-12 19:26:05 +000099 [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500100 ... ${os_password}=${OS_PASSWORD}
101
Michael Walsh3ef2e922019-01-23 10:40:16 -0600102 # Description of argument(s):
103 # command The IPMI command string to be executed
104 # (e.g. "0x06 0x36").
105 # os_host The host name or IP address of the OS Host.
106 # os_username The OS host user name.
107 # os_password The OS host passwrd.
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500108
109 Login To OS Host ${os_host} ${os_username} ${os_password}
110 Check If IPMI Tool Exist
111
Michael Walsh3ef2e922019-01-23 10:40:16 -0600112 ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${command}
113 Qprint Issuing ${ipmi_cmd}
114 ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True
chithrag4ad123a2022-04-12 19:26:05 +0000115 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500116 Should Be Empty ${stderr} msg=${stdout}
117 [Return] ${stdout}
118
Michael Walsh3ef2e922019-01-23 10:40:16 -0600119
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500120Run Inband IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500121 [Documentation] Run the standard IPMI command in-band.
Michael Walsh3ef2e922019-01-23 10:40:16 -0600122 [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST}
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600123 ... ${os_username}=${OS_USERNAME} ${os_password}=${OS_PASSWORD}
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500124 ... ${login_host}=${1}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500125
Michael Walsh3ef2e922019-01-23 10:40:16 -0600126 # Description of argument(s):
127 # command The IPMI command string to be executed
128 # (e.g. "power status").
129 # os_host The host name or IP address of the OS Host.
130 # os_username The OS host user name.
131 # os_password The OS host passwrd.
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500132 # login_host Indicates that this keyword should login to host OS.
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500133
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500134 Run Keyword If ${login_host} == ${1}
135 ... Login To OS Host ${os_host} ${os_username} ${os_password}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500136 Check If IPMI Tool Exist
137
Michael Walsh3ef2e922019-01-23 10:40:16 -0600138 ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${command}
139 Qprint Issuing ${ipmi_cmd}
140 ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600141 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500142 Should Be Empty ${stderr} msg=${stdout}
143 [Return] ${stdout}
144
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500145
146Run External IPMI Standard Command
Michael Walsh3ef2e922019-01-23 10:40:16 -0600147 [Documentation] Run the external IPMI standard command.
Michael Walshd0e58e72019-05-14 11:07:14 -0500148 [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options}
George Keishing02651f02018-04-11 02:07:16 -0500149
150 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600151 # command The IPMI command string to be executed
152 # (e.g. "power status"). Note that if
153 # ${IPMI_USER_OPTIONS} has a value (e.g.
154 # "-vvv"), it will be pre-pended to this
155 # command string.
156 # fail_on_err Fail if the IPMI command execution fails.
Michael Walshd0e58e72019-05-14 11:07:14 -0500157 # expected_rc The expected return code from the ipmi
158 # command (e.g. ${0}, ${1}, etc.).
Michael Walsh3ef2e922019-01-23 10:40:16 -0600159 # options Additional ipmitool command options (e.g.
160 # -C=3, -I=lanplus, etc.).
Michael Walsha7913892017-04-20 16:29:01 -0500161
Michael Walsh3ef2e922019-01-23 10:40:16 -0600162 ${command_string}= Process IPMI User Options ${command}
163 ${ipmi_cmd}= Create IPMI Ext Command String ${command_string} &{options}
164 Qprint Issuing ${ipmi_cmd}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500165 ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd}
George Keishing02651f02018-04-11 02:07:16 -0500166 Return From Keyword If ${fail_on_err} == ${0} ${output}
Michael Walshd0e58e72019-05-14 11:07:14 -0500167 Should Be Equal ${rc} ${expected_rc} msg=${output}
Michael Walsha7913892017-04-20 16:29:01 -0500168 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500169
Michael Walsh3ef2e922019-01-23 10:40:16 -0600170
171Run External IPMI Raw Command
172 [Documentation] Run the external IPMI raw command.
173 [Arguments] ${command} ${fail_on_err}=${1} &{options}
174
175 # This keyword is a wrapper for 'Run External IPMI Standard Command'. See
176 # that keyword's prolog for argument details. This keyword will pre-pend
177 # the word "raw" plus a space to command prior to calling 'Run External
178 # IPMI Standard Command'.
179
180 ${output}= Run External IPMI Standard Command
181 ... raw ${command} ${fail_on_err} &{options}
182 [Return] ${output}
183
184
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500185Check If IPMI Tool Exist
186 [Documentation] Check if IPMI Tool installed or not.
187 ${output}= Execute Command which ipmitool
188 Should Not Be Empty ${output} msg=ipmitool not installed.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500189
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500190
191Activate SOL Via IPMI
192 [Documentation] Start SOL using IPMI and route output to a file.
George Keishing26206722021-11-17 01:29:53 -0600193 [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600194
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500195 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600196 # file_path The file path on the local machine (vs.
197 # OBMC) to collect SOL output. By default
198 # SOL output is collected at
George Keishing26206722021-11-17 01:29:53 -0600199 # logs/sol_<BMC_IP> else user input location.
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500200
Michael Walsh3ef2e922019-01-23 10:40:16 -0600201 ${ipmi_cmd}= Create IPMI Ext Command String sol activate usesolkeepalive
202 Qprint Issuing ${ipmi_cmd}
George Keishing2102f6b2017-06-06 08:30:10 -0500203 Start Process ${ipmi_cmd} shell=True stdout=${file_path}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500204 ... alias=sol_proc
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500205
206
207Deactivate SOL Via IPMI
208 [Documentation] Stop SOL using IPMI and return SOL output.
George Keishing26206722021-11-17 01:29:53 -0600209 [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600210
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500211 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600212 # file_path The file path on the local machine to copy
213 # SOL output collected by above "Activate
214 # SOL Via IPMI" keyword. By default it
George Keishing26206722021-11-17 01:29:53 -0600215 # copies log from logs/sol_<BMC_IP>.
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500216
Michael Walsh3ef2e922019-01-23 10:40:16 -0600217 ${ipmi_cmd}= Create IPMI Ext Command String sol deactivate
218 Qprint Issuing ${ipmi_cmd}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500219 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500220 Run Keyword If ${rc} > 0 Run Keywords
Rahul Maheshwari7f48a2c2017-06-16 04:00:26 -0500221 ... Run Keyword And Ignore Error Terminate Process sol_proc
222 ... AND Return From Keyword ${output}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500223
George Keishingaec8b872019-07-08 23:44:08 -0500224 ${output}= OperatingSystem.Get File ${file_path} encoding_errors=ignore
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500225
226 # Logging SOL output for debug purpose.
227 Log ${output}
228
229 [Return] ${output}
230
231
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500232Byte Conversion
233 [Documentation] Byte Conversion method receives IPMI RAW commands as
234 ... argument in string format.
235 ... Sample argument is as follows
236 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
237 ... 0x00"
238 ... IPMI RAW command format is as follows
239 ... <netfn Byte> <cmd Byte> <Data Bytes..>
240 ... This method converts IPMI command format into
241 ... dbus command format as follows
242 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
243 ... <array:byte:data>
244 ... Sample dbus Host IPMI Received Message argument
245 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30
246 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
Gunnar Mills38032802016-12-12 13:43:40 -0600247 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600248 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500249 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600250 @{listargs}= Split String ${args}
251 ${index}= Set Variable ${0}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500252 FOR ${word} IN @{listargs}
253 Run Keyword if ${index} == 0 Set NetFn Byte ${word}
254 Run Keyword if ${index} == 1 Set Cmd Byte ${word}
255 Run Keyword if ${index} > 1 Set Array Byte ${word}
256 ${index}= Set Variable ${index + 1}
257 END
Gunnar Mills59204d22016-12-06 11:05:19 -0600258 ${length}= Get Length ${arrayByte}
259 ${length}= Evaluate ${length} - 1
260 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500261 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600262 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
263 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte}
264 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte}
265 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
266 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600267 # To Check scenario for smaller IPMI raw commands with only 2 arguments
268 # instead of usual 12 arguments.
269 # Sample small IPMI raw command: Run IPMI command 0x06 0x36
270 # If IPMI raw argument length is only 9 then return value in bytes without
271 # array population.
272 # Equivalent dbus-send argument for smaller IPMI raw command:
273 # byte:0x00 byte:0x06 byte:0x00 byte:0x36
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500274 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600275 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500276
277
278Set NetFn Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500279 [Documentation] Set the network function byte.
280 [Arguments] ${word}
281 ${netfnByteLocal}= Catenate byte:${word}
282 Set Global Variable ${netfnByte} ${netfnByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500283
Michael Walsh3ef2e922019-01-23 10:40:16 -0600284
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500285Set Cmd Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500286 [Documentation] Set the command byte.
287 [Arguments] ${word}
288 ${cmdByteLocal}= Catenate byte:${word}
289 Set Global Variable ${cmdByte} ${cmdByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500290
Michael Walsh3ef2e922019-01-23 10:40:16 -0600291
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500292Set Array Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500293 [Documentation] Set the array byte.
294 [Arguments] ${word}
295 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
296 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
297 Set Global Variable ${arrayByte} ${arrayByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500298
Michael Walsh3ef2e922019-01-23 10:40:16 -0600299
Chris Austenb29d2e82016-06-07 12:25:35 -0500300Copy ipmitool
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500301 [Documentation] Copy the ipmitool to the BMC.
302 ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory.
303 ... It is not part of the automation code by default. You must manually copy or link the correct openbmc
304 ... version of the tool in to the tools directory in order to run this test suite.
305
leetb9a29a62022-05-17 19:30:25 +0000306 ${response} ${stderr} ${rc}= BMC Execute Command
307 ... which ipmitool ignore_err=${1}
308 ${installed}= Get Regexp Matches ${response} ipmitool
309 Run Keyword If ${installed} == ['ipmitool']
310 ... Run Keywords Set Suite Variable ${IPMITOOL_PATH} ${response}
311 ... AND SSHLibrary.Open Connection ${OPENBMC_HOST}
312 ... AND SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
313 ... AND Return From Keyword
Chris Austenb29d2e82016-06-07 12:25:35 -0500314
leetb9a29a62022-05-17 19:30:25 +0000315 OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error}
Chris Austenb29d2e82016-06-07 12:25:35 -0500316 Import Library SCPLibrary WITH NAME scp
317 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD}
318 scp.Put File tools/ipmitool /tmp
319 SSHLibrary.Open Connection ${OPENBMC_HOST}
George Keishingf94de712021-11-10 13:59:44 -0600320 SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
leetb9a29a62022-05-17 19:30:25 +0000321 Execute Command chmod +x ${IPMITOOL_PATH}
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500322
Michael Walsh3ef2e922019-01-23 10:40:16 -0600323
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500324Initiate Host Boot Via External IPMI
325 [Documentation] Initiate host power on using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500326 [Arguments] ${wait}=${1}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600327
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500328 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600329 # wait Indicates that this keyword should wait
330 # for host running state.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500331
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500332 ${output}= Run External IPMI Standard Command chassis power on
333 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500334
335 Run Keyword If '${wait}' == '${0}' Return From Keyword
336 Wait Until Keyword Succeeds 10 min 10 sec Is Host Running
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500337
Michael Walsh3ef2e922019-01-23 10:40:16 -0600338
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500339Initiate Host PowerOff Via External IPMI
340 [Documentation] Initiate host power off using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500341 [Arguments] ${wait}=${1}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600342
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500343 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600344 # wait Indicates that this keyword should wait
345 # for host off state.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500346
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500347 ${output}= Run External IPMI Standard Command chassis power off
348 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500349
350 Run Keyword If '${wait}' == '${0}' Return From Keyword
351 Wait Until Keyword Succeeds 3 min 10 sec Is Host Off
352
Michael Walsh3ef2e922019-01-23 10:40:16 -0600353
Rahul Maheshwari460778d2020-02-23 22:37:22 -0600354Is Host Off Via IPMI
355 [Documentation] Verify if the Host is off using IPMI command.
356
357 ${status}= Run External IPMI Standard Command chassis power status
358 Should Contain ${status} off
359
360
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500361Get Host State Via External IPMI
362 [Documentation] Returns host state using external IPMI.
363
364 ${output}= Run External IPMI Standard Command chassis power status
365 Should Not Contain ${output} Error
366 ${output}= Fetch From Right ${output} ${SPACE}
367
368 [Return] ${output}
George Keishingb4d4a4a2018-08-27 13:35:39 -0500369
370
371Set BMC Network From Host
372 [Documentation] Set BMC network from host.
373 [Arguments] ${nw_info}
374
375 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600376 # nw_info A dictionary containing the network
377 # information to apply.
George Keishingb4d4a4a2018-08-27 13:35:39 -0500378
379 Run Inband IPMI Standard Command
380 ... lan set 1 ipaddr ${nw_info['IP Address']}
381
382 Run Inband IPMI Standard Command
383 ... lan set 1 netmask ${nw_info['Subnet Mask']}
384
385 Run Inband IPMI Standard Command
386 ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600387
388
389Verify IPMI Username And Password
390 [Documentation] Verify that user is able to run IPMI command
391 ... with given username and password.
392 [Arguments] ${username} ${password}
393
394 # Description of argument(s):
395 # username The user name (e.g. "root", "robert", etc.).
396 # password The user password (e.g. "0penBmc", "0penBmc1", etc.).
397
Tony Leef9379e82020-01-08 18:20:38 +0800398 ${output}= Wait Until Keyword Succeeds 15 sec 5 sec Run External IPMI Standard Command
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600399 ... sel info U=${username} P=${password}
400 Should Contain ${output} SEL Information msg=SEL information not present
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500401
402
403IPMI Create User
404 [Documentation] Create IPMI user with given userid and username.
405 [Arguments] ${userid} ${username}
406
407 # Description of argument(s):
408 # userid The user ID (e.g. "1", "2", etc.).
409 # username The user name (e.g. "root", "robert", etc.).
410
411 ${ipmi_cmd}= Catenate user set name ${userid} ${username}
412 ${resp}= Run IPMI Standard Command ${ipmi_cmd}
413 ${user_info}= Get User Info ${userid}
414 Should Be Equal ${user_info['user_name']} ${username}
415
416
nagarjunb22a2255de2022-05-25 19:15:10 +0530417Enable IPMI User And Verify
418 [Documentation] Enable the userid and verify that it has been enabled.
419 [Arguments] ${userid}
420
421 # Description of argument(s):
422 # userid A numeric userid (e.g. "4").
423
424 Run IPMI Standard Command user enable ${userid}
425 ${user_info}= Get User Info ${userid}
426 Valid Value user_info['enable_status'] ['enabled']
427
428
429Create Random IPMI User
430 [Documentation] Create IPMI user with random username and userid and return those fields.
431
432 ${random_username}= Generate Random String 8 [LETTERS]
433 ${random_userid}= Evaluate random.randint(2, 15) modules=random
434 IPMI Create User ${random_userid} ${random_username}
435 [Return] ${random_userid} ${random_username}
436
437
438Delete Created User
439 [Documentation] Delete created IPMI user.
440 [Arguments] ${userid}
441 # Description of argument(s):
442 # userid The user ID (e.g. "1", "2", etc.).
443
444 Run IPMI Standard Command user set name ${userid} ""
445 Sleep 5s
446
447
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500448Set Channel Access
449 [Documentation] Verify that user is able to run IPMI command
450 ... with given username and password.
Tony Lee7c5f4b22019-12-06 17:21:31 +0800451 [Arguments] ${userid} ${options} ${channel_number}=${CHANNEL_NUMBER}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500452
453 # Description of argument(s):
454 # userid The user ID (e.g. "1", "2", etc.).
455 # options Set channel command options (e.g.
456 # "link=on", "ipmi=on", etc.).
457 # channel_number The user's channel number (e.g. "1").
458
459 ${ipmi_cmd}= Catenate SEPARATOR=
Tony Lee7c5f4b22019-12-06 17:21:31 +0800460 ... channel setaccess${SPACE}${channel_number}${SPACE}${userid}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500461 ... ${SPACE}${options}
462 Run IPMI Standard Command ${ipmi_cmd}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500463
464
465Delete All Non Root IPMI User
466 [Documentation] Delete all non-root IPMI user.
467
Michael Walsh34c79af2019-12-09 11:46:48 -0600468 # Get complete list of user info records.
469 ${user_info}= Get User Info ${EMPTY}
470 # Remove header record.
471 ${user_info}= Filter Struct ${user_info} [('user_name', None)] invert=1
472 ${non_empty_user_info}= Filter Struct ${user_info} [('user_name', '')] invert=1
473 ${non_root_user_info}= Filter Struct ${non_empty_user_info} [('user_name', 'root')] invert=1
474
475 FOR ${user_record} IN @{non_root_user_info}
476 Run IPMI Standard Command user set name ${user_record['user_id']} ""
477 Sleep 5s
Rahul Maheshwari460778d2020-02-23 22:37:22 -0600478 END
chithrag0a8c8782022-03-01 12:35:00 +0000479
480
481Create SEL
482 [Documentation] Create a SEL.
483 [Arguments] ${sensor_type} ${sensor_number}
484
485 # Create a SEL.
486 # Example:
487 # a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted
chithrag0a8c8782022-03-01 12:35:00 +0000488 # Description of argument(s):
489 # ${sensor_type} Type of the sensor used in hexadecimal (can be fan, temp etc.,),
490 # obtained from Sensor Type field in - ipmitool sdr get "sensor_name".
491 # Example: Sensor Type (Threshold) : Fan (0x04), here 0xHH is sensor type.
492
493 # ${sensor_number} Sensor number of the sensor in hexadecimal.
494 # obtained from Sensor ID field in - ipmitool sdr get "sensor_name".
495 # Example: Sensor ID : SENSOR_1 (0xHH), here 0xHH is sensor number.
496
497 ${resp}= Run IPMI Command
498 ... ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][0]} 0x${sensor_type} 0x${sensor_number} ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][1]}
499
chithragd7e009b2022-03-01 12:20:57 +0000500 Should Not Contain ${resp} 00 00 msg=SEL not created.
501
chithrag0a8c8782022-03-01 12:35:00 +0000502 [Return] ${resp}
503
504
ganesanbebea55f2022-08-29 10:54:38 +0000505Fetch One Threshold Sensor From Sensor List
506 [Documentation] Fetch one threshold sensor randomly from Sensor list.
ganesanbd282b562022-05-11 20:30:52 +0530507
ganesanbebea55f2022-08-29 10:54:38 +0000508 @{sensor_name_list}= Create List
chithrag0a8c8782022-03-01 12:35:00 +0000509
510 ${resp}= Run IPMI Standard Command sensor
ganesanbebea55f2022-08-29 10:54:38 +0000511 @{sensor_list}= Split To Lines ${resp}
chithrag0a8c8782022-03-01 12:35:00 +0000512
ganesanbd282b562022-05-11 20:30:52 +0530513 # Omit the discrete sensor and create an threshold sensor name list
ganesanbebea55f2022-08-29 10:54:38 +0000514 FOR ${sensor} IN @{sensor_list}
ganesanbd282b562022-05-11 20:30:52 +0530515 ${discrete_sensor_status}= Run Keyword And Return Status Should Contain ${sensor} discrete
516 Continue For Loop If '${discrete_sensor_status}' == 'True'
517 ${sensor_details}= Split String ${sensor} |
518 ${get_sensor_name}= Get From List ${sensor_details} 0
519 ${sensor_name}= Set Variable ${get_sensor_name.strip()}
ganesanbebea55f2022-08-29 10:54:38 +0000520 Append To List ${sensor_name_list} ${sensor_name}
ganesanbd282b562022-05-11 20:30:52 +0530521 END
chithrag0a8c8782022-03-01 12:35:00 +0000522
ganesanbebea55f2022-08-29 10:54:38 +0000523 ${random_sensor_name}= Evaluate random.choice(${sensor_name_list}) random
chithrag0a8c8782022-03-01 12:35:00 +0000524
ganesanbd282b562022-05-11 20:30:52 +0530525 [Return] ${random_sensor_name}
chithrag0a8c8782022-03-01 12:35:00 +0000526
527Fetch Sensor Details From SDR
528 [Documentation] Identify the sensors from sdr get and fetch sensor details required.
529 [Arguments] ${sensor_name} ${setting}
530
531 # Description of argument(s):
532 # ${sensor_number} Sensor number of the sensor in hexadecimal.
533 # obtained sensor name from - 'ipmitool sensor' command.
534 # Example: a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted
535 # here, a is the sensor name.
536
537 # ${setting} Field to fetch data. Example : Sensor ID, Sensor Type (Threshold), etc,.
538
539 ${resp}= Run IPMI Standard Command sdr get "${sensor_name}"
540
541 ${setting_line}= Get Lines Containing String ${resp} ${setting}
542 ... case-insensitive
543 ${setting_status}= Fetch From Right ${setting_line} :${SPACE}
544
545 [Return] ${setting_status}
546
547
548Get Data And Byte From SDR Sensor
549 [Documentation] Fetch the Field Data and hexadecimal values from given details.
550 [Arguments] ${sensor_detail}
551
552 # Description of argument(s):
553 # ${sensor_detail} Requested field and the value from the sdr get ipmi command.
554 # Example : if Sensor ID is the requesting setting, then,
555 # ${sensor_detail} will be "Sensor ID : SENSOR_1 (0xHH)"
556
557 ${sensor_detail}= Split String ${sensor_detail} (0x
558 ${field_data}= Set Variable ${sensor_detail[0]}
559 ${field_data}= Remove Whitespace ${field_data}
560 ${sensor_hex}= Replace String ${sensor_detail[1]} ) ${EMPTY}
561 ${sensor_hex}= Zfill Data ${sensor_hex} 2
562
563 [Return] ${field_data} ${sensor_hex}
564
565
566Get Current Date from BMC
567 [Documentation] Runs the date command from BMC and returns current date and time
568
569 # Get Current Date from BMC
570 ${date} ${stderr} ${rc}= BMC Execute Command date
571
572 # Split the string and remove first and 2nd last value from the list and join to form %d %b %H:%M:%S %Y date format
573 ${date}= Split String ${date}
574 Remove From List ${date} 0
575 Remove From List ${date} -2
576 ${date}= Evaluate " ".join(${date})
577
578 # Convert the date format to %m/%d/%Y %H:%M:%S
579 ${date}= Convert Date ${date} date_format=%b %d %H:%M:%S %Y result_format=%m/%d/%Y %H:%M:%S exclude_millis=True
580
581 [Return] ${date}
chithragd7e009b2022-03-01 12:20:57 +0000582
583
584Get SEL Info Via IPMI
585 [Documentation] Get the SEL Info via IPMI raw command
586
587 # Get SEL Info response consist of 14 bytes of hexadecimal data.
588
589 # Byte 1 - SEL Version,
590 # Byte 2 & 3 - Entry bytes - LSB MSB,
591 # Byte 4 & 5 - Free Space in bytes, LS Byte first.
592 # Byte 6 - 9 - Most recent addition timestamp,
593 # Byte 10-13 - Most recent erase timestamp,
594 # Byte 14 - Operation Support
595
596 # Example: ${resp} will be "51 XX XX XX XX ff ff ff ff ff ff ff ff XX"
597
598 ${resp}= Run IPMI Standard Command
599 ... raw ${IPMI_RAW_CMD['SEL_entry']['SEL_info'][0]}
600 ${resp}= Split String ${resp}
601
602 [Return] ${resp}
nagarjunb227fabf792022-04-19 11:09:29 +0530603
604
605Verify Invalid IPMI Command
606 [Documentation] Execute invalid IPMI command and verify with given response code.
607 [Arguments] ${ipmi_cmd} ${error_code}=0xc9
608
609 # Description Of Arguments.
610 # ${ipmi_cmd} - IPMI raw cmd with invalid data length.
611 # ${error_code} - Expected error code e.g 0xc7, 0xcc.
612
613 ${resp}= Run External IPMI Raw Command ${ipmi_cmd} fail_on_err=0
614
ganesanbc288aff2022-05-19 19:55:47 +0530615 Should Contain ${resp} rsp=${error_code}
616
617
618Identify Request Data
619 [Documentation] Convert text from variable declared to request data.
620 [Arguments] ${string}
621
622 # Convert string to hexadecimal data for each character.
623 # Return the hex data with prefix of 0x as string and list of hex data.
624 # Description of argument(s):
625 # string Any string to be converted to hex.
626
627 # Given a string, convert to hexadecimal and prefix with 0x
628 ${hex1}= Create List
629 ${hex2}= Create List
630 ${resp_data}= Split String With Index ${string} 1
631 FOR ${data} IN @{resp_data}
632 # prefixes 0x by default
633 ${hex_value}= Evaluate hex(ord("${data}"))
634 # prefixes string with bytes prefixed 0x by default
635 Append To List ${hex1} ${hex_value}
636 # provides only hexadecimal bytes
637 ${hex}= Evaluate hex(ord("${data}"))[2:]
638 # provides string with only hexadecimal bytes
639 Append To List ${hex2} ${hex}
640 END
641 ${hex1}= Evaluate " ".join(${hex1})
642
643 # ${hex1} will contains the data to write for fru in list.
644 # ${hex2} will contains the data to verify fru after write operation completed.
645
646 [Return] ${hex1} ${hex2}