blob: c4422e8b7c22154b087da7bccf1020c9f5e62a7e [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
George Keishing43909f32024-08-20 22:08:02 +053035 ${target}= Wait Until Keyword Succeeds 1 min 20 sec
36 ... redfish_utils.Get Target Actions /redfish/v1/Systems/${SYSTEM_ID}/ ComputerSystem.Reset
Sridevi Ramesh0047de82019-02-01 06:33:08 -060037 ${payload}= Create Dictionary ResetType=${reset_type}
Michael Walsh213feb32019-03-08 14:44:31 -060038 ${resp}= Redfish.Post ${target} body=&{payload}
George Keishing8a86c692024-03-29 09:52:25 +053039 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sridevi Ramesh0047de82019-02-01 06:33:08 -060040
41
George Keishingb10eaca2019-02-24 05:07:30 -060042Redfish BMC Reset Operation
43 [Documentation] Do Redfish BMC reset operation.
Sushil Singhb910d892021-11-17 05:34:29 -060044 [Arguments] ${reset_type}=GracefulRestart
Sridevi Ramesh0047de82019-02-01 06:33:08 -060045
George Keishingb10eaca2019-02-24 05:07:30 -060046 # Example:
47 # "Actions": {
48 # "#Manager.Reset": {
49 # "ResetType@Redfish.AllowableValues": [
Sushil Singhb910d892021-11-17 05:34:29 -060050 # "GracefulRestart",
51 # "ForceRestart"
George Keishingb10eaca2019-02-24 05:07:30 -060052 # ],
ganesanb4d430282023-04-27 14:33:23 +000053 # "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.Reset"
George Keishingb10eaca2019-02-24 05:07:30 -060054 # }
55
George Keishing43909f32024-08-20 22:08:02 +053056 ${target}= Wait Until Keyword Succeeds 1 min 20 sec
57 ... redfish_utils.Get Target Actions /redfish/v1/Managers/${MANAGER_ID}/ Manager.Reset
Sushil Singhb910d892021-11-17 05:34:29 -060058 ${payload}= Create Dictionary ResetType=${reset_type}
George Keishing07fb41f2020-06-16 08:09:19 -050059 Redfish.Post ${target} body=&{payload}
George Keishingcaa718b2019-03-10 00:08:33 -060060
61
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060062Reset BIOS Via Redfish
63 [Documentation] Do BIOS reset through Redfish.
64
Yi Huc32434a2024-01-11 17:33:10 -080065 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/${SYSTEM_ID}/Bios/ Bios.ResetBios
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060066 Redfish.Post ${target} valid_status_codes=[${HTTP_OK}]
67
68
Yi Hu02d32762024-03-07 14:34:34 -080069Set Redfish Delete Session Flag
70 [Documentation] Disable or enable delete redfish while performing the power operation keyword.
71 [Arguments] ${set_flag}
72
73 # Description of argument(s):
74 # set_flag Set user specified enable(1) or disable(0).
75
76 Set Suite Variable ${REDFISH_DELETE_SESSIONS} ${set_flag}
77
78
Sushil Singh87e984c2020-10-20 01:43:47 -050079Redfish Delete Session
80 [Documentation] Redfish delete session.
81 [Arguments] ${session_info}
82
83 # Description of argument(s):
84 # session_info Session information are stored in dictionary.
85
86 # ${session_info} = {
87 # 'SessionIDs': 'XXXXXXXXX',
88 # 'ClientID': 'XXXXXX',
89 # 'SessionToken': 'XXXXXXXXX',
90 # 'SessionResp': session response from redfish login
91 # }
92
93 # SessionIDs : Session IDs
94 # ClientID : Client ID
95 # SessionToken : Session token
96 # SessionResp : Response of creating an redfish login session
97
98 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}
99
100
101Redfish Delete List Of Session
102 [Documentation] Redfish delete session from list of session records, individual session information
103 ... are stored in dictionary.
104 [Arguments] ${session_info_list}
105
106 # Description of argument(s):
107 # session_info_list List contains individual session record are stored in dictionary.
108
109 # ${session_info_list} = [{
110 # 'SessionIDs': 'XXXXXXXXX',
111 # 'ClientID': 'XXXXXX',
112 # 'SessionToken': 'XXXXXXXXX',
113 # 'SessionResp': session response from redfish login
114 # }]
115
116 # SessionIDs : Session IDs
117 # ClientID : Client ID
118 # SessionToken : Session token
119 # SessionResp : Response of creating an redfish login session
120
121 FOR ${session_record} IN @{session_info_list}
122 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_record["SessionIDs"]}
123 END
124
125
George Keishingcaa718b2019-03-10 00:08:33 -0600126Delete All Redfish Sessions
127 [Documentation] Delete all active redfish sessions.
128
Sagar Ananded737652023-01-10 02:00:31 -0600129 ${saved_session_info}= Redfish_Utils.Get Redfish Session Info
George Keishingcaa718b2019-03-10 00:08:33 -0600130
131 ${resp_list}= Redfish_Utils.Get Member List
132 ... /redfish/v1/SessionService/Sessions
133
134 # Remove the current login session from the list.
135 Remove Values From List ${resp_list} ${saved_session_info["location"]}
136
George Keishing3612f3a2022-04-21 11:21:53 -0500137 # Remove session with client_id populated from the list.
138 ${client_id_list}= Get Session With Client Id ${resp_list}
139 Log To Console Client sessions skip list: ${client_id_list}
140 FOR ${client_session} IN @{client_id_list}
141 Remove Values From List ${resp_list} ${client_session}
142 END
143
Marissa Garza20ccfc72020-06-19 12:51:10 -0500144 FOR ${session} IN @{resp_list}
George Keishing74c1c852020-12-09 09:03:55 -0600145 Run Keyword And Ignore Error Redfish.Delete ${session}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500146 END
Michael Walshcf163322019-05-22 16:56:17 -0500147
Sushil Singh87e984c2020-10-20 01:43:47 -0500148
George Keishing3612f3a2022-04-21 11:21:53 -0500149Get Session With Client Id
George Keishingf9babff2023-08-16 18:40:22 +0530150 [Documentation] Iterate through the active sessions and return sessions
151 ... populated with Context.
George Keishing3612f3a2022-04-21 11:21:53 -0500152 [Arguments] ${session_list}
153
154 # Description of argument(s):
155 # session_list Active session list from SessionService.
156
George Keishingf9babff2023-08-16 18:40:22 +0530157 # "@odata.type": "#Session.v1_5_0.Session",
158 # "ClientOriginIPAddress": "xx.xx.xx.xx",
159 # "Context": "MYID-01"
George Keishing3612f3a2022-04-21 11:21:53 -0500160
161 ${client_id_sessions}= Create List
162 FOR ${session} IN @{session_list}
163 ${resp}= Redfish.Get ${session} valid_status_codes=[200,404]
George Keishingf9babff2023-08-16 18:40:22 +0530164 # This prevents dictionary KeyError exception when the Context
165 # attribute is not populated in generic session response.
166 ${context_var}= Get Variable Value ${resp.dict["Context"]} ${EMPTY}
George Keishingd2bcbf72023-09-15 22:44:02 +0530167 # Handle backward compatibility for OEM.
168 ${oem_var}= Get Variable Value ${resp.dict["Oem"]["OpenBMC"]["ClientID"]} ${EMPTY}
George Keishingf9babff2023-08-16 18:40:22 +0530169 Run Keyword If '${context_var}' != '${EMPTY}'
George Keishing3612f3a2022-04-21 11:21:53 -0500170 ... Append To List ${client_id_sessions} ${session}
George Keishingd2bcbf72023-09-15 22:44:02 +0530171 Run Keyword If '${oem_var}' != '${EMPTY}'
172 ... Append To List ${client_id_sessions} ${session}
George Keishing3612f3a2022-04-21 11:21:53 -0500173 END
174
George Keishing409df052024-01-17 22:36:14 +0530175 RETURN ${client_id_sessions}
George Keishing3612f3a2022-04-21 11:21:53 -0500176
177
Michael Walshcf163322019-05-22 16:56:17 -0500178Get Valid FRUs
179 [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type.
180 [Arguments] ${fru_type}
181
182 # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
183
184 # Description of argument(s):
185 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
186
187 ${fru_records}= Redfish_Utils.Enumerate Request
Yi Huc32434a2024-01-11 17:33:10 -0800188 ... /redfish/v1/Systems/${SYSTEM_ID}/${fru_type} return_json=0
Michael Walshe256a4f2019-05-29 10:49:06 -0500189 ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')]
Michael Walshcf163322019-05-22 16:56:17 -0500190
George Keishing409df052024-01-17 22:36:14 +0530191 RETURN ${fru_records}
Michael Walshcf163322019-05-22 16:56:17 -0500192
193
194Get Num Valid FRUs
195 [Documentation] Return the number of valid FRU records for the given fru_type.
196 [Arguments] ${fru_type}
197
198 # Description of argument(s):
199 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
200
201 ${fru_records}= Get Valid FRUs ${fru_type}
202 ${num_valid_frus}= Get length ${fru_records}
203
George Keishing409df052024-01-17 22:36:14 +0530204 RETURN ${num_valid_frus}
Marissa Garzad76b1422019-09-13 16:31:54 -0500205
206
207Verify Valid Records
208 [Documentation] Verify all records retrieved with the given arguments are valid.
209 [Arguments] ${record_type} ${redfish_uri} ${reading_type}
210
211 # Description of Argument(s):
212 # record_type The sensor record type (e.g. "PowerSupplies")
213 # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power)
214 # reading_type The power watt readings (e.g. "PowerInputWatts")
215
216 # A valid record will have "State" key "Enabled" and "Health" key "OK".
217 ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type}
218
219 Rprint Vars records
220
221 # Example output:
222 # records:
223 # [0]:
224 # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0
225 # [@odata.type]: #Power.v1_0_0.PowerControl
226 # [MemberId]: 0
227 # [Name]: Chassis Power Control
228 # [PowerConsumedWatts]: 264.0
229 # [PowerLimit]:
230 # [LimitInWatts]: None
231 # [PowerMetrics]:
232 # [AverageConsumedWatts]: 325
233 # [IntervalInMin]: 3
234 # [MaxConsumedWatts]: 538
235 # [Status]:
236 # [Health]: OK
237 # [State]: Enabled
238
239 ${invalid_records}= Filter Struct ${records}
240 ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1
241 Valid Length invalid_records max_length=0
Marissa Garzafdee1b02019-09-20 14:52:12 -0500242
George Keishing409df052024-01-17 22:36:14 +0530243 RETURN ${records}
Vijayff2c0bc2020-02-03 00:05:45 -0600244
245
246Redfish Create User
247 [Documentation] Redfish create user.
248 [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False}
249
250 # Description of argument(s):
251 # user_name The user name to be created.
252 # password The password to be assigned.
253 # role_id The role ID of the user to be created.
254 # (e.g. "Administrator", "Operator", etc.).
255 # enabled Indicates whether the username being created.
256 # should be enabled (${True}, ${False}).
257 # force Delete user account and re-create if force is True.
258
259 ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name}
260 # Ex: ${curr_role} = ('PASS', 'Administrator')
261
262 ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS
263
264 # Delete user account when force is True.
265 Run Keyword If ${force} == ${True} Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name}
266 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
267
268 # Create specified user when force is True or User does not exist.
269 ${payload}= Create Dictionary
270 ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled}
271
272 Run Keyword If ${force} == ${True} or ${user_exists} == ${False}
273 ... Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
274 ... valid_status_codes=[${HTTP_CREATED}]
275
276
277Get User Role
278 [Documentation] Get User Role.
279 [Arguments] ${user_name}
280
281 # Description of argument(s):
282 # user_name User name to get it's role.
283
284 ${role_config}= Redfish_Utils.Get Attribute
285 ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId
286
George Keishing409df052024-01-17 22:36:14 +0530287 RETURN ${role_config}
Vijayff2c0bc2020-02-03 00:05:45 -0600288
289
290Create Users With Different Roles
291 [Documentation] Create users with different roles.
292 [Arguments] ${users} ${force}=${False}
293
294 # Description of argument(s):
George Keishing9bfdf8a2024-04-19 11:09:07 +0530295 # users Dictionary of roles and user credentials to be created.
Vijayff2c0bc2020-02-03 00:05:45 -0600296 # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'}
297 # force Delete given user account if already exists when force is True.
298
299 FOR ${role} IN @{users}
300 Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force}
301 END
302
Vijay39373152020-02-14 08:08:20 -0600303
304Delete BMC Users Via Redfish
305 [Documentation] Delete BMC users via redfish.
306 [Arguments] ${users}
307
308 # Description of argument(s):
309 # users Dictionary of roles and user credentials to be deleted.
310
311 FOR ${role} IN @{users}
312 Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]}
313 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
314 END
315
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600316
317Expire And Update New Password Via Redfish
318 [Documentation] Expire and change password and verify using password.
319 [Arguments] ${username} ${password} ${new_password}
320
321 # Description of argument(s):
322 # username The username to be used to login to the BMC.
323 # password The password to be used to login to the BMC.
324 # new_password The new password to be used to update password.
325
326 # Expire admin password using ssh.
Sushil Singh39848ba2022-08-10 05:49:32 -0500327 Open Connection And Log In ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600328 ${output} ${stderr} ${rc}= BMC Execute Command passwd --expire ${username}
Brian Ma45aa8812022-02-24 14:55:28 +0800329 Should Contain Any ${output} password expiry information changed
330 ... password changed
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600331
332 # Verify user password expired using Redfish
333 Verify User Password Expired Using Redfish ${username} ${password}
334
335 # Change user password.
Brian Ma45aa8812022-02-24 14:55:28 +0800336 Redfish.Patch /redfish/v1/AccountService/Accounts/${username}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600337 ... body={'Password': '${new_password}'}
338 Redfish.Logout
339
340
341Verify User Password Expired Using Redfish
342 [Documentation] Checking whether user password expired or not using redfish.
Sushil Singh473cf7d2023-03-09 04:24:07 -0600343 [Arguments] ${username} ${password} ${expected_result}=${True}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600344
345 # Description of argument(s):
346 # username The username to be used to login to the BMC.
347 # password The password to be used to login to the BMC.
348
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600349 Redfish.Login ${username} ${password}
350 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/${username}
351 Should Be Equal ${resp.dict["PasswordChangeRequired"]} ${expected_result}
352
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600353
354Is BMC LastResetTime Changed
355 [Documentation] Return fail if BMC last reset time is not changed.
356 [Arguments] ${reset_time}
357
358 # Description of argument(s):
359 # reset_time Last BMC reset time.
360
361 ${last_reset_time}= Get BMC Last Reset Time
362 Should Not Be Equal ${last_reset_time} ${reset_time}
363
364
365Redfish BMC Reboot
366 [Documentation] Use Redfish API reboot BMC and wait for BMC ready.
367
368 # Get BMC last reset time for compare
369 ${last_reset_time}= Get BMC Last Reset Time
370
371 # Reboot BMC by Redfish API
372 Redfish BMC Reset Operation
373
374 # Wait for BMC real reboot and Redfish API ready
375 Wait Until Keyword Succeeds 3 min 10 sec Is BMC LastResetTime Changed ${last_reset_time}
376
377
378Get BMC Last Reset Time
379 [Documentation] Return BMC LastResetTime.
380
ganesanb4d430282023-04-27 14:33:23 +0000381 ${last_reset_time}= Redfish.Get Attribute /redfish/v1/Managers/${MANAGER_ID} LastResetTime
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600382
George Keishing409df052024-01-17 22:36:14 +0530383 RETURN ${last_reset_time}