xref: /openbmc/openbmc-test-automation/lib/bmc_redfish_utils.robot (revision e256a4f6987b21f2ddae5ab810d8eed46e27590e)
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}
130047de86SSridevi Ramesh    # Description of arguments:
140047de86SSridevi Ramesh    # reset_type     Type of power operation.
150047de86SSridevi Ramesh    #                (e.g. On/ForceOff/GracefulRestart/GracefulShutdown)
160047de86SSridevi Ramesh
170047de86SSridevi Ramesh    # Example:
180047de86SSridevi Ramesh    # "Actions": {
190047de86SSridevi Ramesh    # "#ComputerSystem.Reset": {
200047de86SSridevi Ramesh    #  "ResetType@Redfish.AllowableValues": [
210047de86SSridevi Ramesh    #    "On",
220047de86SSridevi Ramesh    #    "ForceOff",
230047de86SSridevi Ramesh    #    "GracefulRestart",
240047de86SSridevi Ramesh    #    "GracefulShutdown"
250047de86SSridevi Ramesh    #  ],
262deec3cfSGeorge Keishing    #  "target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"
272deec3cfSGeorge Keishing    #  }
282deec3cfSGeorge Keishing    # }
290047de86SSridevi Ramesh
30213feb34SMichael Walsh    Redfish.Login
31c2b176e2SGeorge Keishing    ${target}=  redfish_utils.Get Target Actions  /redfish/v1/Systems/system/  ComputerSystem.Reset
320047de86SSridevi Ramesh    ${payload}=  Create Dictionary  ResetType=${reset_type}
33213feb34SMichael Walsh    ${resp}=  Redfish.Post  ${target}  body=&{payload}
34213feb34SMichael Walsh    Redfish.Logout
350047de86SSridevi Ramesh
360047de86SSridevi Ramesh
37b10eacafSGeorge KeishingRedfish BMC Reset Operation
38b10eacafSGeorge Keishing    [Documentation]  Do Redfish BMC reset operation.
390047de86SSridevi Ramesh
40b10eacafSGeorge Keishing    # Example:
41b10eacafSGeorge Keishing    # "Actions": {
42b10eacafSGeorge Keishing    # "#Manager.Reset": {
43b10eacafSGeorge Keishing    #  "ResetType@Redfish.AllowableValues": [
44b10eacafSGeorge Keishing    #    "GracefulRestart"
45b10eacafSGeorge Keishing    #  ],
46b10eacafSGeorge Keishing    #  "target": "/redfish/v1/Managers/bmc/Actions/Manager.Reset"
47b10eacafSGeorge Keishing    # }
48b10eacafSGeorge Keishing
49213feb34SMichael Walsh    Redfish.Login
50c2b176e2SGeorge Keishing    ${target}=  redfish_utils.Get Target Actions  /redfish/v1/Managers/bmc/  Manager.Reset
51b10eacafSGeorge Keishing    ${payload}=  Create Dictionary  ResetType=GracefulRestart
52213feb34SMichael Walsh    ${resp}=  Redfish.Post  ${target}  body=&{payload}
53213feb34SMichael Walsh    # The logout may very well fail because the system was just asked to
54213feb34SMichael Walsh    # reset itself.
55213feb34SMichael Walsh    Run Keyword And Ignore Error  Redfish.Logout
56caa718bfSGeorge Keishing
57caa718bfSGeorge Keishing
58caa718bfSGeorge KeishingDelete All Redfish Sessions
59caa718bfSGeorge Keishing    [Documentation]  Delete all active redfish sessions.
60caa718bfSGeorge Keishing
61caa718bfSGeorge Keishing    Redfish.Login
62caa718bfSGeorge Keishing    ${saved_session_info}=  Get Redfish Session Info
63caa718bfSGeorge Keishing
64caa718bfSGeorge Keishing    ${resp_list}=  Redfish_Utils.Get Member List
65caa718bfSGeorge Keishing    ...  /redfish/v1/SessionService/Sessions
66caa718bfSGeorge Keishing
67caa718bfSGeorge Keishing    # Remove the current login session from the list.
68caa718bfSGeorge Keishing    Remove Values From List  ${resp_list}  ${saved_session_info["location"]}
69caa718bfSGeorge Keishing
70caa718bfSGeorge Keishing    :FOR  ${session}  IN  @{resp_list}
71caa718bfSGeorge Keishing    \  Redfish.Delete  ${session}
72caa718bfSGeorge Keishing
73caa718bfSGeorge Keishing    Redfish.Logout
74cf163321SMichael Walsh
75cf163321SMichael Walsh
76cf163321SMichael WalshGet Valid FRUs
77cf163321SMichael Walsh    [Documentation]  Return a dictionary containing all of the valid FRU records for the given fru_type.
78cf163321SMichael Walsh    [Arguments]  ${fru_type}
79cf163321SMichael Walsh
80cf163321SMichael Walsh    # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK".
81cf163321SMichael Walsh
82cf163321SMichael Walsh    # Description of argument(s):
83cf163321SMichael Walsh    # fru_type  The type of fru (e.g. "Processors", "Memory", etc.).
84cf163321SMichael Walsh
85cf163321SMichael Walsh    ${fru_records}=  Redfish_Utils.Enumerate Request
86cf163321SMichael Walsh    ...  /redfish/v1/Systems/system/${fru_type}  return_json=0
87*e256a4f6SMichael Walsh    ${fru_records}=  Filter Struct  ${fru_records}  [('State', 'Enabled'), ('Health', 'OK')]
88cf163321SMichael Walsh
89cf163321SMichael Walsh    [Return]  ${fru_records}
90cf163321SMichael Walsh
91cf163321SMichael Walsh
92cf163321SMichael WalshGet Num Valid FRUs
93cf163321SMichael Walsh    [Documentation]  Return the number of valid FRU records for the given fru_type.
94cf163321SMichael Walsh    [Arguments]  ${fru_type}
95cf163321SMichael Walsh
96cf163321SMichael Walsh    # Description of argument(s):
97cf163321SMichael Walsh    # fru_type  The type of fru (e.g. "Processors", "Memory", etc.).
98cf163321SMichael Walsh
99cf163321SMichael Walsh    ${fru_records}=  Get Valid FRUs  ${fru_type}
100cf163321SMichael Walsh    ${num_valid_frus}=  Get length  ${fru_records}
101cf163321SMichael Walsh
102cf163321SMichael Walsh    [Return]  ${num_valid_frus}
103