xref: /openbmc/openbmc-test-automation/lib/bmc_redfish_utils.robot (revision b78e76d4a3c477c4427e1d48bfc7a1e89c73b3ab)
10047de86SSridevi Ramesh*** Settings ***
2b10eacafSGeorge KeishingDocumentation   BMC and host redfish utility keywords.
30047de86SSridevi Ramesh
42db7bcaeSGeorge KeishingResource        resource.robot
50047de86SSridevi RameshResource        bmc_redfish_resource.robot
60047de86SSridevi Ramesh
70047de86SSridevi Ramesh
80047de86SSridevi Ramesh*** Keywords ***
90047de86SSridevi Ramesh
100047de86SSridevi RameshRedfish Power Operation
11b10eacafSGeorge Keishing    [Documentation]  Do Redfish host power operation.
120047de86SSridevi Ramesh    [Arguments]      ${reset_type}
13b910d89bSSushil Singh
140047de86SSridevi Ramesh    # Description of arguments:
150047de86SSridevi Ramesh    # reset_type     Type of power operation.
160047de86SSridevi Ramesh    #                (e.g. On/ForceOff/GracefulRestart/GracefulShutdown)
170047de86SSridevi Ramesh
180047de86SSridevi Ramesh    # Example:
190047de86SSridevi Ramesh    # "Actions": {
200047de86SSridevi Ramesh    # "#ComputerSystem.Reset": {
21*b78e76d4SGeorge Keishing    #        "@Redfish.ActionInfo": "/redfish/v1/Systems/${SYSTEM_ID}/ResetActionInfo",
22*b78e76d4SGeorge Keishing    #        "target": "/redfish/v1/Systems/${SYSTEM_ID}/Actions/ComputerSystem.Reset"
23*b78e76d4SGeorge Keishing    #    }
24*b78e76d4SGeorge Keishing
25*b78e76d4SGeorge Keishing    # Parameters allowable values  /redfish/v1/Systems/${SYSTEM_ID}/ResetActionInfo
26*b78e76d4SGeorge Keishing
27*b78e76d4SGeorge Keishing    # "@odata.id": "/redfish/v1/Systems/${SYSTEM_ID}/ResetActionInfo",
28*b78e76d4SGeorge Keishing    # "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
29*b78e76d4SGeorge Keishing    # "Id": "ResetActionInfo",
30*b78e76d4SGeorge Keishing    # "Name": "Reset Action Info",
31*b78e76d4SGeorge Keishing    # "Parameters": [
32*b78e76d4SGeorge Keishing    #    {
33*b78e76d4SGeorge Keishing    #        "AllowableValues": [
340047de86SSridevi Ramesh    #            "ForceOff",
35eeb526ceSGeorge Keishing    #            "PowerCycle",
36*b78e76d4SGeorge Keishing    #            "Nmi",
37*b78e76d4SGeorge Keishing    #            "GracefulShutdown",
38*b78e76d4SGeorge Keishing    #            "On",
39*b78e76d4SGeorge Keishing    #            "ForceOn",
40*b78e76d4SGeorge Keishing    #            "GracefulRestart",
41*b78e76d4SGeorge Keishing    #            "ForceRestart"
420047de86SSridevi Ramesh    #        ],
43*b78e76d4SGeorge Keishing    #        "DataType": "String",
44*b78e76d4SGeorge Keishing    #        "Name": "ResetType",
45*b78e76d4SGeorge Keishing    #        "Required": true
462deec3cfSGeorge Keishing    #    }
47*b78e76d4SGeorge Keishing    # ]
480047de86SSridevi Ramesh
4943909f32SGeorge Keishing    ${target}=  Wait Until Keyword Succeeds  1 min  20 sec
5043909f32SGeorge Keishing    ...  redfish_utils.Get Target Actions  /redfish/v1/Systems/${SYSTEM_ID}/  ComputerSystem.Reset
510047de86SSridevi Ramesh    ${payload}=  Create Dictionary  ResetType=${reset_type}
52213feb34SMichael Walsh    ${resp}=  Redfish.Post  ${target}  body=&{payload}
538a86c69dSGeorge Keishing    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
540047de86SSridevi Ramesh
550047de86SSridevi Ramesh
56b10eacafSGeorge KeishingRedfish BMC Reset Operation
57b10eacafSGeorge Keishing    [Documentation]  Do Redfish BMC reset operation.
58b910d89bSSushil Singh    [Arguments]  ${reset_type}=GracefulRestart
590047de86SSridevi Ramesh
60b10eacafSGeorge Keishing    # Example:
61b10eacafSGeorge Keishing    # "Actions": {
62b10eacafSGeorge Keishing    #    "#Manager.Reset": {
63*b78e76d4SGeorge Keishing    #        "@Redfish.ActionInfo": "/redfish/v1/Managers/${MANAGER_ID}/ResetActionInfo",
64*b78e76d4SGeorge Keishing    #        "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.Reset"
65*b78e76d4SGeorge Keishing    #    },
66*b78e76d4SGeorge Keishing    #    "#Manager.ResetToDefaults": {
67b10eacafSGeorge Keishing    #        "ResetType@Redfish.AllowableValues": [
68*b78e76d4SGeorge Keishing    #            "ResetAll"
69*b78e76d4SGeorge Keishing    #        ],
70*b78e76d4SGeorge Keishing    #        "target": "/redfish/v1/Managers/${MANAGER_ID}/Actions/Manager.ResetToDefaults"
71*b78e76d4SGeorge Keishing    #    }
72*b78e76d4SGeorge Keishing    # },
73*b78e76d4SGeorge Keishing
74*b78e76d4SGeorge Keishing    # Parameters allowable values  /redfish/v1/Managers/${MANAGER_ID}/ResetActionInfo
75*b78e76d4SGeorge Keishing
76*b78e76d4SGeorge Keishing    # "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/ResetActionInfo",
77*b78e76d4SGeorge Keishing    # "@odata.type": "#ActionInfo.v1_1_2.ActionInfo",
78*b78e76d4SGeorge Keishing    # "Id": "ResetActionInfo",
79*b78e76d4SGeorge Keishing    # "Name": "Reset Action Info",
80*b78e76d4SGeorge Keishing    # "Parameters": [
81*b78e76d4SGeorge Keishing    #    {
82*b78e76d4SGeorge Keishing    #        "AllowableValues": [
83b910d89bSSushil Singh    #            "GracefulRestart",
84b910d89bSSushil Singh    #            "ForceRestart"
85b10eacafSGeorge Keishing    #        ],
86*b78e76d4SGeorge Keishing    #        "DataType": "String",
87*b78e76d4SGeorge Keishing    #        "Name": "ResetType",
88*b78e76d4SGeorge Keishing    #        "Required": true
89b10eacafSGeorge Keishing    #    }
90*b78e76d4SGeorge Keishing    # ]
91b10eacafSGeorge Keishing
9243909f32SGeorge Keishing    ${target}=  Wait Until Keyword Succeeds  1 min  20 sec
9343909f32SGeorge Keishing    ...  redfish_utils.Get Target Actions  /redfish/v1/Managers/${MANAGER_ID}/  Manager.Reset
94b910d89bSSushil Singh    ${payload}=  Create Dictionary  ResetType=${reset_type}
9507fb41f7SGeorge Keishing    Redfish.Post  ${target}  body=&{payload}
96caa718bfSGeorge Keishing
97caa718bfSGeorge Keishing
980296f1d2SAnvesh Kumar RayankulaReset BIOS Via Redfish
990296f1d2SAnvesh Kumar Rayankula    [Documentation]  Do BIOS reset through Redfish.
1000296f1d2SAnvesh Kumar Rayankula
101c32434a3SYi Hu    ${target}=  redfish_utils.Get Target Actions  /redfish/v1/Systems/${SYSTEM_ID}/Bios/  Bios.ResetBios
1020296f1d2SAnvesh Kumar Rayankula    Redfish.Post  ${target}  valid_status_codes=[${HTTP_OK}]
1030296f1d2SAnvesh Kumar Rayankula
1040296f1d2SAnvesh Kumar Rayankula
10502d32765SYi HuSet Redfish Delete Session Flag
10602d32765SYi Hu    [Documentation]  Disable or enable delete redfish while performing the power operation keyword.
10702d32765SYi Hu    [Arguments]  ${set_flag}
10802d32765SYi Hu
10902d32765SYi Hu    # Description of argument(s):
11002d32765SYi Hu    # set_flag    Set user specified enable(1) or disable(0).
11102d32765SYi Hu
11202d32765SYi Hu    Set Suite Variable  ${REDFISH_DELETE_SESSIONS}  ${set_flag}
11302d32765SYi Hu
11402d32765SYi Hu
11587e984c8SSushil SinghRedfish Delete Session
11687e984c8SSushil Singh    [Documentation]  Redfish delete session.
11787e984c8SSushil Singh    [Arguments]  ${session_info}
11887e984c8SSushil Singh
11987e984c8SSushil Singh    # Description of argument(s):
12087e984c8SSushil Singh    # session_info      Session information are stored in dictionary.
12187e984c8SSushil Singh
12287e984c8SSushil Singh    # ${session_info} = {
12387e984c8SSushil Singh    #     'SessionIDs': 'XXXXXXXXX',
12487e984c8SSushil Singh    #     'ClientID': 'XXXXXX',
12587e984c8SSushil Singh    #     'SessionToken': 'XXXXXXXXX',
12687e984c8SSushil Singh    #     'SessionResp': session response from redfish login
12787e984c8SSushil Singh    # }
12887e984c8SSushil Singh
12987e984c8SSushil Singh    # SessionIDs   : Session IDs
13087e984c8SSushil Singh    # ClientID     : Client ID
13187e984c8SSushil Singh    # SessionToken : Session token
13287e984c8SSushil Singh    # SessionResp  : Response of creating an redfish login session
13387e984c8SSushil Singh
13487e984c8SSushil Singh    Redfish.Delete  /redfish/v1/SessionService/Sessions/${session_info["SessionIDs"]}
13587e984c8SSushil Singh
13687e984c8SSushil Singh
13787e984c8SSushil SinghRedfish Delete List Of Session
13887e984c8SSushil Singh    [Documentation]  Redfish delete session from list of session records, individual session information
13987e984c8SSushil Singh    ...              are stored in dictionary.
14087e984c8SSushil Singh    [Arguments]  ${session_info_list}
14187e984c8SSushil Singh
14287e984c8SSushil Singh    # Description of argument(s):
14387e984c8SSushil Singh    # session_info_list    List contains individual session record are stored in dictionary.
14487e984c8SSushil Singh
14587e984c8SSushil Singh    # ${session_info_list} = [{
14687e984c8SSushil Singh    #     'SessionIDs': 'XXXXXXXXX',
14787e984c8SSushil Singh    #     'ClientID': 'XXXXXX',
14887e984c8SSushil Singh    #     'SessionToken': 'XXXXXXXXX',
14987e984c8SSushil Singh    #     'SessionResp': session response from redfish login
15087e984c8SSushil Singh    # }]
15187e984c8SSushil Singh
15287e984c8SSushil Singh    # SessionIDs   : Session IDs
15387e984c8SSushil Singh    # ClientID     : Client ID
15487e984c8SSushil Singh    # SessionToken : Session token
15587e984c8SSushil Singh    # SessionResp  : Response of creating an redfish login session
15687e984c8SSushil Singh
15787e984c8SSushil Singh    FOR  ${session_record}  IN  @{session_info_list}
15887e984c8SSushil Singh      Redfish.Delete  /redfish/v1/SessionService/Sessions/${session_record["SessionIDs"]}
15987e984c8SSushil Singh    END
16087e984c8SSushil Singh
16187e984c8SSushil Singh
162caa718bfSGeorge KeishingDelete All Redfish Sessions
163caa718bfSGeorge Keishing    [Documentation]  Delete all active redfish sessions.
164caa718bfSGeorge Keishing
165ed737653SSagar Anand    ${saved_session_info}=  Redfish_Utils.Get Redfish Session Info
166caa718bfSGeorge Keishing
167caa718bfSGeorge Keishing    ${resp_list}=  Redfish_Utils.Get Member List
168caa718bfSGeorge Keishing    ...  /redfish/v1/SessionService/Sessions
169caa718bfSGeorge Keishing
170caa718bfSGeorge Keishing    # Remove the current login session from the list.
171caa718bfSGeorge Keishing    Remove Values From List  ${resp_list}  ${saved_session_info["location"]}
172caa718bfSGeorge Keishing
1733612f3aaSGeorge Keishing    # Remove session with client_id populated from the list.
1743612f3aaSGeorge Keishing    ${client_id_list}=  Get Session With Client Id  ${resp_list}
1753612f3aaSGeorge Keishing    Log To Console  Client sessions skip list: ${client_id_list}
1763612f3aaSGeorge Keishing    FOR  ${client_session}  IN  @{client_id_list}
1773612f3aaSGeorge Keishing        Remove Values From List  ${resp_list}  ${client_session}
1783612f3aaSGeorge Keishing    END
1793612f3aaSGeorge Keishing
18020ccfc71SMarissa Garza    FOR  ${session}  IN  @{resp_list}
18174c1c856SGeorge Keishing        Run Keyword And Ignore Error  Redfish.Delete  ${session}
18220ccfc71SMarissa Garza    END
183cf163321SMichael Walsh
18487e984c8SSushil Singh
1853612f3aaSGeorge KeishingGet Session With Client Id
186f9babff8SGeorge Keishing    [Documentation]  Iterate through the active sessions and return sessions
187f9babff8SGeorge Keishing    ...              populated with Context.
1883612f3aaSGeorge Keishing    [Arguments]  ${session_list}
1893612f3aaSGeorge Keishing
1903612f3aaSGeorge Keishing    # Description of argument(s):
1913612f3aaSGeorge Keishing    # session_list   Active session list from SessionService.
1923612f3aaSGeorge Keishing
193f9babff8SGeorge Keishing    # "@odata.type": "#Session.v1_5_0.Session",
194f9babff8SGeorge Keishing    # "ClientOriginIPAddress": "xx.xx.xx.xx",
195f9babff8SGeorge Keishing    # "Context": "MYID-01"
1963612f3aaSGeorge Keishing
1973612f3aaSGeorge Keishing    ${client_id_sessions}=  Create List
1983612f3aaSGeorge Keishing    FOR  ${session}  IN  @{session_list}
1993612f3aaSGeorge Keishing        ${resp}=  Redfish.Get  ${session}   valid_status_codes=[200,404]
200f9babff8SGeorge Keishing        # This prevents dictionary KeyError exception when the Context
201f9babff8SGeorge Keishing        # attribute is not populated in generic session response.
202f9babff8SGeorge Keishing        ${context_var}=  Get Variable Value  ${resp.dict["Context"]}  ${EMPTY}
203d2bcbf76SGeorge Keishing        # Handle backward compatibility for OEM.
204d2bcbf76SGeorge Keishing        ${oem_var}=  Get Variable Value  ${resp.dict["Oem"]["OpenBMC"]["ClientID"]}  ${EMPTY}
205f9babff8SGeorge Keishing        Run Keyword If  '${context_var}' != '${EMPTY}'
2063612f3aaSGeorge Keishing        ...    Append To List  ${client_id_sessions}  ${session}
207d2bcbf76SGeorge Keishing        Run Keyword If  '${oem_var}' != '${EMPTY}'
208d2bcbf76SGeorge Keishing        ...    Append To List  ${client_id_sessions}  ${session}
2093612f3aaSGeorge Keishing    END
2103612f3aaSGeorge Keishing
211409df05dSGeorge Keishing    RETURN  ${client_id_sessions}
2123612f3aaSGeorge Keishing
2133612f3aaSGeorge Keishing
214cf163321SMichael WalshGet Valid FRUs
215cf163321SMichael Walsh    [Documentation]  Return a dictionary containing all of the valid FRU records for the given fru_type.
216cf163321SMichael Walsh    [Arguments]  ${fru_type}
217cf163321SMichael Walsh
218cf163321SMichael Walsh    # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
219cf163321SMichael Walsh
220cf163321SMichael Walsh    # Description of argument(s):
221cf163321SMichael Walsh    # fru_type  The type of fru (e.g. "Processors", "Memory", etc.).
222cf163321SMichael Walsh
223cf163321SMichael Walsh    ${fru_records}=  Redfish_Utils.Enumerate Request
224c32434a3SYi Hu    ...  /redfish/v1/Systems/${SYSTEM_ID}/${fru_type}  return_json=0
225e256a4f6SMichael Walsh    ${fru_records}=  Filter Struct  ${fru_records}  [('State', 'Enabled'), ('Health', 'OK')]
226cf163321SMichael Walsh
227409df05dSGeorge Keishing    RETURN  ${fru_records}
228cf163321SMichael Walsh
229cf163321SMichael Walsh
230cf163321SMichael WalshGet Num Valid FRUs
231cf163321SMichael Walsh    [Documentation]  Return the number of valid FRU records for the given fru_type.
232cf163321SMichael Walsh    [Arguments]  ${fru_type}
233cf163321SMichael Walsh
234cf163321SMichael Walsh    # Description of argument(s):
235cf163321SMichael Walsh    # fru_type  The type of fru (e.g. "Processors", "Memory", etc.).
236cf163321SMichael Walsh
237cf163321SMichael Walsh    ${fru_records}=  Get Valid FRUs  ${fru_type}
238cf163321SMichael Walsh    ${num_valid_frus}=  Get length  ${fru_records}
239cf163321SMichael Walsh
240409df05dSGeorge Keishing    RETURN  ${num_valid_frus}
241d76b1423SMarissa Garza
242d76b1423SMarissa Garza
243d76b1423SMarissa GarzaVerify Valid Records
244d76b1423SMarissa Garza    [Documentation]  Verify all records retrieved with the given arguments are valid.
245d76b1423SMarissa Garza    [Arguments]  ${record_type}  ${redfish_uri}  ${reading_type}
246d76b1423SMarissa Garza
247d76b1423SMarissa Garza    # Description of Argument(s):
248d76b1423SMarissa Garza    # record_type    The sensor record type (e.g. "PowerSupplies")
249d76b1423SMarissa Garza    # redfish_uri    The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power)
250d76b1423SMarissa Garza    # reading_type   The power watt readings (e.g. "PowerInputWatts")
251d76b1423SMarissa Garza
252d76b1423SMarissa Garza    # A valid record will have "State" key "Enabled" and "Health" key "OK".
253d76b1423SMarissa Garza    ${records}=  Redfish.Get Attribute  ${redfish_uri}  ${record_type}
254d76b1423SMarissa Garza
255d76b1423SMarissa Garza    Rprint Vars  records
256d76b1423SMarissa Garza
257d76b1423SMarissa Garza    # Example output:
258d76b1423SMarissa Garza    # records:
259d76b1423SMarissa Garza    #   [0]:
260d76b1423SMarissa Garza    #     [@odata.id]:                 /redfish/v1/Chassis/chassis/Power#/PowerControl/0
261d76b1423SMarissa Garza    #     [@odata.type]:               #Power.v1_0_0.PowerControl
262d76b1423SMarissa Garza    #     [MemberId]:                  0
263d76b1423SMarissa Garza    #     [Name]:                      Chassis Power Control
264d76b1423SMarissa Garza    #     [PowerConsumedWatts]:        264.0
265d76b1423SMarissa Garza    #     [PowerLimit]:
266d76b1423SMarissa Garza    #       [LimitInWatts]:            None
267d76b1423SMarissa Garza    #     [PowerMetrics]:
268d76b1423SMarissa Garza    #       [AverageConsumedWatts]:    325
269d76b1423SMarissa Garza    #       [IntervalInMin]:           3
270d76b1423SMarissa Garza    #       [MaxConsumedWatts]:        538
271d76b1423SMarissa Garza    #     [Status]:
272d76b1423SMarissa Garza    #       [Health]:                  OK
273d76b1423SMarissa Garza    #       [State]:                   Enabled
274d76b1423SMarissa Garza
275d76b1423SMarissa Garza    ${invalid_records}=  Filter Struct  ${records}
276d76b1423SMarissa Garza    ...  [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')]  regex=1  invert=1
277d76b1423SMarissa Garza    Valid Length  invalid_records  max_length=0
278fdee1b05SMarissa Garza
279409df05dSGeorge Keishing    RETURN  ${records}
280ff2c0bc4SVijay
281ff2c0bc4SVijay
282ff2c0bc4SVijayRedfish Create User
283ff2c0bc4SVijay    [Documentation]  Redfish create user.
284ff2c0bc4SVijay    [Arguments]   ${user_name}  ${password}  ${role_id}  ${enabled}  ${force}=${False}
285ff2c0bc4SVijay
286ff2c0bc4SVijay    # Description of argument(s):
287ff2c0bc4SVijay    # user_name           The user name to be created.
288ff2c0bc4SVijay    # password            The password to be assigned.
289ff2c0bc4SVijay    # role_id             The role ID of the user to be created.
290ff2c0bc4SVijay    #                     (e.g. "Administrator", "Operator", etc.).
291ff2c0bc4SVijay    # enabled             Indicates whether the username being created.
292ff2c0bc4SVijay    #                     should be enabled (${True}, ${False}).
293ff2c0bc4SVijay    # force               Delete user account and re-create if force is True.
294ff2c0bc4SVijay
295ff2c0bc4SVijay    ${curr_role}=  Run Keyword And Ignore Error  Get User Role  ${user_name}
296ff2c0bc4SVijay    # Ex: ${curr_role} = ('PASS', 'Administrator')
297ff2c0bc4SVijay
298ff2c0bc4SVijay    ${user_exists}=  Run Keyword And Return Status  Should Be Equal As Strings  ${curr_role}[0]  PASS
299ff2c0bc4SVijay
300ff2c0bc4SVijay    # Delete user account when force is True.
301ff2c0bc4SVijay    Run Keyword If  ${force} == ${True}  Redfish.Delete  ${REDFISH_ACCOUNTS_URI}${user_name}
302ff2c0bc4SVijay    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
303ff2c0bc4SVijay
304ff2c0bc4SVijay    # Create specified user when force is True or User does not exist.
305ff2c0bc4SVijay    ${payload}=  Create Dictionary
306ff2c0bc4SVijay    ...  UserName=${user_name}  Password=${password}  RoleId=${role_id}  Enabled=${enabled}
307ff2c0bc4SVijay
308ff2c0bc4SVijay    Run Keyword If  ${force} == ${True} or ${user_exists} == ${False}
309ff2c0bc4SVijay    ...  Redfish.Post  ${REDFISH_ACCOUNTS_URI}  body=&{payload}
310ff2c0bc4SVijay    ...  valid_status_codes=[${HTTP_CREATED}]
311ff2c0bc4SVijay
312ff2c0bc4SVijay
313ff2c0bc4SVijayGet User Role
314ff2c0bc4SVijay    [Documentation]  Get User Role.
315ff2c0bc4SVijay    [Arguments]  ${user_name}
316ff2c0bc4SVijay
317ff2c0bc4SVijay    # Description of argument(s):
318ff2c0bc4SVijay    # user_name    User name to get it's role.
319ff2c0bc4SVijay
320ff2c0bc4SVijay    ${role_config}=  Redfish_Utils.Get Attribute
321ff2c0bc4SVijay    ...  ${REDFISH_ACCOUNTS_URI}${user_name}  RoleId
322ff2c0bc4SVijay
323409df05dSGeorge Keishing    RETURN  ${role_config}
324ff2c0bc4SVijay
325ff2c0bc4SVijay
326ff2c0bc4SVijayCreate Users With Different Roles
327ff2c0bc4SVijay    [Documentation]  Create users with different roles.
328ff2c0bc4SVijay    [Arguments]  ${users}  ${force}=${False}
329ff2c0bc4SVijay
330ff2c0bc4SVijay    # Description of argument(s):
3319bfdf8a7SGeorge Keishing    # users    Dictionary of roles and user credentials to be created.
332ff2c0bc4SVijay    #          Ex:  {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'}
333ff2c0bc4SVijay    # force    Delete given user account if already exists when force is True.
334ff2c0bc4SVijay
335ff2c0bc4SVijay    FOR  ${role}  IN  @{users}
336ff2c0bc4SVijay      Redfish Create User  ${users['${role}'][0]}  ${users['${role}']}[1]  ${role}  ${True}  ${force}
337ff2c0bc4SVijay    END
338ff2c0bc4SVijay
33939373158SVijay
34039373158SVijayDelete BMC Users Via Redfish
34139373158SVijay    [Documentation]  Delete BMC users via redfish.
34239373158SVijay    [Arguments]  ${users}
34339373158SVijay
34439373158SVijay    # Description of argument(s):
34539373158SVijay    # users    Dictionary of roles and user credentials to be deleted.
34639373158SVijay
34739373158SVijay    FOR  ${role}  IN  @{users}
34839373158SVijay        Redfish.Delete  /redfish/v1/AccountService/Accounts/${users['${role}'][0]}
34939373158SVijay        ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}]
35039373158SVijay    END
35139373158SVijay
3527ed1ae88SAnves Kumar rayankula
3537ed1ae88SAnves Kumar rayankulaExpire And Update New Password Via Redfish
3547ed1ae88SAnves Kumar rayankula    [Documentation]  Expire and change password and verify using password.
3557ed1ae88SAnves Kumar rayankula    [Arguments]  ${username}  ${password}  ${new_password}
3567ed1ae88SAnves Kumar rayankula
3577ed1ae88SAnves Kumar rayankula    # Description of argument(s):
3587ed1ae88SAnves Kumar rayankula    # username        The username to be used to login to the BMC.
3597ed1ae88SAnves Kumar rayankula    # password        The password to be used to login to the BMC.
3607ed1ae88SAnves Kumar rayankula    # new_password    The new password to be used to update password.
3617ed1ae88SAnves Kumar rayankula
3627ed1ae88SAnves Kumar rayankula    # Expire admin password using ssh.
36339848ba6SSushil Singh    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
3647ed1ae88SAnves Kumar rayankula    ${output}  ${stderr}  ${rc}=  BMC Execute Command  passwd --expire ${username}
36545aa881dSBrian Ma    Should Contain Any  ${output}  password expiry information changed
36645aa881dSBrian Ma    ...  password changed
3677ed1ae88SAnves Kumar rayankula
3687ed1ae88SAnves Kumar rayankula    # Verify user password expired using Redfish
3697ed1ae88SAnves Kumar rayankula    Verify User Password Expired Using Redfish  ${username}  ${password}
3707ed1ae88SAnves Kumar rayankula
3717ed1ae88SAnves Kumar rayankula    # Change user password.
37245aa881dSBrian Ma    Redfish.Patch  /redfish/v1/AccountService/Accounts/${username}
3737ed1ae88SAnves Kumar rayankula    ...  body={'Password': '${new_password}'}
3747ed1ae88SAnves Kumar rayankula    Redfish.Logout
3757ed1ae88SAnves Kumar rayankula
3767ed1ae88SAnves Kumar rayankula
3777ed1ae88SAnves Kumar rayankulaVerify User Password Expired Using Redfish
3787ed1ae88SAnves Kumar rayankula    [Documentation]  Checking whether user password expired or not using redfish.
379473cf7dcSSushil Singh    [Arguments]  ${username}  ${password}  ${expected_result}=${True}
3807ed1ae88SAnves Kumar rayankula
3817ed1ae88SAnves Kumar rayankula    # Description of argument(s):
3827ed1ae88SAnves Kumar rayankula    # username        The username to be used to login to the BMC.
3837ed1ae88SAnves Kumar rayankula    # password        The password to be used to login to the BMC.
3847ed1ae88SAnves Kumar rayankula
3857ed1ae88SAnves Kumar rayankula    Redfish.Login  ${username}  ${password}
3867ed1ae88SAnves Kumar rayankula    ${resp}=  Redfish.Get  /redfish/v1/AccountService/Accounts/${username}
3877ed1ae88SAnves Kumar rayankula    Should Be Equal  ${resp.dict["PasswordChangeRequired"]}  ${expected_result}
3887ed1ae88SAnves Kumar rayankula
389b3d1c7aaSPrashanth Katti
390b3d1c7aaSPrashanth KattiIs BMC LastResetTime Changed
391b3d1c7aaSPrashanth Katti    [Documentation]  Return fail if BMC last reset time is not changed.
392b3d1c7aaSPrashanth Katti    [Arguments]  ${reset_time}
393b3d1c7aaSPrashanth Katti
394b3d1c7aaSPrashanth Katti    # Description of argument(s):
395b3d1c7aaSPrashanth Katti    # reset_time  Last BMC reset time.
396b3d1c7aaSPrashanth Katti
397b3d1c7aaSPrashanth Katti    ${last_reset_time}=  Get BMC Last Reset Time
398b3d1c7aaSPrashanth Katti    Should Not Be Equal  ${last_reset_time}  ${reset_time}
399b3d1c7aaSPrashanth Katti
400b3d1c7aaSPrashanth Katti
401b3d1c7aaSPrashanth KattiRedfish BMC Reboot
402b3d1c7aaSPrashanth Katti    [Documentation]  Use Redfish API reboot BMC and wait for BMC ready.
403b3d1c7aaSPrashanth Katti
404b3d1c7aaSPrashanth Katti    #  Get BMC last reset time for compare
405b3d1c7aaSPrashanth Katti    ${last_reset_time}=  Get BMC Last Reset Time
406b3d1c7aaSPrashanth Katti
407b3d1c7aaSPrashanth Katti    # Reboot BMC by Redfish API
408b3d1c7aaSPrashanth Katti    Redfish BMC Reset Operation
409b3d1c7aaSPrashanth Katti
410b3d1c7aaSPrashanth Katti    # Wait for BMC real reboot and Redfish API ready
411b3d1c7aaSPrashanth Katti    Wait Until Keyword Succeeds  3 min  10 sec  Is BMC LastResetTime Changed  ${last_reset_time}
412b3d1c7aaSPrashanth Katti
413b3d1c7aaSPrashanth Katti
414b3d1c7aaSPrashanth KattiGet BMC Last Reset Time
415b3d1c7aaSPrashanth Katti    [Documentation]  Return BMC LastResetTime.
416b3d1c7aaSPrashanth Katti
4174d430283Sganesanb    ${last_reset_time}=  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  LastResetTime
418b3d1c7aaSPrashanth Katti
419409df05dSGeorge Keishing    RETURN  ${last_reset_time}
420