blob: 8bee9dadb27eda69e895e72d9a58993922de1e78 [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
Sivas SRRa2dab3c2016-07-25 05:08:18 -050013
14*** Variables ***
George Keishingd7f11f72017-01-04 10:58:19 -060015${dbusHostIpmicmd1}= dbus-send --system ${OPENBMC_BASE_URI}HostIpmi/1
16${dbusHostIpmiCmdReceivedMsg}= ${OPENBMC_BASE_DBUS}.HostIpmi.ReceivedMessage
Gunnar Mills59204d22016-12-06 11:05:19 -060017${netfnByte}= ${EMPTY}
George Keishingd7f11f72017-01-04 10:58:19 -060018${cmdByte}= ${EMPTY}
Gunnar Mills59204d22016-12-06 11:05:19 -060019${arrayByte}= array:byte:
Michael Walsha7913892017-04-20 16:29:01 -050020${IPMI_USER_OPTIONS} ${EMPTY}
George Keishing75f55dc2021-03-29 10:48:09 -050021${IPMI_INBAND_CMD}= ipmitool -C ${IPMI_CIPHER_LEVEL} -N ${IPMI_TIMEOUT} -p ${IPMI_PORT}
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
Michael Walsh3ef2e922019-01-23 10:40:16 -060028 [Documentation] Run the raw IPMI command.
29 [Arguments] ${command} ${fail_on_err}=${1} &{options}
30
31 # Description of argument(s):
32 # command The IPMI command string to be executed
33 # (e.g. "power status").
34 # fail_on_err Fail if the IPMI command execution fails.
35 # options Additional ipmitool command options (e.g.
36 # -C=3, -I=lanplus, etc.). Currently, only
37 # used for external IPMI commands.
38
Prashanth Kattiae7c2282017-03-15 07:43:46 -050039 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Michael Walsh3ef2e922019-01-23 10:40:16 -060040 ... Run External IPMI Raw Command ${command} ${fail_on_err} &{options}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050041 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Michael Walsh3ef2e922019-01-23 10:40:16 -060042 ... Run Inband IPMI Raw Command ${command}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050043 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
Michael Walsh3ef2e922019-01-23 10:40:16 -060044 ... Run Dbus IPMI RAW Command ${command}
45 ... ELSE Fail msg=Invalid IPMI Command type provided: ${IPMI_COMMAND}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050046 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050047
Michael Walsh3ef2e922019-01-23 10:40:16 -060048
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050049Run IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050050 [Documentation] Run the standard IPMI command.
Michael Walshd0e58e72019-05-14 11:07:14 -050051 [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options}
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060052
53 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -060054 # command The IPMI command string to be executed
55 # (e.g. "0x06 0x36").
56 # fail_on_err Fail if the IPMI command execution fails.
Michael Walshd0e58e72019-05-14 11:07:14 -050057 # expected_rc The expected return code from the ipmi
58 # command (e.g. ${0}, ${1}, etc.).
Michael Walsh3ef2e922019-01-23 10:40:16 -060059 # options Additional ipmitool command options (e.g.
60 # -C=3, -I=lanplus, etc.). Currently, only
61 # used for external IPMI commands.
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -060062
Prashanth Kattiae7c2282017-03-15 07:43:46 -050063 ${resp}= Run Keyword If '${IPMI_COMMAND}' == 'External'
Michael Walshd0e58e72019-05-14 11:07:14 -050064 ... Run External IPMI Standard Command ${command} ${fail_on_err} ${expected_rc} &{options}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050065 ... ELSE IF '${IPMI_COMMAND}' == 'Inband'
Michael Walsh3ef2e922019-01-23 10:40:16 -060066 ... Run Inband IPMI Standard Command ${command} ${fail_on_err}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050067 ... ELSE IF '${IPMI_COMMAND}' == 'Dbus'
Michael Walsh3ef2e922019-01-23 10:40:16 -060068 ... Run Dbus IPMI Standard Command ${command}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050069 ... ELSE Fail msg=Invalid IPMI Command type provided : ${IPMI_COMMAND}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050070 [Return] ${resp}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050071
Michael Walsh3ef2e922019-01-23 10:40:16 -060072
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050073Run Dbus IPMI RAW Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050074 [Documentation] Run the raw IPMI command through dbus.
Michael Walsh3ef2e922019-01-23 10:40:16 -060075 [Arguments] ${command}
76 ${valueinBytes}= Byte Conversion ${command}
Gunnar Mills59204d22016-12-06 11:05:19 -060077 ${cmd}= Catenate ${dbushostipmicmd1} ${dbusHostIpmiCmdReceivedMsg}
78 ${cmd}= Catenate ${cmd} ${valueinBytes}
Sivas SRRa2dab3c2016-07-25 05:08:18 -050079 ${output} ${stderr}= Execute Command ${cmd} return_stderr=True
80 Should Be Empty ${stderr}
Chris Austenb29d2e82016-06-07 12:25:35 -050081 set test variable ${OUTPUT} "${output}"
82
Michael Walsh3ef2e922019-01-23 10:40:16 -060083
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050084Run Dbus IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050085 [Documentation] Run the standard IPMI command through dbus.
Michael Walsh3ef2e922019-01-23 10:40:16 -060086 [Arguments] ${command}
George Keishing4d6c1da2016-07-15 05:51:22 -050087 Copy ipmitool
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050088 ${stdout} ${stderr} ${output}= Execute Command
Michael Walsh3ef2e922019-01-23 10:40:16 -060089 ... /tmp/ipmitool -I dbus ${command} return_stdout=True
Rahul Maheshwari7a212a02016-09-05 21:17:30 -050090 ... return_stderr= True return_rc=True
Chris Austenb29d2e82016-06-07 12:25:35 -050091 Should Be Equal ${output} ${0} msg=${stderr}
Gunnar Millsc9ea9362016-12-13 16:21:13 -060092 [Return] ${stdout}
Chris Austenb29d2e82016-06-07 12:25:35 -050093
Michael Walsh3ef2e922019-01-23 10:40:16 -060094
Prashanth Kattiae7c2282017-03-15 07:43:46 -050095Run Inband IPMI Raw Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -050096 [Documentation] Run the raw IPMI command in-band.
chithrag4ad123a2022-04-12 19:26:05 +000097 [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
Prashanth Kattiae7c2282017-03-15 07:43:46 -050098 ... ${os_password}=${OS_PASSWORD}
99
Michael Walsh3ef2e922019-01-23 10:40:16 -0600100 # Description of argument(s):
101 # command The IPMI command string to be executed
102 # (e.g. "0x06 0x36").
103 # os_host The host name or IP address of the OS Host.
104 # os_username The OS host user name.
105 # os_password The OS host passwrd.
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500106
107 Login To OS Host ${os_host} ${os_username} ${os_password}
108 Check If IPMI Tool Exist
109
Michael Walsh3ef2e922019-01-23 10:40:16 -0600110 ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${RAW} ${command}
111 Qprint Issuing ${ipmi_cmd}
112 ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True
chithrag4ad123a2022-04-12 19:26:05 +0000113 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500114 Should Be Empty ${stderr} msg=${stdout}
115 [Return] ${stdout}
116
Michael Walsh3ef2e922019-01-23 10:40:16 -0600117
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500118Run Inband IPMI Standard Command
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500119 [Documentation] Run the standard IPMI command in-band.
Michael Walsh3ef2e922019-01-23 10:40:16 -0600120 [Arguments] ${command} ${fail_on_err}=${1} ${os_host}=${OS_HOST}
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600121 ... ${os_username}=${OS_USERNAME} ${os_password}=${OS_PASSWORD}
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500122 ... ${login_host}=${1}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500123
Michael Walsh3ef2e922019-01-23 10:40:16 -0600124 # Description of argument(s):
125 # command The IPMI command string to be executed
126 # (e.g. "power status").
127 # os_host The host name or IP address of the OS Host.
128 # os_username The OS host user name.
129 # os_password The OS host passwrd.
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500130 # login_host Indicates that this keyword should login to host OS.
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500131
Naman Navin Hegde9e8c0d82019-08-11 15:22:44 -0500132 Run Keyword If ${login_host} == ${1}
133 ... Login To OS Host ${os_host} ${os_username} ${os_password}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500134 Check If IPMI Tool Exist
135
Michael Walsh3ef2e922019-01-23 10:40:16 -0600136 ${ipmi_cmd}= Catenate ${IPMI_INBAND_CMD} ${command}
137 Qprint Issuing ${ipmi_cmd}
138 ${stdout} ${stderr}= Execute Command ${ipmi_cmd} return_stderr=True
Rahul Maheshwari20f3bf72018-12-18 04:24:20 -0600139 Return From Keyword If ${fail_on_err} == ${0} ${stderr}
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500140 Should Be Empty ${stderr} msg=${stdout}
141 [Return] ${stdout}
142
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500143
144Run External IPMI Standard Command
Michael Walsh3ef2e922019-01-23 10:40:16 -0600145 [Documentation] Run the external IPMI standard command.
Michael Walshd0e58e72019-05-14 11:07:14 -0500146 [Arguments] ${command} ${fail_on_err}=${1} ${expected_rc}=${0} &{options}
George Keishing02651f02018-04-11 02:07:16 -0500147
148 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600149 # command The IPMI command string to be executed
150 # (e.g. "power status"). Note that if
151 # ${IPMI_USER_OPTIONS} has a value (e.g.
152 # "-vvv"), it will be pre-pended to this
153 # command string.
154 # fail_on_err Fail if the IPMI command execution fails.
Michael Walshd0e58e72019-05-14 11:07:14 -0500155 # expected_rc The expected return code from the ipmi
156 # command (e.g. ${0}, ${1}, etc.).
Michael Walsh3ef2e922019-01-23 10:40:16 -0600157 # options Additional ipmitool command options (e.g.
158 # -C=3, -I=lanplus, etc.).
Michael Walsha7913892017-04-20 16:29:01 -0500159
Michael Walsh3ef2e922019-01-23 10:40:16 -0600160 ${command_string}= Process IPMI User Options ${command}
161 ${ipmi_cmd}= Create IPMI Ext Command String ${command_string} &{options}
162 Qprint Issuing ${ipmi_cmd}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500163 ${rc} ${output}= Run And Return RC and Output ${ipmi_cmd}
George Keishing02651f02018-04-11 02:07:16 -0500164 Return From Keyword If ${fail_on_err} == ${0} ${output}
Michael Walshd0e58e72019-05-14 11:07:14 -0500165 Should Be Equal ${rc} ${expected_rc} msg=${output}
Michael Walsha7913892017-04-20 16:29:01 -0500166 [Return] ${output}
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500167
Michael Walsh3ef2e922019-01-23 10:40:16 -0600168
169Run External IPMI Raw Command
170 [Documentation] Run the external IPMI raw command.
171 [Arguments] ${command} ${fail_on_err}=${1} &{options}
172
173 # This keyword is a wrapper for 'Run External IPMI Standard Command'. See
174 # that keyword's prolog for argument details. This keyword will pre-pend
175 # the word "raw" plus a space to command prior to calling 'Run External
176 # IPMI Standard Command'.
177
178 ${output}= Run External IPMI Standard Command
179 ... raw ${command} ${fail_on_err} &{options}
180 [Return] ${output}
181
182
Prashanth Kattiae7c2282017-03-15 07:43:46 -0500183Check If IPMI Tool Exist
184 [Documentation] Check if IPMI Tool installed or not.
185 ${output}= Execute Command which ipmitool
186 Should Not Be Empty ${output} msg=ipmitool not installed.
Rahul Maheshwari7a212a02016-09-05 21:17:30 -0500187
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500188
189Activate SOL Via IPMI
190 [Documentation] Start SOL using IPMI and route output to a file.
George Keishing26206722021-11-17 01:29:53 -0600191 [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600192
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500193 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600194 # file_path The file path on the local machine (vs.
195 # OBMC) to collect SOL output. By default
196 # SOL output is collected at
George Keishing26206722021-11-17 01:29:53 -0600197 # logs/sol_<BMC_IP> else user input location.
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500198
Michael Walsh3ef2e922019-01-23 10:40:16 -0600199 ${ipmi_cmd}= Create IPMI Ext Command String sol activate usesolkeepalive
200 Qprint Issuing ${ipmi_cmd}
George Keishing2102f6b2017-06-06 08:30:10 -0500201 Start Process ${ipmi_cmd} shell=True stdout=${file_path}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500202 ... alias=sol_proc
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500203
204
205Deactivate SOL Via IPMI
206 [Documentation] Stop SOL using IPMI and return SOL output.
George Keishing26206722021-11-17 01:29:53 -0600207 [Arguments] ${file_path}=${IPMI_SOL_LOG_FILE}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600208
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500209 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600210 # file_path The file path on the local machine to copy
211 # SOL output collected by above "Activate
212 # SOL Via IPMI" keyword. By default it
George Keishing26206722021-11-17 01:29:53 -0600213 # copies log from logs/sol_<BMC_IP>.
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500214
Michael Walsh3ef2e922019-01-23 10:40:16 -0600215 ${ipmi_cmd}= Create IPMI Ext Command String sol deactivate
216 Qprint Issuing ${ipmi_cmd}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500217 ${rc} ${output}= Run and Return RC and Output ${ipmi_cmd}
Rahul Maheshwari4f360842017-06-06 15:05:01 -0500218 Run Keyword If ${rc} > 0 Run Keywords
Rahul Maheshwari7f48a2c2017-06-16 04:00:26 -0500219 ... Run Keyword And Ignore Error Terminate Process sol_proc
220 ... AND Return From Keyword ${output}
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500221
George Keishingaec8b872019-07-08 23:44:08 -0500222 ${output}= OperatingSystem.Get File ${file_path} encoding_errors=ignore
Rahul Maheshwari04a22042017-05-02 01:54:31 -0500223
224 # Logging SOL output for debug purpose.
225 Log ${output}
226
227 [Return] ${output}
228
229
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500230Byte Conversion
231 [Documentation] Byte Conversion method receives IPMI RAW commands as
232 ... argument in string format.
233 ... Sample argument is as follows
234 ... "0x04 0x30 9 0x01 0x00 0x35 0x00 0x00 0x00 0x00 0x00
235 ... 0x00"
236 ... IPMI RAW command format is as follows
237 ... <netfn Byte> <cmd Byte> <Data Bytes..>
238 ... This method converts IPMI command format into
239 ... dbus command format as follows
240 ... <byte:seq-id> <byte:netfn> <byte:lun> <byte:cmd>
241 ... <array:byte:data>
242 ... Sample dbus Host IPMI Received Message argument
243 ... byte:0x00 byte:0x04 byte:0x00 byte:0x30
244 ... array:byte:9,0x01,0x00,0x35,0x00,0x00,0x00,0x00,0x00,0x00
Gunnar Mills38032802016-12-12 13:43:40 -0600245 [Arguments] ${args}
Gunnar Mills59204d22016-12-06 11:05:19 -0600246 ${argLength}= Get Length ${args}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500247 Set Global Variable ${arrayByte} array:byte:
Gunnar Mills59204d22016-12-06 11:05:19 -0600248 @{listargs}= Split String ${args}
249 ${index}= Set Variable ${0}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500250 FOR ${word} IN @{listargs}
251 Run Keyword if ${index} == 0 Set NetFn Byte ${word}
252 Run Keyword if ${index} == 1 Set Cmd Byte ${word}
253 Run Keyword if ${index} > 1 Set Array Byte ${word}
254 ${index}= Set Variable ${index + 1}
255 END
Gunnar Mills59204d22016-12-06 11:05:19 -0600256 ${length}= Get Length ${arrayByte}
257 ${length}= Evaluate ${length} - 1
258 ${arrayByteLocal}= Get Substring ${arrayByte} 0 ${length}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500259 Set Global Variable ${arrayByte} ${arrayByteLocal}
Gunnar Mills59204d22016-12-06 11:05:19 -0600260 ${valueinBytesWithArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
261 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${cmdByte}
262 ${valueinBytesWithArray}= Catenate ${valueinBytesWithArray} ${arrayByte}
263 ${valueinBytesWithoutArray}= Catenate byte:0x00 ${netfnByte} byte:0x00
264 ${valueinBytesWithoutArray}= Catenate ${valueinBytesWithoutArray} ${cmdByte}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600265 # To Check scenario for smaller IPMI raw commands with only 2 arguments
266 # instead of usual 12 arguments.
267 # Sample small IPMI raw command: Run IPMI command 0x06 0x36
268 # If IPMI raw argument length is only 9 then return value in bytes without
269 # array population.
270 # Equivalent dbus-send argument for smaller IPMI raw command:
271 # byte:0x00 byte:0x06 byte:0x00 byte:0x36
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500272 Run Keyword if ${argLength} == 9 Return from Keyword ${valueinBytesWithoutArray}
Gunnar Millsc9ea9362016-12-13 16:21:13 -0600273 [Return] ${valueinBytesWithArray}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500274
275
276Set NetFn Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500277 [Documentation] Set the network function byte.
278 [Arguments] ${word}
279 ${netfnByteLocal}= Catenate byte:${word}
280 Set Global Variable ${netfnByte} ${netfnByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500281
Michael Walsh3ef2e922019-01-23 10:40:16 -0600282
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500283Set Cmd Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500284 [Documentation] Set the command byte.
285 [Arguments] ${word}
286 ${cmdByteLocal}= Catenate byte:${word}
287 Set Global Variable ${cmdByte} ${cmdByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500288
Michael Walsh3ef2e922019-01-23 10:40:16 -0600289
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500290Set Array Byte
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500291 [Documentation] Set the array byte.
292 [Arguments] ${word}
293 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByte} ${word}
294 ${arrayByteLocal}= Catenate SEPARATOR= ${arrayByteLocal} ,
295 Set Global Variable ${arrayByte} ${arrayByteLocal}
Sivas SRRa2dab3c2016-07-25 05:08:18 -0500296
Michael Walsh3ef2e922019-01-23 10:40:16 -0600297
Chris Austenb29d2e82016-06-07 12:25:35 -0500298Copy ipmitool
Joy Onyerikwuf4a807b2018-06-20 08:43:54 -0500299 [Documentation] Copy the ipmitool to the BMC.
300 ${ipmitool_error}= Catenate The ipmitool program could not be found in the tools directory.
301 ... It is not part of the automation code by default. You must manually copy or link the correct openbmc
302 ... version of the tool in to the tools directory in order to run this test suite.
303
304 OperatingSystem.File Should Exist tools/ipmitool msg=${ipmitool_error}
Chris Austenb29d2e82016-06-07 12:25:35 -0500305
306 Import Library SCPLibrary WITH NAME scp
307 scp.Open connection ${OPENBMC_HOST} username=${OPENBMC_USERNAME} password=${OPENBMC_PASSWORD}
308 scp.Put File tools/ipmitool /tmp
309 SSHLibrary.Open Connection ${OPENBMC_HOST}
George Keishingf94de712021-11-10 13:59:44 -0600310 SSHLibrary.Login ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
Chris Austenb29d2e82016-06-07 12:25:35 -0500311 Execute Command chmod +x /tmp/ipmitool
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500312
Michael Walsh3ef2e922019-01-23 10:40:16 -0600313
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500314Initiate Host Boot Via External IPMI
315 [Documentation] Initiate host power on using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500316 [Arguments] ${wait}=${1}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600317
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500318 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600319 # wait Indicates that this keyword should wait
320 # for host running state.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500321
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500322 ${output}= Run External IPMI Standard Command chassis power on
323 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500324
325 Run Keyword If '${wait}' == '${0}' Return From Keyword
326 Wait Until Keyword Succeeds 10 min 10 sec Is Host Running
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500327
Michael Walsh3ef2e922019-01-23 10:40:16 -0600328
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500329Initiate Host PowerOff Via External IPMI
330 [Documentation] Initiate host power off using external IPMI.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500331 [Arguments] ${wait}=${1}
Michael Walsh3ef2e922019-01-23 10:40:16 -0600332
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500333 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600334 # wait Indicates that this keyword should wait
335 # for host off state.
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500336
Sridevi Ramesh0c34f692017-04-25 02:40:32 -0500337 ${output}= Run External IPMI Standard Command chassis power off
338 Should Not Contain ${output} Error
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500339
340 Run Keyword If '${wait}' == '${0}' Return From Keyword
341 Wait Until Keyword Succeeds 3 min 10 sec Is Host Off
342
Michael Walsh3ef2e922019-01-23 10:40:16 -0600343
Rahul Maheshwari460778d2020-02-23 22:37:22 -0600344Is Host Off Via IPMI
345 [Documentation] Verify if the Host is off using IPMI command.
346
347 ${status}= Run External IPMI Standard Command chassis power status
348 Should Contain ${status} off
349
350
Rahul Maheshwari982fee42017-05-03 00:33:15 -0500351Get Host State Via External IPMI
352 [Documentation] Returns host state using external IPMI.
353
354 ${output}= Run External IPMI Standard Command chassis power status
355 Should Not Contain ${output} Error
356 ${output}= Fetch From Right ${output} ${SPACE}
357
358 [Return] ${output}
George Keishingb4d4a4a2018-08-27 13:35:39 -0500359
360
361Set BMC Network From Host
362 [Documentation] Set BMC network from host.
363 [Arguments] ${nw_info}
364
365 # Description of argument(s):
Michael Walsh3ef2e922019-01-23 10:40:16 -0600366 # nw_info A dictionary containing the network
367 # information to apply.
George Keishingb4d4a4a2018-08-27 13:35:39 -0500368
369 Run Inband IPMI Standard Command
370 ... lan set 1 ipaddr ${nw_info['IP Address']}
371
372 Run Inband IPMI Standard Command
373 ... lan set 1 netmask ${nw_info['Subnet Mask']}
374
375 Run Inband IPMI Standard Command
376 ... lan set 1 defgw ipaddr ${nw_info['Default Gateway IP']}
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600377
378
379Verify IPMI Username And Password
380 [Documentation] Verify that user is able to run IPMI command
381 ... with given username and password.
382 [Arguments] ${username} ${password}
383
384 # Description of argument(s):
385 # username The user name (e.g. "root", "robert", etc.).
386 # password The user password (e.g. "0penBmc", "0penBmc1", etc.).
387
Tony Leef9379e82020-01-08 18:20:38 +0800388 ${output}= Wait Until Keyword Succeeds 15 sec 5 sec Run External IPMI Standard Command
Rahul Maheshwaric3d1e962019-03-06 23:53:21 -0600389 ... sel info U=${username} P=${password}
390 Should Contain ${output} SEL Information msg=SEL information not present
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500391
392
393IPMI Create User
394 [Documentation] Create IPMI user with given userid and username.
395 [Arguments] ${userid} ${username}
396
397 # Description of argument(s):
398 # userid The user ID (e.g. "1", "2", etc.).
399 # username The user name (e.g. "root", "robert", etc.).
400
401 ${ipmi_cmd}= Catenate user set name ${userid} ${username}
402 ${resp}= Run IPMI Standard Command ${ipmi_cmd}
403 ${user_info}= Get User Info ${userid}
404 Should Be Equal ${user_info['user_name']} ${username}
405
406
407Set Channel Access
408 [Documentation] Verify that user is able to run IPMI command
409 ... with given username and password.
Tony Lee7c5f4b22019-12-06 17:21:31 +0800410 [Arguments] ${userid} ${options} ${channel_number}=${CHANNEL_NUMBER}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500411
412 # Description of argument(s):
413 # userid The user ID (e.g. "1", "2", etc.).
414 # options Set channel command options (e.g.
415 # "link=on", "ipmi=on", etc.).
416 # channel_number The user's channel number (e.g. "1").
417
418 ${ipmi_cmd}= Catenate SEPARATOR=
Tony Lee7c5f4b22019-12-06 17:21:31 +0800419 ... channel setaccess${SPACE}${channel_number}${SPACE}${userid}
Rahul Maheshwari75e91fe2019-03-29 05:32:28 -0500420 ... ${SPACE}${options}
421 Run IPMI Standard Command ${ipmi_cmd}
Rahul Maheshwari3e61ce62019-06-18 02:09:01 -0500422
423
424Delete All Non Root IPMI User
425 [Documentation] Delete all non-root IPMI user.
426
Michael Walsh34c79af2019-12-09 11:46:48 -0600427 # Get complete list of user info records.
428 ${user_info}= Get User Info ${EMPTY}
429 # Remove header record.
430 ${user_info}= Filter Struct ${user_info} [('user_name', None)] invert=1
431 ${non_empty_user_info}= Filter Struct ${user_info} [('user_name', '')] invert=1
432 ${non_root_user_info}= Filter Struct ${non_empty_user_info} [('user_name', 'root')] invert=1
433
434 FOR ${user_record} IN @{non_root_user_info}
435 Run IPMI Standard Command user set name ${user_record['user_id']} ""
436 Sleep 5s
Rahul Maheshwari460778d2020-02-23 22:37:22 -0600437 END
chithrag0a8c8782022-03-01 12:35:00 +0000438
439
440Create SEL
441 [Documentation] Create a SEL.
442 [Arguments] ${sensor_type} ${sensor_number}
443
444 # Create a SEL.
445 # Example:
446 # a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted
447
448 # Description of argument(s):
449 # ${sensor_type} Type of the sensor used in hexadecimal (can be fan, temp etc.,),
450 # obtained from Sensor Type field in - ipmitool sdr get "sensor_name".
451 # Example: Sensor Type (Threshold) : Fan (0x04), here 0xHH is sensor type.
452
453 # ${sensor_number} Sensor number of the sensor in hexadecimal.
454 # obtained from Sensor ID field in - ipmitool sdr get "sensor_name".
455 # Example: Sensor ID : SENSOR_1 (0xHH), here 0xHH is sensor number.
456
457 ${resp}= Run IPMI Command
458 ... ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][0]} 0x${sensor_type} 0x${sensor_number} ${IPMI_RAW_CMD['SEL_entry']['Create_SEL'][1]}
459
chithragd7e009b2022-03-01 12:20:57 +0000460 Should Not Contain ${resp} 00 00 msg=SEL not created.
461
chithrag0a8c8782022-03-01 12:35:00 +0000462 [Return] ${resp}
463
464
ganesanbd282b562022-05-11 20:30:52 +0530465Fetch One Threshold Sensor From Sensor List
466 [Documentation] Fetch one threshold sensor randomly from Sensor list.
467
468 @{sensor_name_list}= Create List
chithrag0a8c8782022-03-01 12:35:00 +0000469
470 ${resp}= Run IPMI Standard Command sensor
ganesanbd282b562022-05-11 20:30:52 +0530471 @{sensor_list}= Split To Lines ${resp}
chithrag0a8c8782022-03-01 12:35:00 +0000472
ganesanbd282b562022-05-11 20:30:52 +0530473 # Omit the discrete sensor and create an threshold sensor name list
474 FOR ${sensor} IN @{sensor_list}
475 ${discrete_sensor_status}= Run Keyword And Return Status Should Contain ${sensor} discrete
476 Continue For Loop If '${discrete_sensor_status}' == 'True'
477 ${sensor_details}= Split String ${sensor} |
478 ${get_sensor_name}= Get From List ${sensor_details} 0
479 ${sensor_name}= Set Variable ${get_sensor_name.strip()}
480 Append To List ${sensor_name_list} ${sensor_name}
481 END
chithrag0a8c8782022-03-01 12:35:00 +0000482
ganesanbd282b562022-05-11 20:30:52 +0530483 ${random_sensor_name}= Evaluate random.choice(${sensor_name_list}) random
chithrag0a8c8782022-03-01 12:35:00 +0000484
ganesanbd282b562022-05-11 20:30:52 +0530485 [Return] ${random_sensor_name}
chithrag0a8c8782022-03-01 12:35:00 +0000486
487Fetch Sensor Details From SDR
488 [Documentation] Identify the sensors from sdr get and fetch sensor details required.
489 [Arguments] ${sensor_name} ${setting}
490
491 # Description of argument(s):
492 # ${sensor_number} Sensor number of the sensor in hexadecimal.
493 # obtained sensor name from - 'ipmitool sensor' command.
494 # Example: a | 02/14/2020 | 01:16:58 | Sensor_type #0x17 | | Asserted
495 # here, a is the sensor name.
496
497 # ${setting} Field to fetch data. Example : Sensor ID, Sensor Type (Threshold), etc,.
498
499 ${resp}= Run IPMI Standard Command sdr get "${sensor_name}"
500
501 ${setting_line}= Get Lines Containing String ${resp} ${setting}
502 ... case-insensitive
503 ${setting_status}= Fetch From Right ${setting_line} :${SPACE}
504
505 [Return] ${setting_status}
506
507
508Get Data And Byte From SDR Sensor
509 [Documentation] Fetch the Field Data and hexadecimal values from given details.
510 [Arguments] ${sensor_detail}
511
512 # Description of argument(s):
513 # ${sensor_detail} Requested field and the value from the sdr get ipmi command.
514 # Example : if Sensor ID is the requesting setting, then,
515 # ${sensor_detail} will be "Sensor ID : SENSOR_1 (0xHH)"
516
517 ${sensor_detail}= Split String ${sensor_detail} (0x
518 ${field_data}= Set Variable ${sensor_detail[0]}
519 ${field_data}= Remove Whitespace ${field_data}
520 ${sensor_hex}= Replace String ${sensor_detail[1]} ) ${EMPTY}
521 ${sensor_hex}= Zfill Data ${sensor_hex} 2
522
523 [Return] ${field_data} ${sensor_hex}
524
525
526Get Current Date from BMC
527 [Documentation] Runs the date command from BMC and returns current date and time
528
529 # Get Current Date from BMC
530 ${date} ${stderr} ${rc}= BMC Execute Command date
531
532 # 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
533 ${date}= Split String ${date}
534 Remove From List ${date} 0
535 Remove From List ${date} -2
536 ${date}= Evaluate " ".join(${date})
537
538 # Convert the date format to %m/%d/%Y %H:%M:%S
539 ${date}= Convert Date ${date} date_format=%b %d %H:%M:%S %Y result_format=%m/%d/%Y %H:%M:%S exclude_millis=True
540
541 [Return] ${date}
chithragd7e009b2022-03-01 12:20:57 +0000542
543
544Get SEL Info Via IPMI
545 [Documentation] Get the SEL Info via IPMI raw command
546
547 # Get SEL Info response consist of 14 bytes of hexadecimal data.
548
549 # Byte 1 - SEL Version,
550 # Byte 2 & 3 - Entry bytes - LSB MSB,
551 # Byte 4 & 5 - Free Space in bytes, LS Byte first.
552 # Byte 6 - 9 - Most recent addition timestamp,
553 # Byte 10-13 - Most recent erase timestamp,
554 # Byte 14 - Operation Support
555
556 # Example: ${resp} will be "51 XX XX XX XX ff ff ff ff ff ff ff ff XX"
557
558 ${resp}= Run IPMI Standard Command
559 ... raw ${IPMI_RAW_CMD['SEL_entry']['SEL_info'][0]}
560 ${resp}= Split String ${resp}
561
562 [Return] ${resp}