blob: c37a2afaf32be54c295d450c7722e8e80b8da72f [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
Ruud A. Haring9e4481b2023-12-08 12:08:01 -050025${IPMITOOL_PATH} /tmp/ipmitool
26${expected_max_ids} 15
27${empty_name_pattern} ^User Name\\s.*\\s:\\s$
Chris Austenb29d2e82016-06-07 12:25:35 -050028
29*** Keywords ***
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050030
Chris Austenb29d2e82016-06-07 12:25:35 -050031Run IPMI Command
Michael Walsh3ef2e922019-01-23 10:40:16 -060032 [Documentation] Run the raw IPMI command.
33 [Arguments] ${command} ${fail_on_err}=${1} &{options}
34
35 # Description of argument(s):
36 # command The IPMI command string to be executed
37 # (e.g. "power status").
38 # fail_on_err Fail if the IPMI command execution fails.
39 # options Additional ipmitool command options (e.g.
40 # -C=3, -I=lanplus, etc.). Currently, only
41 # used for external IPMI commands.
42
Prashanth Kattiae7c2282017-03-15 07:43:46 -050043 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Michael Walsh3ef2e922019-01-23 10:40:16 -060044 ... Run External IPMI Raw Command ${command} ${fail_on_err} &{options}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050045 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Michael Walsh3ef2e922019-01-23 10:40:16 -060046 ... Run Inband IPMI Raw Command ${command}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050047 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
Michael Walsh3ef2e922019-01-23 10:40:16 -060048 ... Run Dbus IPMI RAW Command ${command}
49 ... ELSE Fail msg=Invalid IPMI Command type provided: ${IPMI_COMMAND}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050050 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050051
Michael Walsh3ef2e922019-01-23 10:40:16 -060052
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050053Run IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050054 [Documentation] Run the standard IPMI command.
Michael Walshd0e58e72019-05-14 11:07:14 -050055 [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options}
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060056
57 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -060058 # command The IPMI command string to be executed
59 # (e.g. "0x06 0x36").
60 # fail_on_err Fail if the IPMI command execution fails.
Michael Walshd0e58e72019-05-14 11:07:14 -050061 # expected_rc The expected return code from the ipmi
62 # command (e.g. ${0}, ${1}, etc.).
Michael Walsh3ef2e922019-01-23 10:40:16 -060063 # options Additional ipmitool command options (e.g.
64 # -C=3, -I=lanplus, etc.). Currently, only
65 # used for external IPMI commands.
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060066
Prashanth Kattiae7c2282017-03-15 07:43:46 -050067 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Michael Walshd0e58e72019-05-14 11:07:14 -050068 ... Run External IPMI Standard Command ${command} ${fail_on_err} ${expected_rc} &{options}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050069 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Michael Walsh3ef2e922019-01-23 10:40:16 -060070 ... Run Inband IPMI Standard Command ${command} ${fail_on_err}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050071 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
Michael Walsh3ef2e922019-01-23 10:40:16 -060072 ... Run Dbus IPMI Standard Command ${command}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050073 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050074 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050075
Michael Walsh3ef2e922019-01-23 10:40:16 -060076
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050077Run Dbus IPMI RAW Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050078 [Documentation] Run the raw IPMI command through dbus.
Michael Walsh3ef2e922019-01-23 10:40:16 -060079 [Arguments] ${command}
80 ${valueinBytes}= Byte Conversion ${command}
Gunnar Mills59204d22016-12-06 11:05:19 -060081 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
82 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050083 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
84 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050085 set test variable ${OUTPUT} "${output}"
86
Michael Walsh3ef2e922019-01-23 10:40:16 -060087
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050088Run Dbus IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050089 [Documentation] Run the standard IPMI command through dbus.
Michael Walsh3ef2e922019-01-23 10:40:16 -060090 [Arguments] ${command}
George Keishing4d6c1da2016-07-15 05:51:22 -050091 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050092 ${stdout} ${stderr} ${output}= Execute Command
leetb9a29a62022-05-17 19:30:25 +000093 ... ${IPMITOOL_PATH} -I dbus ${command} return_stdout=True
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050094 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050095 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060096 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050097
Michael Walsh3ef2e922019-01-23 10:40:16 -060098
Prashanth Kattiae7c2282017-03-15 07:43:46 -050099Run Inband IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500100 [Documentation] Run the raw IPMI command in-band.
chithrag4ad123a2022-04-12 19:26:05 +0000101 [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500102 ... ${os_password}=${OS_PASSWORD}
103
Michael Walsh3ef2e922019-01-23 10:40:16 -0600104 # Description of argument(s):
105 # command The IPMI command string to be executed
106 # (e.g. "0x06 0x36").
107 # os_host The host name or IP address of the OS Host.
108 # os_username The OS host user name.
109 # os_password The OS host passwrd.
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500110
111 Login To OS Host ${os_host} ${os_username} ${os_password}
112 Check If IPMI Tool Exist
113
Michael Walsh3ef2e922019-01-23 10:40:16 -0600114 ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${command}
115 Qprint Issuing ${ipmi_cmd}
116 ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True
chithrag4ad123a2022-04-12 19:26:05 +0000117 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500118 Should Be Empty ${stderr} msg=${stdout}
119 [Return] ${stdout}
120
Michael Walsh3ef2e922019-01-23 10:40:16 -0600121
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500122Run Inband IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500123 [Documentation] Run the standard IPMI command in-band.
Michael Walsh3ef2e922019-01-23 10:40:16 -0600124 [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST}
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600125 ... ${os_username}=${OS_USERNAME} ${os_password}=${OS_PASSWORD}
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500126 ... ${login_host}=${1}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500127
Michael Walsh3ef2e922019-01-23 10:40:16 -0600128 # Description of argument(s):
129 # command The IPMI command string to be executed
130 # (e.g. "power status").
131 # os_host The host name or IP address of the OS Host.
132 # os_username The OS host user name.
133 # os_password The OS host passwrd.
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500134 # login_host Indicates that this keyword should login to host OS.
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500135
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500136 Run Keyword If ${login_host} == ${1}
137 ... Login To OS Host ${os_host} ${os_username} ${os_password}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500138 Check If IPMI Tool Exist
139
Michael Walsh3ef2e922019-01-23 10:40:16 -0600140 ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${command}
141 Qprint Issuing ${ipmi_cmd}
142 ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600143 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500144 Should Be Empty ${stderr} msg=${stdout}
145 [Return] ${stdout}
146
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500147
148Run External IPMI Standard Command
Michael Walsh3ef2e922019-01-23 10:40:16 -0600149 [Documentation] Run the external IPMI standard command.
Michael Walshd0e58e72019-05-14 11:07:14 -0500150 [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options}
George Keishing02651f02018-04-11 02:07:16 -0500151
152 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600153 # command The IPMI command string to be executed
154 # (e.g. "power status"). Note that if
155 # ${IPMI_USER_OPTIONS} has a value (e.g.
156 # "-vvv"), it will be pre-pended to this
157 # command string.
158 # fail_on_err Fail if the IPMI command execution fails.
Michael Walshd0e58e72019-05-14 11:07:14 -0500159 # expected_rc The expected return code from the ipmi
160 # command (e.g. ${0}, ${1}, etc.).
Michael Walsh3ef2e922019-01-23 10:40:16 -0600161 # options Additional ipmitool command options (e.g.
162 # -C=3, -I=lanplus, etc.).
Michael Walsha7913892017-04-20 16:29:01 -0500163
Michael Walsh3ef2e922019-01-23 10:40:16 -0600164 ${command_string}= Process IPMI User Options ${command}
165 ${ipmi_cmd}= Create IPMI Ext Command String ${command_string} &{options}
166 Qprint Issuing ${ipmi_cmd}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500167 ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd}
George Keishing02651f02018-04-11 02:07:16 -0500168 Return From Keyword If ${fail_on_err} == ${0} ${output}
Michael Walshd0e58e72019-05-14 11:07:14 -0500169 Should Be Equal ${rc} ${expected_rc} msg=${output}
Michael Walsha7913892017-04-20 16:29:01 -0500170 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500171
Michael Walsh3ef2e922019-01-23 10:40:16 -0600172
173Run External IPMI Raw Command
174 [Documentation] Run the external IPMI raw command.
175 [Arguments] ${command} ${fail_on_err}=${1} &{options}
176
177 # This keyword is a wrapper for 'Run External IPMI Standard Command'. See
178 # that keyword's prolog for argument details. This keyword will pre-pend
179 # the word "raw" plus a space to command prior to calling 'Run External
180 # IPMI Standard Command'.
181
182 ${output}= Run External IPMI Standard Command
183 ... raw ${command} ${fail_on_err} &{options}
184 [Return] ${output}
185
186
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500187Check If IPMI Tool Exist
188 [Documentation] Check if IPMI Tool installed or not.
189 ${output}= Execute Command which ipmitool
190 Should Not Be Empty ${output} msg=ipmitool not installed.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500191
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500192
193Activate SOL Via IPMI
194 [Documentation] Start SOL using IPMI and route output to a file.
George Keishing26206722021-11-17 01:29:53 -0600195 [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600196
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500197 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600198 # file_path The file path on the local machine (vs.
199 # OBMC) to collect SOL output. By default
200 # SOL output is collected at
George Keishing26206722021-11-17 01:29:53 -0600201 # logs/sol_<BMC_IP> else user input location.
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500202
Michael Walsh3ef2e922019-01-23 10:40:16 -0600203 ${ipmi_cmd}= Create IPMI Ext Command String sol activate usesolkeepalive
204 Qprint Issuing ${ipmi_cmd}
George Keishing2102f6b2017-06-06 08:30:10 -0500205 Start Process ${ipmi_cmd} shell=True stdout=${file_path}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500206 ... alias=sol_proc
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500207
208
209Deactivate SOL Via IPMI
210 [Documentation] Stop SOL using IPMI and return SOL output.
George Keishing26206722021-11-17 01:29:53 -0600211 [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600212
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500213 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600214 # file_path The file path on the local machine to copy
215 # SOL output collected by above "Activate
216 # SOL Via IPMI" keyword. By default it
George Keishing26206722021-11-17 01:29:53 -0600217 # copies log from logs/sol_<BMC_IP>.
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500218
Michael Walsh3ef2e922019-01-23 10:40:16 -0600219 ${ipmi_cmd}= Create IPMI Ext Command String sol deactivate
220 Qprint Issuing ${ipmi_cmd}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500221 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500222 Run Keyword If ${rc} > 0 Run Keywords
Rahul Maheshwari7f48a2c2017-06-16 04:00:26 -0500223 ... Run Keyword And Ignore Error Terminate Process sol_proc
224 ... AND Return From Keyword ${output}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500225
George Keishingaec8b872019-07-08 23:44:08 -0500226 ${output}= OperatingSystem.Get File ${file_path} encoding_errors=ignore
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500227
228 # Logging SOL output for debug purpose.
229 Log ${output}
230
231 [Return] ${output}
232
233
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500234Byte Conversion
235 [Documentation] Byte Conversion method receives IPMI RAW commands as
236 ... argument in string format.
237 ... Sample argument is as follows
238 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
239 ... 0x00"
240 ... IPMI RAW command format is as follows
241 ... <netfn Byte> <cmd Byte> <Data Bytes..>
242 ... This method converts IPMI command format into
243 ... dbus command format as follows
244 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
245 ... <array:byte:data>
246 ... Sample dbus Host IPMI Received Message argument
247 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30
248 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
Gunnar Mills38032802016-12-12 13:43:40 -0600249 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600250 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500251 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600252 @{listargs}= Split String ${args}
253 ${index}= Set Variable ${0}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500254 FOR ${word} IN @{listargs}
255 Run Keyword if ${index} == 0 Set NetFn Byte ${word}
256 Run Keyword if ${index} == 1 Set Cmd Byte ${word}
257 Run Keyword if ${index} > 1 Set Array Byte ${word}
258 ${index}= Set Variable ${index + 1}
259 END
Gunnar Mills59204d22016-12-06 11:05:19 -0600260 ${length}= Get Length ${arrayByte}
261 ${length}= Evaluate ${length} - 1
262 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500263 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600264 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
265 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte}
266 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte}
267 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
268 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600269 # To Check scenario for smaller IPMI raw commands with only 2 arguments
270 # instead of usual 12 arguments.
271 # Sample small IPMI raw command: Run IPMI command 0x06 0x36
272 # If IPMI raw argument length is only 9 then return value in bytes without
273 # array population.
274 # Equivalent dbus-send argument for smaller IPMI raw command:
275 # byte:0x00 byte:0x06 byte:0x00 byte:0x36
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500276 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600277 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500278
279
280Set NetFn Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500281 [Documentation] Set the network function byte.
282 [Arguments] ${word}
283 ${netfnByteLocal}= Catenate byte:${word}
284 Set Global Variable ${netfnByte} ${netfnByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500285
Michael Walsh3ef2e922019-01-23 10:40:16 -0600286
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500287Set Cmd Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500288 [Documentation] Set the command byte.
289 [Arguments] ${word}
290 ${cmdByteLocal}= Catenate byte:${word}
291 Set Global Variable ${cmdByte} ${cmdByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500292
Michael Walsh3ef2e922019-01-23 10:40:16 -0600293
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500294Set Array Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500295 [Documentation] Set the array byte.
296 [Arguments] ${word}
297 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
298 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
299 Set Global Variable ${arrayByte} ${arrayByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500300
Michael Walsh3ef2e922019-01-23 10:40:16 -0600301
Chris Austenb29d2e82016-06-07 12:25:35 -0500302Copy ipmitool
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500303 [Documentation] Copy the ipmitool to the BMC.
304 ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory.
305 ... It is not part of the automation code by default. You must manually copy or link the correct openbmc
306 ... version of the tool in to the tools directory in order to run this test suite.
307
leetb9a29a62022-05-17 19:30:25 +0000308 ${response} ${stderr} ${rc}= BMC Execute Command
309 ... which ipmitool ignore_err=${1}
310 ${installed}= Get Regexp Matches ${response} ipmitool
311 Run Keyword If ${installed} == ['ipmitool']
312 ... Run Keywords Set Suite Variable ${IPMITOOL_PATH} ${response}
313 ... AND SSHLibrary.Open Connection ${OPENBMC_HOST}
314 ... AND SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
315 ... AND Return From Keyword
Chris Austenb29d2e82016-06-07 12:25:35 -0500316
leetb9a29a62022-05-17 19:30:25 +0000317 OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error}
Chris Austenb29d2e82016-06-07 12:25:35 -0500318 Import Library SCPLibrary WITH NAME scp
319 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD}
320 scp.Put File tools/ipmitool /tmp
321 SSHLibrary.Open Connection ${OPENBMC_HOST}
George Keishingf94de712021-11-10 13:59:44 -0600322 SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
leetb9a29a62022-05-17 19:30:25 +0000323 Execute Command chmod +x ${IPMITOOL_PATH}
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500324
Michael Walsh3ef2e922019-01-23 10:40:16 -0600325
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500326Initiate Host Boot Via External IPMI
327 [Documentation] Initiate host power on using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500328 [Arguments] ${wait}=${1}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600329
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500330 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600331 # wait Indicates that this keyword should wait
332 # for host running state.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500333
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500334 ${output}= Run External IPMI Standard Command chassis power on
335 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500336
337 Run Keyword If '${wait}' == '${0}' Return From Keyword
338 Wait Until Keyword Succeeds 10 min 10 sec Is Host Running
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500339
Michael Walsh3ef2e922019-01-23 10:40:16 -0600340
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500341Initiate Host PowerOff Via External IPMI
342 [Documentation] Initiate host power off using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500343 [Arguments] ${wait}=${1}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600344
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500345 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600346 # wait Indicates that this keyword should wait
347 # for host off state.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500348
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500349 ${output}= Run External IPMI Standard Command chassis power off
350 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500351
352 Run Keyword If '${wait}' == '${0}' Return From Keyword
353 Wait Until Keyword Succeeds 3 min 10 sec Is Host Off
354
Michael Walsh3ef2e922019-01-23 10:40:16 -0600355
Rahul Maheshwari460778d2020-02-23 22:37:22 -0600356Is Host Off Via IPMI
357 [Documentation] Verify if the Host is off using IPMI command.
358
359 ${status}= Run External IPMI Standard Command chassis power status
360 Should Contain ${status} off
361
362
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500363Get Host State Via External IPMI
364 [Documentation] Returns host state using external IPMI.
365
366 ${output}= Run External IPMI Standard Command chassis power status
367 Should Not Contain ${output} Error
368 ${output}= Fetch From Right ${output} ${SPACE}
369
370 [Return] ${output}
George Keishingb4d4a4a2018-08-27 13:35:39 -0500371
372
373Set BMC Network From Host
374 [Documentation] Set BMC network from host.
375 [Arguments] ${nw_info}
376
377 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600378 # nw_info A dictionary containing the network
379 # information to apply.
George Keishingb4d4a4a2018-08-27 13:35:39 -0500380
381 Run Inband IPMI Standard Command
382 ... lan set 1 ipaddr ${nw_info['IP Address']}
383
384 Run Inband IPMI Standard Command
385 ... lan set 1 netmask ${nw_info['Subnet Mask']}
386
387 Run Inband IPMI Standard Command
388 ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600389
390
391Verify IPMI Username And Password
392 [Documentation] Verify that user is able to run IPMI command
393 ... with given username and password.
394 [Arguments] ${username} ${password}
395
396 # Description of argument(s):
397 # username The user name (e.g. "root", "robert", etc.).
George Keishing7ac1f562023-11-27 21:46:47 +0530398 # password The user password.
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600399
Tony Leef9379e82020-01-08 18:20:38 +0800400 ${output}= Wait Until Keyword Succeeds 15 sec 5 sec Run External IPMI Standard Command
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600401 ... sel info U=${username} P=${password}
402 Should Contain ${output} SEL Information msg=SEL information not present
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500403
404
405IPMI Create User
406 [Documentation] Create IPMI user with given userid and username.
407 [Arguments] ${userid} ${username}
408
409 # Description of argument(s):
410 # userid The user ID (e.g. "1", "2", etc.).
411 # username The user name (e.g. "root", "robert", etc.).
412
413 ${ipmi_cmd}= Catenate user set name ${userid} ${username}
414 ${resp}= Run IPMI Standard Command ${ipmi_cmd}
Nagarjun B26499142023-02-16 15:20:14 +0530415 ${user_info}= Get User Info ${userid} ${CHANNEL_NUMBER}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500416 Should Be Equal ${user_info['user_name']} ${username}
417
418
nagarjunb22a2255de2022-05-25 19:15:10 +0530419Enable IPMI User And Verify
420 [Documentation] Enable the userid and verify that it has been enabled.
421 [Arguments] ${userid}
422
423 # Description of argument(s):
424 # userid A numeric userid (e.g. "4").
425
426 Run IPMI Standard Command user enable ${userid}
Nagarjun B26499142023-02-16 15:20:14 +0530427 ${user_info}= Get User Info ${userid} ${CHANNEL_NUMBER}
nagarjunb22a2255de2022-05-25 19:15:10 +0530428 Valid Value user_info['enable_status'] ['enabled']
429
430
431Create Random IPMI User
432 [Documentation] Create IPMI user with random username and userid and return those fields.
433
434 ${random_username}= Generate Random String 8 [LETTERS]
Ruud A. Haring9e4481b2023-12-08 12:08:01 -0500435 ${random_userid}= Find Free User Id
nagarjunb22a2255de2022-05-25 19:15:10 +0530436 IPMI Create User ${random_userid} ${random_username}
Ruud A. Haring9e4481b2023-12-08 12:08:01 -0500437 Wait And Confirm New User Entry ${random_username}
nagarjunb22a2255de2022-05-25 19:15:10 +0530438 [Return] ${random_userid} ${random_username}
439
440
Ruud A. Haring9e4481b2023-12-08 12:08:01 -0500441Find Free User Id
442 [Documentation] Find a userid that is not being used.
443
444 Check Enabled User Count
445 FOR ${num} IN RANGE 300
446 ${random_userid}= Evaluate random.randint(1, ${expected_max_ids}) modules=random
447 ${access}= Run IPMI Standard Command channel getaccess ${CHANNEL_NUMBER} ${random_userid}
448
449 ${name_line}= Get Lines Containing String ${access} User Name
450 Log To Console For ID ${random_userid}: ${name_line}
451 ${is_empty}= Run Keyword And Return Status
452 ... Should Match Regexp ${name_line} ${empty_name_pattern}
453
454 Exit For Loop If ${is_empty} == ${True}
455 END
456 [Return] ${random_userid}
457
458
459Check Enabled User Count
460 [Documentation] Ensure that there are available user IDs.
461
462 # Check for the enabled user count
463 ${resp}= Run IPMI Standard Command user summary ${CHANNEL_NUMBER}
464 ${enabled_user_count}=
465 ... Get Lines Containing String ${resp} Enabled User Count
466
467 Should not contain ${enabled_user_count} ${expected_max_ids}
468 ... msg=IPMI has reached maximum user count
469
470
471Wait And Confirm New User Entry
472 [Documentation] Wait in loop until new user appears with given username.
473 [Arguments] ${username}
474
475 # Description of argument(s):
476 # username The user name (e.g. "root", "robert", etc.).
477
478 Wait Until Keyword Succeeds 45 sec 1 sec Verify IPMI Username Visible
479 ... ${username}
480
481
482Verify IPMI Username Visible
483 [Documentation] Confirm that username is present in user list.
484 [Arguments] ${username}
485
486 # Description of argument(s):
487 # username The user name (e.g. "root", "robert", etc.).
488
489 ${resp}= Run IPMI Standard Command user list
490 Should Contain ${resp} ${username}
491
492
nagarjunb22a2255de2022-05-25 19:15:10 +0530493Delete Created User
494 [Documentation] Delete created IPMI user.
495 [Arguments] ${userid}
496 # Description of argument(s):
497 # userid The user ID (e.g. "1", "2", etc.).
498
499 Run IPMI Standard Command user set name ${userid} ""
500 Sleep 5s
501
502
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500503Set Channel Access
504 [Documentation] Verify that user is able to run IPMI command
505 ... with given username and password.
Tony Lee7c5f4b22019-12-06 17:21:31 +0800506 [Arguments] ${userid} ${options} ${channel_number}=${CHANNEL_NUMBER}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500507
508 # Description of argument(s):
509 # userid The user ID (e.g. "1", "2", etc.).
510 # options Set channel command options (e.g.
511 # "link=on", "ipmi=on", etc.).
512 # channel_number The user's channel number (e.g. "1").
513
514 ${ipmi_cmd}= Catenate SEPARATOR=
Tony Lee7c5f4b22019-12-06 17:21:31 +0800515 ... channel setaccess${SPACE}${channel_number}${SPACE}${userid}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500516 ... ${SPACE}${options}
517 Run IPMI Standard Command ${ipmi_cmd}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500518
519
520Delete All Non Root IPMI User
521 [Documentation] Delete all non-root IPMI user.
522
Michael Walsh34c79af2019-12-09 11:46:48 -0600523 # Get complete list of user info records.
Nagarjun B26499142023-02-16 15:20:14 +0530524 ${user_info}= Get User Info ${EMPTY} ${CHANNEL_NUMBER}
Michael Walsh34c79af2019-12-09 11:46:48 -0600525 # Remove header record.
526 ${user_info}= Filter Struct ${user_info} [('user_name', None)] invert=1
527 ${non_empty_user_info}= Filter Struct ${user_info} [('user_name', '')] invert=1
528 ${non_root_user_info}= Filter Struct ${non_empty_user_info} [('user_name', 'root')] invert=1
529
530 FOR ${user_record} IN @{non_root_user_info}
531 Run IPMI Standard Command user set name ${user_record['user_id']} ""
532 Sleep 5s
Rahul Maheshwari460778d2020-02-23 22:37:22 -0600533 END
chithrag0a8c8782022-03-01 12:35:00 +0000534
535
536Create SEL
537 [Documentation] Create a SEL.
538 [Arguments] ${sensor_type} ${sensor_number}
539
540 # Create a SEL.
541 # Example:
542 # a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted
chithrag0a8c8782022-03-01 12:35:00 +0000543 # Description of argument(s):
544 # ${sensor_type} Type of the sensor used in hexadecimal (can be fan, temp etc.,),
545 # obtained from Sensor Type field in - ipmitool sdr get "sensor_name".
546 # Example: Sensor Type (Threshold) : Fan (0x04), here 0xHH is sensor type.
547
548 # ${sensor_number} Sensor number of the sensor in hexadecimal.
549 # obtained from Sensor ID field in - ipmitool sdr get "sensor_name".
550 # Example: Sensor ID : SENSOR_1 (0xHH), here 0xHH is sensor number.
551
ganesanba8aee232023-04-08 12:17:15 +0000552 ${cmd}= Catenate ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][0]} 0x${GEN_ID_BYTE_1} 0x${GEN_ID_BYTE_2}
553 ... ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][1]} 0x${sensor_type} 0x${sensor_number}
554 ... ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][2]}
555
556 ${resp}= Run IPMI Command ${cmd}
chithrag0a8c8782022-03-01 12:35:00 +0000557
chithragd7e009b2022-03-01 12:20:57 +0000558 Should Not Contain ${resp} 00 00 msg=SEL not created.
559
manimozhik75379c92023-11-08 18:40:11 +0000560 Sleep 5s
561
chithrag0a8c8782022-03-01 12:35:00 +0000562 [Return] ${resp}
563
564
ganesanbebea55f2022-08-29 10:54:38 +0000565Fetch One Threshold Sensor From Sensor List
566 [Documentation] Fetch one threshold sensor randomly from Sensor list.
ganesanbd282b562022-05-11 20:30:52 +0530567
ganesanbebea55f2022-08-29 10:54:38 +0000568 @{sensor_name_list}= Create List
chithrag0a8c8782022-03-01 12:35:00 +0000569
570 ${resp}= Run IPMI Standard Command sensor
ganesanbebea55f2022-08-29 10:54:38 +0000571 @{sensor_list}= Split To Lines ${resp}
chithrag0a8c8782022-03-01 12:35:00 +0000572
ganesanbd282b562022-05-11 20:30:52 +0530573 # Omit the discrete sensor and create an threshold sensor name list
ganesanbebea55f2022-08-29 10:54:38 +0000574 FOR ${sensor} IN @{sensor_list}
ganesanbd282b562022-05-11 20:30:52 +0530575 ${discrete_sensor_status}= Run Keyword And Return Status Should Contain ${sensor} discrete
576 Continue For Loop If '${discrete_sensor_status}' == 'True'
577 ${sensor_details}= Split String ${sensor} |
578 ${get_sensor_name}= Get From List ${sensor_details} 0
579 ${sensor_name}= Set Variable ${get_sensor_name.strip()}
ganesanbebea55f2022-08-29 10:54:38 +0000580 Append To List ${sensor_name_list} ${sensor_name}
ganesanbd282b562022-05-11 20:30:52 +0530581 END
chithrag0a8c8782022-03-01 12:35:00 +0000582
ganesanbebea55f2022-08-29 10:54:38 +0000583 ${random_sensor_name}= Evaluate random.choice(${sensor_name_list}) random
chithrag0a8c8782022-03-01 12:35:00 +0000584
ganesanbd282b562022-05-11 20:30:52 +0530585 [Return] ${random_sensor_name}
chithrag0a8c8782022-03-01 12:35:00 +0000586
587Fetch Sensor Details From SDR
588 [Documentation] Identify the sensors from sdr get and fetch sensor details required.
589 [Arguments] ${sensor_name} ${setting}
590
591 # Description of argument(s):
592 # ${sensor_number} Sensor number of the sensor in hexadecimal.
593 # obtained sensor name from - 'ipmitool sensor' command.
594 # Example: a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted
595 # here, a is the sensor name.
596
597 # ${setting} Field to fetch data. Example : Sensor ID, Sensor Type (Threshold), etc,.
598
599 ${resp}= Run IPMI Standard Command sdr get "${sensor_name}"
600
601 ${setting_line}= Get Lines Containing String ${resp} ${setting}
602 ... case-insensitive
603 ${setting_status}= Fetch From Right ${setting_line} :${SPACE}
604
605 [Return] ${setting_status}
606
607
ganesanb11fe27f2022-08-24 10:00:17 +0000608Get Bytes From SDR Sensor
chithrag0a8c8782022-03-01 12:35:00 +0000609 [Documentation] Fetch the Field Data and hexadecimal values from given details.
610 [Arguments] ${sensor_detail}
611
612 # Description of argument(s):
613 # ${sensor_detail} Requested field and the value from the sdr get ipmi command.
614 # Example : if Sensor ID is the requesting setting, then,
615 # ${sensor_detail} will be "Sensor ID : SENSOR_1 (0xHH)"
616
617 ${sensor_detail}= Split String ${sensor_detail} (0x
chithrag0a8c8782022-03-01 12:35:00 +0000618 ${sensor_hex}= Replace String ${sensor_detail[1]} ) ${EMPTY}
619 ${sensor_hex}= Zfill Data ${sensor_hex} 2
620
ganesanb11fe27f2022-08-24 10:00:17 +0000621 [Return] ${sensor_hex}
chithrag0a8c8782022-03-01 12:35:00 +0000622
623
624Get Current Date from BMC
625 [Documentation] Runs the date command from BMC and returns current date and time
Anusha Dathatri0b29ed32023-11-28 06:48:56 -0600626 [Arguments] ${date_format}=%m/%d/%Y %H:%M:%S
627
628 # Description of argument(s):
629 # date_format Date format of the result. E.g. %Y-%m-%d %H:%M:%S etc.
chithrag0a8c8782022-03-01 12:35:00 +0000630
631 # Get Current Date from BMC
632 ${date} ${stderr} ${rc}= BMC Execute Command date
633
634 # 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
635 ${date}= Split String ${date}
636 Remove From List ${date} 0
637 Remove From List ${date} -2
638 ${date}= Evaluate " ".join(${date})
639
Anusha Dathatri0b29ed32023-11-28 06:48:56 -0600640 # Convert the date to specified format, default:%m/%d/%Y %H:%M:%S
641 ${date}= Convert Date ${date} date_format=%b %d %H:%M:%S %Y result_format=${date_format} exclude_millis=True
chithrag0a8c8782022-03-01 12:35:00 +0000642
643 [Return] ${date}
chithragd7e009b2022-03-01 12:20:57 +0000644
645
646Get SEL Info Via IPMI
647 [Documentation] Get the SEL Info via IPMI raw command
648
649 # Get SEL Info response consist of 14 bytes of hexadecimal data.
650
651 # Byte 1 - SEL Version,
652 # Byte 2 & 3 - Entry bytes - LSB MSB,
653 # Byte 4 & 5 - Free Space in bytes, LS Byte first.
654 # Byte 6 - 9 - Most recent addition timestamp,
655 # Byte 10-13 - Most recent erase timestamp,
656 # Byte 14 - Operation Support
657
658 # Example: ${resp} will be "51 XX XX XX XX ff ff ff ff ff ff ff ff XX"
659
ishwaryamathim372cd862023-11-14 18:12:23 +0000660 ${resp}= Run IPMI Command
661 ... ${IPMI_RAW_CMD['SEL_entry']['SEL_info'][0]}
chithragd7e009b2022-03-01 12:20:57 +0000662 ${resp}= Split String ${resp}
663
664 [Return] ${resp}
nagarjunb227fabf792022-04-19 11:09:29 +0530665
666
667Verify Invalid IPMI Command
668 [Documentation] Execute invalid IPMI command and verify with given response code.
669 [Arguments] ${ipmi_cmd} ${error_code}=0xc9
670
671 # Description Of Arguments.
672 # ${ipmi_cmd} - IPMI raw cmd with invalid data length.
673 # ${error_code} - Expected error code e.g 0xc7, 0xcc.
674
ishwaryamathim372cd862023-11-14 18:12:23 +0000675 ${resp}= Run IPMI Command ${ipmi_cmd} fail_on_err=0
nagarjunb227fabf792022-04-19 11:09:29 +0530676
ganesanbc288aff2022-05-19 19:55:47 +0530677 Should Contain ${resp} rsp=${error_code}
678
679
680Identify Request Data
681 [Documentation] Convert text from variable declared to request data.
682 [Arguments] ${string}
683
684 # Convert string to hexadecimal data for each character.
685 # Return the hex data with prefix of 0x as string and list of hex data.
686 # Description of argument(s):
687 # string Any string to be converted to hex.
688
689 # Given a string, convert to hexadecimal and prefix with 0x
690 ${hex1}= Create List
691 ${hex2}= Create List
692 ${resp_data}= Split String With Index ${string} 1
693 FOR ${data} IN @{resp_data}
694 # prefixes 0x by default
695 ${hex_value}= Evaluate hex(ord("${data}"))
696 # prefixes string with bytes prefixed 0x by default
697 Append To List ${hex1} ${hex_value}
698 # provides only hexadecimal bytes
699 ${hex}= Evaluate hex(ord("${data}"))[2:]
700 # provides string with only hexadecimal bytes
701 Append To List ${hex2} ${hex}
702 END
703 ${hex1}= Evaluate " ".join(${hex1})
704
705 # ${hex1} will contains the data to write for fru in list.
706 # ${hex2} will contains the data to verify fru after write operation completed.
707
Nagarjun B26499142023-02-16 15:20:14 +0530708 [Return] ${hex1} ${hex2}