blob: fbac104cd87539b6e5fe3c8364f56d9fc033924f [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": {
21 # "ResetType@Redfish.AllowableValues": [
22 # "On",
23 # "ForceOff",
George Keishingeeb526c2020-03-03 07:39:44 -060024 # "ForceOn",
25 # "ForceRestart",
Sridevi Ramesh0047de82019-02-01 06:33:08 -060026 # "GracefulRestart",
27 # "GracefulShutdown"
George Keishingeeb526c2020-03-03 07:39:44 -060028 # "PowerCycle",
29 # "Nmi"
Sridevi Ramesh0047de82019-02-01 06:33:08 -060030 # ],
George Keishing2deec3c2019-02-26 09:20:10 -060031 # "target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"
32 # }
33 # }
Sridevi Ramesh0047de82019-02-01 06:33:08 -060034
Yi Huc32434a2024-01-11 17:33:10 -080035 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/${SYSTEM_ID}/ ComputerSystem.Reset
Sridevi Ramesh0047de82019-02-01 06:33:08 -060036 ${payload}= Create Dictionary ResetType=${reset_type}
Michael Walsh213feb32019-03-08 14:44:31 -060037 ${resp}= Redfish.Post ${target} body=&{payload}
George Keishing8a86c692024-03-29 09:52:25 +053038 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sridevi Ramesh0047de82019-02-01 06:33:08 -060039
40
George Keishingb10eaca2019-02-24 05:07:30 -060041Redfish BMC Reset Operation
42 [Documentation] Do Redfish BMC reset operation.
Sushil Singhb910d892021-11-17 05:34:29 -060043 [Arguments] ${reset_type}=GracefulRestart
Sridevi Ramesh0047de82019-02-01 06:33:08 -060044
George Keishingb10eaca2019-02-24 05:07:30 -060045 # Example:
46 # "Actions": {
47 # "#Manager.Reset": {
48 # "ResetType@Redfish.AllowableValues": [
Sushil Singhb910d892021-11-17 05:34:29 -060049 # "GracefulRestart",
50 # "ForceRestart"
George Keishingb10eaca2019-02-24 05:07:30 -060051 # ],
ganesanb4d430282023-04-27 14:33:23 +000052 # "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.Reset"
George Keishingb10eaca2019-02-24 05:07:30 -060053 # }
54
ganesanb4d430282023-04-27 14:33:23 +000055 ${target}= redfish_utils.Get Target Actions /redfish/v1/Managers/${MANAGER_ID}/ Manager.Reset
Sushil Singhb910d892021-11-17 05:34:29 -060056 ${payload}= Create Dictionary ResetType=${reset_type}
George Keishing07fb41f2020-06-16 08:09:19 -050057 Redfish.Post ${target} body=&{payload}
George Keishingcaa718b2019-03-10 00:08:33 -060058
59
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060060Reset BIOS Via Redfish
61 [Documentation] Do BIOS reset through Redfish.
62
Yi Huc32434a2024-01-11 17:33:10 -080063 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/${SYSTEM_ID}/Bios/ Bios.ResetBios
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060064 Redfish.Post ${target} valid_status_codes=[${HTTP_OK}]
65
66
Yi Hu02d32762024-03-07 14:34:34 -080067Set Redfish Delete Session Flag
68 [Documentation] Disable or enable delete redfish while performing the power operation keyword.
69 [Arguments] ${set_flag}
70
71 # Description of argument(s):
72 # set_flag Set user specified enable(1) or disable(0).
73
74 Set Suite Variable ${REDFISH_DELETE_SESSIONS} ${set_flag}
75
76
Sushil Singh87e984c2020-10-20 01:43:47 -050077Redfish Delete Session
78 [Documentation] Redfish delete session.
79 [Arguments] ${session_info}
80
81 # Description of argument(s):
82 # session_info Session information are stored in dictionary.
83
84 # ${session_info} = {
85 # 'SessionIDs': 'XXXXXXXXX',
86 # 'ClientID': 'XXXXXX',
87 # 'SessionToken': 'XXXXXXXXX',
88 # 'SessionResp': session response from redfish login
89 # }
90
91 # SessionIDs : Session IDs
92 # ClientID : Client ID
93 # SessionToken : Session token
94 # SessionResp : Response of creating an redfish login session
95
96 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}
97
98
99Redfish Delete List Of Session
100 [Documentation] Redfish delete session from list of session records, individual session information
101 ... are stored in dictionary.
102 [Arguments] ${session_info_list}
103
104 # Description of argument(s):
105 # session_info_list List contains individual session record are stored in dictionary.
106
107 # ${session_info_list} = [{
108 # 'SessionIDs': 'XXXXXXXXX',
109 # 'ClientID': 'XXXXXX',
110 # 'SessionToken': 'XXXXXXXXX',
111 # 'SessionResp': session response from redfish login
112 # }]
113
114 # SessionIDs : Session IDs
115 # ClientID : Client ID
116 # SessionToken : Session token
117 # SessionResp : Response of creating an redfish login session
118
119 FOR ${session_record} IN @{session_info_list}
120 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_record["SessionIDs"]}
121 END
122
123
George Keishingcaa718b2019-03-10 00:08:33 -0600124Delete All Redfish Sessions
125 [Documentation] Delete all active redfish sessions.
126
Sagar Ananded737652023-01-10 02:00:31 -0600127 ${saved_session_info}= Redfish_Utils.Get Redfish Session Info
George Keishingcaa718b2019-03-10 00:08:33 -0600128
129 ${resp_list}= Redfish_Utils.Get Member List
130 ... /redfish/v1/SessionService/Sessions
131
132 # Remove the current login session from the list.
133 Remove Values From List ${resp_list} ${saved_session_info["location"]}
134
George Keishing3612f3a2022-04-21 11:21:53 -0500135 # Remove session with client_id populated from the list.
136 ${client_id_list}= Get Session With Client Id ${resp_list}
137 Log To Console Client sessions skip list: ${client_id_list}
138 FOR ${client_session} IN @{client_id_list}
139 Remove Values From List ${resp_list} ${client_session}
140 END
141
Marissa Garza20ccfc72020-06-19 12:51:10 -0500142 FOR ${session} IN @{resp_list}
George Keishing74c1c852020-12-09 09:03:55 -0600143 Run Keyword And Ignore Error Redfish.Delete ${session}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500144 END
Michael Walshcf163322019-05-22 16:56:17 -0500145
Sushil Singh87e984c2020-10-20 01:43:47 -0500146
George Keishing3612f3a2022-04-21 11:21:53 -0500147Get Session With Client Id
George Keishingf9babff2023-08-16 18:40:22 +0530148 [Documentation] Iterate through the active sessions and return sessions
149 ... populated with Context.
George Keishing3612f3a2022-04-21 11:21:53 -0500150 [Arguments] ${session_list}
151
152 # Description of argument(s):
153 # session_list Active session list from SessionService.
154
George Keishingf9babff2023-08-16 18:40:22 +0530155 # "@odata.type": "#Session.v1_5_0.Session",
156 # "ClientOriginIPAddress": "xx.xx.xx.xx",
157 # "Context": "MYID-01"
George Keishing3612f3a2022-04-21 11:21:53 -0500158
159 ${client_id_sessions}= Create List
160 FOR ${session} IN @{session_list}
161 ${resp}= Redfish.Get ${session} valid_status_codes=[200,404]
George Keishingf9babff2023-08-16 18:40:22 +0530162 # This prevents dictionary KeyError exception when the Context
163 # attribute is not populated in generic session response.
164 ${context_var}= Get Variable Value ${resp.dict["Context"]} ${EMPTY}
George Keishingd2bcbf72023-09-15 22:44:02 +0530165 # Handle backward compatibility for OEM.
166 ${oem_var}= Get Variable Value ${resp.dict["Oem"]["OpenBMC"]["ClientID"]} ${EMPTY}
George Keishingf9babff2023-08-16 18:40:22 +0530167 Run Keyword If '${context_var}' != '${EMPTY}'
George Keishing3612f3a2022-04-21 11:21:53 -0500168 ... Append To List ${client_id_sessions} ${session}
George Keishingd2bcbf72023-09-15 22:44:02 +0530169 Run Keyword If '${oem_var}' != '${EMPTY}'
170 ... Append To List ${client_id_sessions} ${session}
George Keishing3612f3a2022-04-21 11:21:53 -0500171 END
172
173 [Return] ${client_id_sessions}
174
175
Michael Walshcf163322019-05-22 16:56:17 -0500176Get Valid FRUs
177 [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type.
178 [Arguments] ${fru_type}
179
180 # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
181
182 # Description of argument(s):
183 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
184
185 ${fru_records}= Redfish_Utils.Enumerate Request
Yi Huc32434a2024-01-11 17:33:10 -0800186 ... /redfish/v1/Systems/${SYSTEM_ID}/${fru_type} return_json=0
Michael Walshe256a4f2019-05-29 10:49:06 -0500187 ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')]
Michael Walshcf163322019-05-22 16:56:17 -0500188
189 [Return] ${fru_records}
190
191
192Get Num Valid FRUs
193 [Documentation] Return the number of valid FRU records for the given fru_type.
194 [Arguments] ${fru_type}
195
196 # Description of argument(s):
197 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
198
199 ${fru_records}= Get Valid FRUs ${fru_type}
200 ${num_valid_frus}= Get length ${fru_records}
201
202 [Return] ${num_valid_frus}
Marissa Garzad76b1422019-09-13 16:31:54 -0500203
204
205Verify Valid Records
206 [Documentation] Verify all records retrieved with the given arguments are valid.
207 [Arguments] ${record_type} ${redfish_uri} ${reading_type}
208
209 # Description of Argument(s):
210 # record_type The sensor record type (e.g. "PowerSupplies")
211 # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power)
212 # reading_type The power watt readings (e.g. "PowerInputWatts")
213
214 # A valid record will have "State" key "Enabled" and "Health" key "OK".
215 ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type}
216
217 Rprint Vars records
218
219 # Example output:
220 # records:
221 # [0]:
222 # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0
223 # [@odata.type]: #Power.v1_0_0.PowerControl
224 # [MemberId]: 0
225 # [Name]: Chassis Power Control
226 # [PowerConsumedWatts]: 264.0
227 # [PowerLimit]:
228 # [LimitInWatts]: None
229 # [PowerMetrics]:
230 # [AverageConsumedWatts]: 325
231 # [IntervalInMin]: 3
232 # [MaxConsumedWatts]: 538
233 # [Status]:
234 # [Health]: OK
235 # [State]: Enabled
236
237 ${invalid_records}= Filter Struct ${records}
238 ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1
239 Valid Length invalid_records max_length=0
Marissa Garzafdee1b02019-09-20 14:52:12 -0500240
241 [Return] ${records}
Vijayff2c0bc2020-02-03 00:05:45 -0600242
243
244Redfish Create User
245 [Documentation] Redfish create user.
246 [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False}
247
248 # Description of argument(s):
249 # user_name The user name to be created.
250 # password The password to be assigned.
251 # role_id The role ID of the user to be created.
252 # (e.g. "Administrator", "Operator", etc.).
253 # enabled Indicates whether the username being created.
254 # should be enabled (${True}, ${False}).
255 # force Delete user account and re-create if force is True.
256
257 ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name}
258 # Ex: ${curr_role} = ('PASS', 'Administrator')
259
260 ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS
261
262 # Delete user account when force is True.
263 Run Keyword If ${force} == ${True} Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name}
264 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
265
266 # Create specified user when force is True or User does not exist.
267 ${payload}= Create Dictionary
268 ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled}
269
270 Run Keyword If ${force} == ${True} or ${user_exists} == ${False}
271 ... Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
272 ... valid_status_codes=[${HTTP_CREATED}]
273
274
275Get User Role
276 [Documentation] Get User Role.
277 [Arguments] ${user_name}
278
279 # Description of argument(s):
280 # user_name User name to get it's role.
281
282 ${role_config}= Redfish_Utils.Get Attribute
283 ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId
284
285 [Return] ${role_config}
286
287
288Create Users With Different Roles
289 [Documentation] Create users with different roles.
290 [Arguments] ${users} ${force}=${False}
291
292 # Description of argument(s):
George Keishing9bfdf8a2024-04-19 11:09:07 +0530293 # users Dictionary of roles and user credentials to be created.
Vijayff2c0bc2020-02-03 00:05:45 -0600294 # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'}
295 # force Delete given user account if already exists when force is True.
296
297 FOR ${role} IN @{users}
298 Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force}
299 END
300
Vijay39373152020-02-14 08:08:20 -0600301
302Delete BMC Users Via Redfish
303 [Documentation] Delete BMC users via redfish.
304 [Arguments] ${users}
305
306 # Description of argument(s):
307 # users Dictionary of roles and user credentials to be deleted.
308
309 FOR ${role} IN @{users}
310 Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]}
311 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
312 END
313
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600314
315Expire And Update New Password Via Redfish
316 [Documentation] Expire and change password and verify using password.
317 [Arguments] ${username} ${password} ${new_password}
318
319 # Description of argument(s):
320 # username The username to be used to login to the BMC.
321 # password The password to be used to login to the BMC.
322 # new_password The new password to be used to update password.
323
324 # Expire admin password using ssh.
Sushil Singh39848ba2022-08-10 05:49:32 -0500325 Open Connection And Log In ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600326 ${output} ${stderr} ${rc}= BMC Execute Command passwd --expire ${username}
Brian Ma45aa8812022-02-24 14:55:28 +0800327 Should Contain Any ${output} password expiry information changed
328 ... password changed
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600329
330 # Verify user password expired using Redfish
331 Verify User Password Expired Using Redfish ${username} ${password}
332
333 # Change user password.
Brian Ma45aa8812022-02-24 14:55:28 +0800334 Redfish.Patch /redfish/v1/AccountService/Accounts/${username}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600335 ... body={'Password': '${new_password}'}
336 Redfish.Logout
337
338
339Verify User Password Expired Using Redfish
340 [Documentation] Checking whether user password expired or not using redfish.
Sushil Singh473cf7d2023-03-09 04:24:07 -0600341 [Arguments] ${username} ${password} ${expected_result}=${True}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600342
343 # Description of argument(s):
344 # username The username to be used to login to the BMC.
345 # password The password to be used to login to the BMC.
346
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600347 Redfish.Login ${username} ${password}
348 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/${username}
349 Should Be Equal ${resp.dict["PasswordChangeRequired"]} ${expected_result}
350
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600351
352Is BMC LastResetTime Changed
353 [Documentation] Return fail if BMC last reset time is not changed.
354 [Arguments] ${reset_time}
355
356 # Description of argument(s):
357 # reset_time Last BMC reset time.
358
359 ${last_reset_time}= Get BMC Last Reset Time
360 Should Not Be Equal ${last_reset_time} ${reset_time}
361
362
363Redfish BMC Reboot
364 [Documentation] Use Redfish API reboot BMC and wait for BMC ready.
365
366 # Get BMC last reset time for compare
367 ${last_reset_time}= Get BMC Last Reset Time
368
369 # Reboot BMC by Redfish API
370 Redfish BMC Reset Operation
371
372 # Wait for BMC real reboot and Redfish API ready
373 Wait Until Keyword Succeeds 3 min 10 sec Is BMC LastResetTime Changed ${last_reset_time}
374
375
376Get BMC Last Reset Time
377 [Documentation] Return BMC LastResetTime.
378
ganesanb4d430282023-04-27 14:33:23 +0000379 ${last_reset_time}= Redfish.Get Attribute /redfish/v1/Managers/${MANAGER_ID} LastResetTime
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600380
381 [Return] ${last_reset_time}