blob: 6c8143ed9abf9595703aa2e29533dbeaf48e6e8b [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 Keishingc2b176e2019-03-02 23:31:30 -060035 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/system/ 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}
Sridevi Ramesh0047de82019-02-01 06:33:08 -060038
39
George Keishingb10eaca2019-02-24 05:07:30 -060040Redfish BMC Reset Operation
41 [Documentation] Do Redfish BMC reset operation.
Sushil Singhb910d892021-11-17 05:34:29 -060042 [Arguments] ${reset_type}=GracefulRestart
Sridevi Ramesh0047de82019-02-01 06:33:08 -060043
George Keishingb10eaca2019-02-24 05:07:30 -060044 # Example:
45 # "Actions": {
46 # "#Manager.Reset": {
47 # "ResetType@Redfish.AllowableValues": [
Sushil Singhb910d892021-11-17 05:34:29 -060048 # "GracefulRestart",
49 # "ForceRestart"
George Keishingb10eaca2019-02-24 05:07:30 -060050 # ],
ganesanb4d430282023-04-27 14:33:23 +000051 # "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.Reset"
George Keishingb10eaca2019-02-24 05:07:30 -060052 # }
53
ganesanb4d430282023-04-27 14:33:23 +000054 ${target}= redfish_utils.Get Target Actions /redfish/v1/Managers/${MANAGER_ID}/ Manager.Reset
Sushil Singhb910d892021-11-17 05:34:29 -060055 ${payload}= Create Dictionary ResetType=${reset_type}
George Keishing07fb41f2020-06-16 08:09:19 -050056 Redfish.Post ${target} body=&{payload}
George Keishingcaa718b2019-03-10 00:08:33 -060057
58
Anvesh Kumar Rayankula0296f1d2019-12-17 03:33:16 -060059Reset BIOS Via Redfish
60 [Documentation] Do BIOS reset through Redfish.
61
62 ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/system/Bios/ Bios.ResetBios
63 Redfish.Post ${target} valid_status_codes=[${HTTP_OK}]
64
65
Sushil Singh87e984c2020-10-20 01:43:47 -050066Redfish Delete Session
67 [Documentation] Redfish delete session.
68 [Arguments] ${session_info}
69
70 # Description of argument(s):
71 # session_info Session information are stored in dictionary.
72
73 # ${session_info} = {
74 # 'SessionIDs': 'XXXXXXXXX',
75 # 'ClientID': 'XXXXXX',
76 # 'SessionToken': 'XXXXXXXXX',
77 # 'SessionResp': session response from redfish login
78 # }
79
80 # SessionIDs : Session IDs
81 # ClientID : Client ID
82 # SessionToken : Session token
83 # SessionResp : Response of creating an redfish login session
84
85 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}
86
87
88Redfish Delete List Of Session
89 [Documentation] Redfish delete session from list of session records, individual session information
90 ... are stored in dictionary.
91 [Arguments] ${session_info_list}
92
93 # Description of argument(s):
94 # session_info_list List contains individual session record are stored in dictionary.
95
96 # ${session_info_list} = [{
97 # 'SessionIDs': 'XXXXXXXXX',
98 # 'ClientID': 'XXXXXX',
99 # 'SessionToken': 'XXXXXXXXX',
100 # 'SessionResp': session response from redfish login
101 # }]
102
103 # SessionIDs : Session IDs
104 # ClientID : Client ID
105 # SessionToken : Session token
106 # SessionResp : Response of creating an redfish login session
107
108 FOR ${session_record} IN @{session_info_list}
109 Redfish.Delete /redfish/v1/SessionService/Sessions/${session_record["SessionIDs"]}
110 END
111
112
George Keishingcaa718b2019-03-10 00:08:33 -0600113Delete All Redfish Sessions
114 [Documentation] Delete all active redfish sessions.
115
Sagar Ananded737652023-01-10 02:00:31 -0600116 ${saved_session_info}= Redfish_Utils.Get Redfish Session Info
George Keishingcaa718b2019-03-10 00:08:33 -0600117
118 ${resp_list}= Redfish_Utils.Get Member List
119 ... /redfish/v1/SessionService/Sessions
120
121 # Remove the current login session from the list.
122 Remove Values From List ${resp_list} ${saved_session_info["location"]}
123
George Keishing3612f3a2022-04-21 11:21:53 -0500124 # Remove session with client_id populated from the list.
125 ${client_id_list}= Get Session With Client Id ${resp_list}
126 Log To Console Client sessions skip list: ${client_id_list}
127 FOR ${client_session} IN @{client_id_list}
128 Remove Values From List ${resp_list} ${client_session}
129 END
130
Marissa Garza20ccfc72020-06-19 12:51:10 -0500131 FOR ${session} IN @{resp_list}
George Keishing74c1c852020-12-09 09:03:55 -0600132 Run Keyword And Ignore Error Redfish.Delete ${session}
Marissa Garza20ccfc72020-06-19 12:51:10 -0500133 END
Michael Walshcf163322019-05-22 16:56:17 -0500134
Sushil Singh87e984c2020-10-20 01:43:47 -0500135
George Keishing3612f3a2022-04-21 11:21:53 -0500136Get Session With Client Id
George Keishingf9babff2023-08-16 18:40:22 +0530137 [Documentation] Iterate through the active sessions and return sessions
138 ... populated with Context.
George Keishing3612f3a2022-04-21 11:21:53 -0500139 [Arguments] ${session_list}
140
141 # Description of argument(s):
142 # session_list Active session list from SessionService.
143
George Keishingf9babff2023-08-16 18:40:22 +0530144 # "@odata.type": "#Session.v1_5_0.Session",
145 # "ClientOriginIPAddress": "xx.xx.xx.xx",
146 # "Context": "MYID-01"
George Keishing3612f3a2022-04-21 11:21:53 -0500147
148 ${client_id_sessions}= Create List
149 FOR ${session} IN @{session_list}
150 ${resp}= Redfish.Get ${session} valid_status_codes=[200,404]
George Keishingf9babff2023-08-16 18:40:22 +0530151 # This prevents dictionary KeyError exception when the Context
152 # attribute is not populated in generic session response.
153 ${context_var}= Get Variable Value ${resp.dict["Context"]} ${EMPTY}
154 Run Keyword If '${context_var}' != '${EMPTY}'
George Keishing3612f3a2022-04-21 11:21:53 -0500155 ... Append To List ${client_id_sessions} ${session}
156 END
157
158 [Return] ${client_id_sessions}
159
160
Michael Walshcf163322019-05-22 16:56:17 -0500161Get Valid FRUs
162 [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type.
163 [Arguments] ${fru_type}
164
165 # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
166
167 # Description of argument(s):
168 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
169
170 ${fru_records}= Redfish_Utils.Enumerate Request
171 ... /redfish/v1/Systems/system/${fru_type} return_json=0
Michael Walshe256a4f2019-05-29 10:49:06 -0500172 ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')]
Michael Walshcf163322019-05-22 16:56:17 -0500173
174 [Return] ${fru_records}
175
176
177Get Num Valid FRUs
178 [Documentation] Return the number of valid FRU records for the given fru_type.
179 [Arguments] ${fru_type}
180
181 # Description of argument(s):
182 # fru_type The type of fru (e.g. "Processors", "Memory", etc.).
183
184 ${fru_records}= Get Valid FRUs ${fru_type}
185 ${num_valid_frus}= Get length ${fru_records}
186
187 [Return] ${num_valid_frus}
Marissa Garzad76b1422019-09-13 16:31:54 -0500188
189
190Verify Valid Records
191 [Documentation] Verify all records retrieved with the given arguments are valid.
192 [Arguments] ${record_type} ${redfish_uri} ${reading_type}
193
194 # Description of Argument(s):
195 # record_type The sensor record type (e.g. "PowerSupplies")
196 # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power)
197 # reading_type The power watt readings (e.g. "PowerInputWatts")
198
199 # A valid record will have "State" key "Enabled" and "Health" key "OK".
200 ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type}
201
202 Rprint Vars records
203
204 # Example output:
205 # records:
206 # [0]:
207 # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0
208 # [@odata.type]: #Power.v1_0_0.PowerControl
209 # [MemberId]: 0
210 # [Name]: Chassis Power Control
211 # [PowerConsumedWatts]: 264.0
212 # [PowerLimit]:
213 # [LimitInWatts]: None
214 # [PowerMetrics]:
215 # [AverageConsumedWatts]: 325
216 # [IntervalInMin]: 3
217 # [MaxConsumedWatts]: 538
218 # [Status]:
219 # [Health]: OK
220 # [State]: Enabled
221
222 ${invalid_records}= Filter Struct ${records}
223 ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1
224 Valid Length invalid_records max_length=0
Marissa Garzafdee1b02019-09-20 14:52:12 -0500225
226 [Return] ${records}
Vijayff2c0bc2020-02-03 00:05:45 -0600227
228
229Redfish Create User
230 [Documentation] Redfish create user.
231 [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False}
232
233 # Description of argument(s):
234 # user_name The user name to be created.
235 # password The password to be assigned.
236 # role_id The role ID of the user to be created.
237 # (e.g. "Administrator", "Operator", etc.).
238 # enabled Indicates whether the username being created.
239 # should be enabled (${True}, ${False}).
240 # force Delete user account and re-create if force is True.
241
242 ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name}
243 # Ex: ${curr_role} = ('PASS', 'Administrator')
244
245 ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS
246
247 # Delete user account when force is True.
248 Run Keyword If ${force} == ${True} Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name}
249 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
250
251 # Create specified user when force is True or User does not exist.
252 ${payload}= Create Dictionary
253 ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled}
254
255 Run Keyword If ${force} == ${True} or ${user_exists} == ${False}
256 ... Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload}
257 ... valid_status_codes=[${HTTP_CREATED}]
258
259
260Get User Role
261 [Documentation] Get User Role.
262 [Arguments] ${user_name}
263
264 # Description of argument(s):
265 # user_name User name to get it's role.
266
267 ${role_config}= Redfish_Utils.Get Attribute
268 ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId
269
270 [Return] ${role_config}
271
272
273Create Users With Different Roles
274 [Documentation] Create users with different roles.
275 [Arguments] ${users} ${force}=${False}
276
277 # Description of argument(s):
278 # users Dictionary of roles and user credentails to be created.
279 # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'}
280 # force Delete given user account if already exists when force is True.
281
282 FOR ${role} IN @{users}
283 Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force}
284 END
285
Vijay39373152020-02-14 08:08:20 -0600286
287Delete BMC Users Via Redfish
288 [Documentation] Delete BMC users via redfish.
289 [Arguments] ${users}
290
291 # Description of argument(s):
292 # users Dictionary of roles and user credentials to be deleted.
293
294 FOR ${role} IN @{users}
295 Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]}
296 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
297 END
298
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600299
300Expire And Update New Password Via Redfish
301 [Documentation] Expire and change password and verify using password.
302 [Arguments] ${username} ${password} ${new_password}
303
304 # Description of argument(s):
305 # username The username to be used to login to the BMC.
306 # password The password to be used to login to the BMC.
307 # new_password The new password to be used to update password.
308
309 # Expire admin password using ssh.
Sushil Singh39848ba2022-08-10 05:49:32 -0500310 Open Connection And Log In ${OPENBMC_USERNAME} ${OPENBMC_PASSWORD}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600311 ${output} ${stderr} ${rc}= BMC Execute Command passwd --expire ${username}
Brian Ma45aa8812022-02-24 14:55:28 +0800312 Should Contain Any ${output} password expiry information changed
313 ... password changed
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600314
315 # Verify user password expired using Redfish
316 Verify User Password Expired Using Redfish ${username} ${password}
317
318 # Change user password.
Brian Ma45aa8812022-02-24 14:55:28 +0800319 Redfish.Patch /redfish/v1/AccountService/Accounts/${username}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600320 ... body={'Password': '${new_password}'}
321 Redfish.Logout
322
323
324Verify User Password Expired Using Redfish
325 [Documentation] Checking whether user password expired or not using redfish.
Sushil Singh473cf7d2023-03-09 04:24:07 -0600326 [Arguments] ${username} ${password} ${expected_result}=${True}
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600327
328 # Description of argument(s):
329 # username The username to be used to login to the BMC.
330 # password The password to be used to login to the BMC.
331
Anves Kumar rayankula7ed1ae82021-02-03 04:19:46 -0600332 Redfish.Login ${username} ${password}
333 ${resp}= Redfish.Get /redfish/v1/AccountService/Accounts/${username}
334 Should Be Equal ${resp.dict["PasswordChangeRequired"]} ${expected_result}
335
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600336
337Is BMC LastResetTime Changed
338 [Documentation] Return fail if BMC last reset time is not changed.
339 [Arguments] ${reset_time}
340
341 # Description of argument(s):
342 # reset_time Last BMC reset time.
343
344 ${last_reset_time}= Get BMC Last Reset Time
345 Should Not Be Equal ${last_reset_time} ${reset_time}
346
347
348Redfish BMC Reboot
349 [Documentation] Use Redfish API reboot BMC and wait for BMC ready.
350
351 # Get BMC last reset time for compare
352 ${last_reset_time}= Get BMC Last Reset Time
353
354 # Reboot BMC by Redfish API
355 Redfish BMC Reset Operation
356
357 # Wait for BMC real reboot and Redfish API ready
358 Wait Until Keyword Succeeds 3 min 10 sec Is BMC LastResetTime Changed ${last_reset_time}
359
360
361Get BMC Last Reset Time
362 [Documentation] Return BMC LastResetTime.
363
ganesanb4d430282023-04-27 14:33:23 +0000364 ${last_reset_time}= Redfish.Get Attribute /redfish/v1/Managers/${MANAGER_ID} LastResetTime
Prashanth Kattib3d1c7a2021-12-09 03:51:08 -0600365
366 [Return] ${last_reset_time}