blob: 25d4dc8c4624536ca1a3251b9a221669cfbbe1d5 [file] [log] [blame]
Sridevi Ramesh0047de82019-02-01 06:33:08 -06001*** Settings ***
George Keishingb10eaca2019-02-24 05:07:30 -06002Documentation BMC and host redfish utility keywords.
Sridevi Ramesh0047de82019-02-01 06:33:08 -06003
George Keishing2db7bca2019-02-14 13:03:08 -06004Resource resource.robot
Sridevi Ramesh0047de82019-02-01 06:33:08 -06005Resource bmc_redfish_resource.robot
6
7
8*** Keywords ***
9
10Redfish Power Operation
George Keishingb10eaca2019-02-24 05:07:30 -060011 [Documentation] Do Redfish host power operation.
Sridevi Ramesh0047de82019-02-01 06:33:08 -060012 [Arguments] ${reset_type}
Sushil Singhb910d892021-11-17 05:34:29 -060013
Sridevi Ramesh0047de82019-02-01 06:33:08 -060014 # Description of arguments:
15 # reset_type Type of power operation.
16 # (e.g. On/ForceOff/GracefulRestart/GracefulShutdown)
17
18 # Example:
19 # "Actions": {
20 # "#ComputerSystem.Reset": {
George Keishingb78e76d2024-10-10 14:33:34 +053021 # "@Redfish.ActionInfo": "/redfish/v1/Systems/${SYSTEM_ID}/ResetActionInfo",
22 # "target": "/redfish/v1/Systems/${SYSTEM_ID}/Actions/ComputerSystem.Reset"
23 # }
24
25 # Parameters allowable values /redfish/v1/Systems/${SYSTEM_ID}/ResetActionInfo
26
27 # "@odata.id": "/redfish/v1/Systems/${SYSTEM_ID}/ResetActionInfo",
28 # "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
29 # "Id": "ResetActionInfo",
30 # "Name": "Reset Action Info",
31 # "Parameters": [
32 # {
33 # "AllowableValues": [
34 # "ForceOff",
35 # "PowerCycle",
36 # "Nmi",
37 # "GracefulShutdown",
38 # "On",
39 # "ForceOn",
40 # "GracefulRestart",
41 # "ForceRestart"
42 # ],
43 # "DataType": "String",
44 # "Name": "ResetType",
45 # "Required": true
46 # }
47 # ]
Sridevi Ramesh0047de82019-02-01 06:33:08 -060048
George Keishing43909f32024-08-20 22:08:02 +053049 ${target}= Wait Until Keyword Succeeds 1 min 20 sec
50 ... redfish_utils.Get Target Actions /redfish/v1/Systems/${SYSTEM_ID}/ ComputerSystem.Reset
Sridevi Ramesh0047de82019-02-01 06:33:08 -060051 ${payload}= Create Dictionary ResetType=${reset_type}
Michael Walsh213feb32019-03-08 14:44:31 -060052 ${resp}= Redfish.Post ${target} body=&{payload}
George Keishing8a86c692024-03-29 09:52:25 +053053 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sridevi Ramesh0047de82019-02-01 06:33:08 -060054
55
George Keishingb10eaca2019-02-24 05:07:30 -060056Redfish BMC Reset Operation
57 [Documentation] Do Redfish BMC reset operation.
Sushil Singhb910d892021-11-17 05:34:29 -060058 [Arguments] ${reset_type}=GracefulRestart
Sridevi Ramesh0047de82019-02-01 06:33:08 -060059
George Keishingb10eaca2019-02-24 05:07:30 -060060 # Example:
61 # "Actions": {
George Keishingb78e76d2024-10-10 14:33:34 +053062 # "#Manager.Reset": {
63 # "@Redfish.ActionInfo": "/redfish/v1/Managers/${MANAGER_ID}/ResetActionInfo",
64 # "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.Reset"
65 # },
66 # "#Manager.ResetToDefaults": {
67 # "ResetType@Redfish.AllowableValues": [
68 # "ResetAll"
69 # ],
70 # "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.ResetToDefaults"
71 # }
72 # },
73
74 # Parameters allowable values /redfish/v1/Managers/${MANAGER_ID}/ResetActionInfo
75
76 # "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/ResetActionInfo",
77 # "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
78 # "Id": "ResetActionInfo",
79 # "Name": "Reset Action Info",
80 # "Parameters": [
81 # {
82 # "AllowableValues": [
83 # "GracefulRestart",
84 # "ForceRestart"
85 # ],
86 # "DataType": "String",
87 # "Name": "ResetType",
88 # "Required": true
89 # }
90 # ]
George Keishingb10eaca2019-02-24 05:07:30 -060091
George Keishing43909f32024-08-20 22:08:02 +053092 ${target}= Wait Until Keyword Succeeds 1 min 20 sec
93 ... redfish_utils.Get Target Actions /redfish/v1/Managers/${MANAGER_ID}/ Manager.Reset
Sushil Singhb910d892021-11-17 05:34:29 -060094 ${payload}= Create Dictionary ResetType=${reset_type}
George Keishing07fb41f2020-06-16 08:09:19 -050095 Redfish.Post ${target} body=&{payload}
George Keishingcaa718b2019-03-10 00:08:33 -060096
97
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060098Reset BIOS Via Redfish
99 [Documentation] Do BIOS reset through Redfish.
100
Yi Huc32434a2024-01-11 17:33:10 -0800101 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/${SYSTEM_ID}/Bios/ Bios.ResetBios
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -0600102 Redfish.Post ${target} valid_status_codes=[${HTTP_OK}]
103
104
Yi Hu02d32762024-03-07 14:34:34 -0800105Set Redfish Delete Session Flag
106 [Documentation] Disable or enable delete redfish while performing the power operation keyword.
107 [Arguments] ${set_flag}
108
109 # Description of argument(s):
110 # set_flag Set user specified enable(1) or disable(0).
111
112 Set Suite Variable ${REDFISH_DELETE_SESSIONS} ${set_flag}
113
114
Sushil Singh87e984c2020-10-20 01:43:47 -0500115Redfish Delete Session
116 [Documentation] Redfish delete session.
117 [Arguments] ${session_info}
118
119 # Description of argument(s):
120 # session_info Session information are stored in dictionary.
121
122 # ${session_info} = {
123 # 'SessionIDs': 'XXXXXXXXX',
124 # 'ClientID': 'XXXXXX',
125 # 'SessionToken': 'XXXXXXXXX',
126 # 'SessionResp': session response from redfish login
127 # }
128
129 # SessionIDs : Session IDs
130 # ClientID : Client ID
131 # SessionToken : Session token
132 # SessionResp : Response of creating an redfish login session
133
134 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}
135
136
137Redfish Delete List Of Session
138 [Documentation] Redfish delete session from list of session records, individual session information
139 ... are stored in dictionary.
140 [Arguments] ${session_info_list}
141
142 # Description of argument(s):
143 # session_info_list List contains individual session record are stored in dictionary.
144
145 # ${session_info_list} = [{
146 # 'SessionIDs': 'XXXXXXXXX',
147 # 'ClientID': 'XXXXXX',
148 # 'SessionToken': 'XXXXXXXXX',
149 # 'SessionResp': session response from redfish login
150 # }]
151
152 # SessionIDs : Session IDs
153 # ClientID : Client ID
154 # SessionToken : Session token
155 # SessionResp : Response of creating an redfish login session
156
157 FOR ${session_record} IN @{session_info_list}
158 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_record["SessionIDs"]}
159 END
160
161
George Keishingcaa718b2019-03-10 00:08:33 -0600162Delete All Redfish Sessions
163 [Documentation] Delete all active redfish sessions.
164
Sagar Ananded737652023-01-10 02:00:31 -0600165 ${saved_session_info}= Redfish_Utils.Get Redfish Session Info
George Keishingcaa718b2019-03-10 00:08:33 -0600166
167 ${resp_list}= Redfish_Utils.Get Member List
168 ... /redfish/v1/SessionService/Sessions
169
170 # Remove the current login session from the list.
171 Remove Values From List ${resp_list} ${saved_session_info["location"]}
172
George Keishing3612f3a2022-04-21 11:21:53 -0500173 # Remove session with client_id populated from the list.
174 ${client_id_list}= Get Session With Client Id ${resp_list}
175 Log To Console Client sessions skip list: ${client_id_list}
176 FOR ${client_session} IN @{client_id_list}
177 Remove Values From List ${resp_list} ${client_session}
178 END
179
Marissa Garza20ccfc72020-06-19 12:51:10 -0500180 FOR ${session} IN @{resp_list}
George Keishing74c1c852020-12-09 09:03:55 -0600181 Run Keyword And Ignore Error Redfish.Delete ${session}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500182 END
Michael Walshcf163322019-05-22 16:56:17 -0500183
Sushil Singh87e984c2020-10-20 01:43:47 -0500184
George Keishing3612f3a2022-04-21 11:21:53 -0500185Get Session With Client Id
George Keishingf9babff2023-08-16 18:40:22 +0530186 [Documentation] Iterate through the active sessions and return sessions
187 ... populated with Context.
George Keishing3612f3a2022-04-21 11:21:53 -0500188 [Arguments] ${session_list}
189
190 # Description of argument(s):
191 # session_list Active session list from SessionService.
192
George Keishingf9babff2023-08-16 18:40:22 +0530193 # "@odata.type": "#Session.v1_5_0.Session",
194 # "ClientOriginIPAddress": "xx.xx.xx.xx",
195 # "Context": "MYID-01"
George Keishing3612f3a2022-04-21 11:21:53 -0500196
197 ${client_id_sessions}= Create List
198 FOR ${session} IN @{session_list}
199 ${resp}= Redfish.Get ${session} valid_status_codes=[200,404]
George Keishingf9babff2023-08-16 18:40:22 +0530200 # This prevents dictionary KeyError exception when the Context
201 # attribute is not populated in generic session response.
202 ${context_var}= Get Variable Value ${resp.dict["Context"]} ${EMPTY}
George Keishingd2bcbf72023-09-15 22:44:02 +0530203 # Handle backward compatibility for OEM.
204 ${oem_var}= Get Variable Value ${resp.dict["Oem"]["OpenBMC"]["ClientID"]} ${EMPTY}
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -0500205 IF '${context_var}' != '${EMPTY}'
206 Append To List ${client_id_sessions} ${session}
207 END
208 IF '${oem_var}' != '${EMPTY}'
209 Append To List ${client_id_sessions} ${session}
210 END
George Keishing3612f3a2022-04-21 11:21:53 -0500211 END
212
George Keishing409df052024-01-17 22:36:14 +0530213 RETURN ${client_id_sessions}
George Keishing3612f3a2022-04-21 11:21:53 -0500214
215
Michael Walshcf163322019-05-22 16:56:17 -0500216Get Valid FRUs
217 [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type.
218 [Arguments] ${fru_type}
219
220 # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
221
222 # Description of argument(s):
223 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
224
225 ${fru_records}= Redfish_Utils.Enumerate Request
Yi Huc32434a2024-01-11 17:33:10 -0800226 ... /redfish/v1/Systems/${SYSTEM_ID}/${fru_type} return_json=0
Michael Walshe256a4f2019-05-29 10:49:06 -0500227 ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')]
Michael Walshcf163322019-05-22 16:56:17 -0500228
George Keishing409df052024-01-17 22:36:14 +0530229 RETURN ${fru_records}
Michael Walshcf163322019-05-22 16:56:17 -0500230
231
232Get Num Valid FRUs
233 [Documentation] Return the number of valid FRU records for the given fru_type.
234 [Arguments] ${fru_type}
235
236 # Description of argument(s):
237 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
238
239 ${fru_records}= Get Valid FRUs ${fru_type}
240 ${num_valid_frus}= Get length ${fru_records}
241
George Keishing409df052024-01-17 22:36:14 +0530242 RETURN ${num_valid_frus}
Marissa Garzad76b1422019-09-13 16:31:54 -0500243
244
245Verify Valid Records
246 [Documentation] Verify all records retrieved with the given arguments are valid.
247 [Arguments] ${record_type} ${redfish_uri} ${reading_type}
248
249 # Description of Argument(s):
250 # record_type The sensor record type (e.g. "PowerSupplies")
251 # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power)
252 # reading_type The power watt readings (e.g. "PowerInputWatts")
253
254 # A valid record will have "State" key "Enabled" and "Health" key "OK".
255 ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type}
256
257 Rprint Vars records
258
259 # Example output:
260 # records:
261 # [0]:
262 # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0
263 # [@odata.type]: #Power.v1_0_0.PowerControl
264 # [MemberId]: 0
265 # [Name]: Chassis Power Control
266 # [PowerConsumedWatts]: 264.0
267 # [PowerLimit]:
268 # [LimitInWatts]: None
269 # [PowerMetrics]:
270 # [AverageConsumedWatts]: 325
271 # [IntervalInMin]: 3
272 # [MaxConsumedWatts]: 538
273 # [Status]:
274 # [Health]: OK
275 # [State]: Enabled
276
277 ${invalid_records}= Filter Struct ${records}
278 ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1
279 Valid Length invalid_records max_length=0
Marissa Garzafdee1b02019-09-20 14:52:12 -0500280
George Keishing409df052024-01-17 22:36:14 +0530281 RETURN ${records}
Vijayff2c0bc2020-02-03 00:05:45 -0600282
283
284Redfish Create User
285 [Documentation] Redfish create user.
286 [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False}
287
288 # Description of argument(s):
289 # user_name The user name to be created.
290 # password The password to be assigned.
291 # role_id The role ID of the user to be created.
292 # (e.g. "Administrator", "Operator", etc.).
293 # enabled Indicates whether the username being created.
294 # should be enabled (${True}, ${False}).
295 # force Delete user account and re-create if force is True.
296
297 ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name}
298 # Ex: ${curr_role} = ('PASS', 'Administrator')
299
300 ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS
301
302 # Delete user account when force is True.
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -0500303 IF ${force} == ${True}
304 Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name}
305 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
306 END
Vijayff2c0bc2020-02-03 00:05:45 -0600307
308 # Create specified user when force is True or User does not exist.
309 ${payload}= Create Dictionary
310 ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled}
311
Sridevi Ramesh9f9edcc2025-05-16 01:27:01 -0500312 IF ${force} == ${True} or ${user_exists} == ${False}
313 Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
314 ... valid_status_codes=[${HTTP_CREATED}]
315 END
Vijayff2c0bc2020-02-03 00:05:45 -0600316
317Get User Role
318 [Documentation] Get User Role.
319 [Arguments] ${user_name}
320
321 # Description of argument(s):
322 # user_name User name to get it's role.
323
324 ${role_config}= Redfish_Utils.Get Attribute
325 ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId
326
George Keishing409df052024-01-17 22:36:14 +0530327 RETURN ${role_config}
Vijayff2c0bc2020-02-03 00:05:45 -0600328
329
330Create Users With Different Roles
331 [Documentation] Create users with different roles.
332 [Arguments] ${users} ${force}=${False}
333
334 # Description of argument(s):
George Keishing9bfdf8a2024-04-19 11:09:07 +0530335 # users Dictionary of roles and user credentials to be created.
Vijayff2c0bc2020-02-03 00:05:45 -0600336 # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'}
337 # force Delete given user account if already exists when force is True.
338
339 FOR ${role} IN @{users}
340 Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force}
341 END
342
Vijay39373152020-02-14 08:08:20 -0600343
344Delete BMC Users Via Redfish
345 [Documentation] Delete BMC users via redfish.
346 [Arguments] ${users}
347
348 # Description of argument(s):
349 # users Dictionary of roles and user credentials to be deleted.
350
351 FOR ${role} IN @{users}
352 Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]}
353 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
354 END
355
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600356
357Expire And Update New Password Via Redfish
358 [Documentation] Expire and change password and verify using password.
359 [Arguments] ${username} ${password} ${new_password}
360
361 # Description of argument(s):
362 # username The username to be used to login to the BMC.
363 # password The password to be used to login to the BMC.
364 # new_password The new password to be used to update password.
365
366 # Expire admin password using ssh.
Sushil Singh39848ba2022-08-10 05:49:32 -0500367 Open Connection And Log In ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600368 ${output} ${stderr} ${rc}= BMC Execute Command passwd --expire ${username}
Brian Ma45aa8812022-02-24 14:55:28 +0800369 Should Contain Any ${output} password expiry information changed
370 ... password changed
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600371
372 # Verify user password expired using Redfish
373 Verify User Password Expired Using Redfish ${username} ${password}
374
375 # Change user password.
Brian Ma45aa8812022-02-24 14:55:28 +0800376 Redfish.Patch /redfish/v1/AccountService/Accounts/${username}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600377 ... body={'Password': '${new_password}'}
378 Redfish.Logout
379
380
381Verify User Password Expired Using Redfish
382 [Documentation] Checking whether user password expired or not using redfish.
Sushil Singh473cf7d2023-03-09 04:24:07 -0600383 [Arguments] ${username} ${password} ${expected_result}=${True}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600384
385 # Description of argument(s):
386 # username The username to be used to login to the BMC.
387 # password The password to be used to login to the BMC.
388
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600389 Redfish.Login ${username} ${password}
390 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/${username}
391 Should Be Equal ${resp.dict["PasswordChangeRequired"]} ${expected_result}
392
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600393
394Is BMC LastResetTime Changed
395 [Documentation] Return fail if BMC last reset time is not changed.
396 [Arguments] ${reset_time}
397
398 # Description of argument(s):
399 # reset_time Last BMC reset time.
400
401 ${last_reset_time}= Get BMC Last Reset Time
402 Should Not Be Equal ${last_reset_time} ${reset_time}
403
404
405Redfish BMC Reboot
406 [Documentation] Use Redfish API reboot BMC and wait for BMC ready.
407
408 # Get BMC last reset time for compare
409 ${last_reset_time}= Get BMC Last Reset Time
410
411 # Reboot BMC by Redfish API
412 Redfish BMC Reset Operation
413
414 # Wait for BMC real reboot and Redfish API ready
George Keishing15914c02025-04-15 13:23:42 +0530415 Wait Until Keyword Succeeds 3 min 10 sec
416 ... Is BMC LastResetTime Changed ${last_reset_time}
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600417
418
419Get BMC Last Reset Time
420 [Documentation] Return BMC LastResetTime.
421
George Keishing15914c02025-04-15 13:23:42 +0530422 ${last_reset_time}= Redfish.Get Attribute
423 ... /redfish/v1/Managers/${MANAGER_ID} LastResetTime
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600424
George Keishing409df052024-01-17 22:36:14 +0530425 RETURN ${last_reset_time}
George Keishing15914c02025-04-15 13:23:42 +0530426
427
428Get BMC Active Session Count
429 [Documentation] Return active session count from BMC.
430
431 ${session_count}= Redfish.Get Attribute
432 ... /redfish/v1/SessionService/Sessions Members@odata.count
433
434 Log To Console Redfish active session count: ${session_count}
435 RETURN ${session_count}