Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 1 | *** Settings *** |
George Keishing | b10eaca | 2019-02-24 05:07:30 -0600 | [diff] [blame] | 2 | Documentation BMC and host redfish utility keywords. |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 3 | |
George Keishing | 2db7bca | 2019-02-14 13:03:08 -0600 | [diff] [blame] | 4 | Resource resource.robot |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 5 | Resource bmc_redfish_resource.robot |
| 6 | |
| 7 | |
| 8 | *** Keywords *** |
| 9 | |
| 10 | Redfish Power Operation |
George Keishing | b10eaca | 2019-02-24 05:07:30 -0600 | [diff] [blame] | 11 | [Documentation] Do Redfish host power operation. |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 12 | [Arguments] ${reset_type} |
| 13 | # Description of arguments: |
| 14 | # reset_type Type of power operation. |
| 15 | # (e.g. On/ForceOff/GracefulRestart/GracefulShutdown) |
| 16 | |
| 17 | # Example: |
| 18 | # "Actions": { |
| 19 | # "#ComputerSystem.Reset": { |
| 20 | # "ResetType@Redfish.AllowableValues": [ |
| 21 | # "On", |
| 22 | # "ForceOff", |
George Keishing | eeb526c | 2020-03-03 07:39:44 -0600 | [diff] [blame] | 23 | # "ForceOn", |
| 24 | # "ForceRestart", |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 25 | # "GracefulRestart", |
| 26 | # "GracefulShutdown" |
George Keishing | eeb526c | 2020-03-03 07:39:44 -0600 | [diff] [blame] | 27 | # "PowerCycle", |
| 28 | # "Nmi" |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 29 | # ], |
George Keishing | 2deec3c | 2019-02-26 09:20:10 -0600 | [diff] [blame] | 30 | # "target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset" |
| 31 | # } |
| 32 | # } |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 33 | |
Michael Walsh | 213feb3 | 2019-03-08 14:44:31 -0600 | [diff] [blame] | 34 | Redfish.Login |
George Keishing | c2b176e | 2019-03-02 23:31:30 -0600 | [diff] [blame] | 35 | ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/system/ ComputerSystem.Reset |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 36 | ${payload}= Create Dictionary ResetType=${reset_type} |
Michael Walsh | 213feb3 | 2019-03-08 14:44:31 -0600 | [diff] [blame] | 37 | ${resp}= Redfish.Post ${target} body=&{payload} |
| 38 | Redfish.Logout |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 39 | |
| 40 | |
George Keishing | b10eaca | 2019-02-24 05:07:30 -0600 | [diff] [blame] | 41 | Redfish BMC Reset Operation |
| 42 | [Documentation] Do Redfish BMC reset operation. |
Sridevi Ramesh | 0047de8 | 2019-02-01 06:33:08 -0600 | [diff] [blame] | 43 | |
George Keishing | b10eaca | 2019-02-24 05:07:30 -0600 | [diff] [blame] | 44 | # Example: |
| 45 | # "Actions": { |
| 46 | # "#Manager.Reset": { |
| 47 | # "ResetType@Redfish.AllowableValues": [ |
| 48 | # "GracefulRestart" |
| 49 | # ], |
| 50 | # "target": "/redfish/v1/Managers/bmc/Actions/Manager.Reset" |
| 51 | # } |
| 52 | |
Michael Walsh | 213feb3 | 2019-03-08 14:44:31 -0600 | [diff] [blame] | 53 | Redfish.Login |
George Keishing | c2b176e | 2019-03-02 23:31:30 -0600 | [diff] [blame] | 54 | ${target}= redfish_utils.Get Target Actions /redfish/v1/Managers/bmc/ Manager.Reset |
George Keishing | b10eaca | 2019-02-24 05:07:30 -0600 | [diff] [blame] | 55 | ${payload}= Create Dictionary ResetType=GracefulRestart |
Michael Walsh | 213feb3 | 2019-03-08 14:44:31 -0600 | [diff] [blame] | 56 | ${resp}= Redfish.Post ${target} body=&{payload} |
| 57 | # The logout may very well fail because the system was just asked to |
| 58 | # reset itself. |
| 59 | Run Keyword And Ignore Error Redfish.Logout |
George Keishing | caa718b | 2019-03-10 00:08:33 -0600 | [diff] [blame] | 60 | |
| 61 | |
Anvesh Kumar Rayankula | 0296f1d | 2019-12-17 03:33:16 -0600 | [diff] [blame] | 62 | Reset BIOS Via Redfish |
| 63 | [Documentation] Do BIOS reset through Redfish. |
| 64 | |
| 65 | ${target}= redfish_utils.Get Target Actions /redfish/v1/Systems/system/Bios/ Bios.ResetBios |
| 66 | Redfish.Post ${target} valid_status_codes=[${HTTP_OK}] |
| 67 | |
| 68 | |
George Keishing | caa718b | 2019-03-10 00:08:33 -0600 | [diff] [blame] | 69 | Delete All Redfish Sessions |
| 70 | [Documentation] Delete all active redfish sessions. |
| 71 | |
| 72 | Redfish.Login |
| 73 | ${saved_session_info}= Get Redfish Session Info |
| 74 | |
| 75 | ${resp_list}= Redfish_Utils.Get Member List |
| 76 | ... /redfish/v1/SessionService/Sessions |
| 77 | |
| 78 | # Remove the current login session from the list. |
| 79 | Remove Values From List ${resp_list} ${saved_session_info["location"]} |
| 80 | |
| 81 | :FOR ${session} IN @{resp_list} |
| 82 | \ Redfish.Delete ${session} |
| 83 | |
| 84 | Redfish.Logout |
Michael Walsh | cf16332 | 2019-05-22 16:56:17 -0500 | [diff] [blame] | 85 | |
| 86 | |
| 87 | Get Valid FRUs |
| 88 | [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type. |
| 89 | [Arguments] ${fru_type} |
| 90 | |
| 91 | # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK". |
| 92 | |
| 93 | # Description of argument(s): |
| 94 | # fru_type The type of fru (e.g. "Processors", "Memory", etc.). |
| 95 | |
| 96 | ${fru_records}= Redfish_Utils.Enumerate Request |
| 97 | ... /redfish/v1/Systems/system/${fru_type} return_json=0 |
Michael Walsh | e256a4f | 2019-05-29 10:49:06 -0500 | [diff] [blame] | 98 | ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')] |
Michael Walsh | cf16332 | 2019-05-22 16:56:17 -0500 | [diff] [blame] | 99 | |
| 100 | [Return] ${fru_records} |
| 101 | |
| 102 | |
| 103 | Get Num Valid FRUs |
| 104 | [Documentation] Return the number of valid FRU records for the given fru_type. |
| 105 | [Arguments] ${fru_type} |
| 106 | |
| 107 | # Description of argument(s): |
| 108 | # fru_type The type of fru (e.g. "Processors", "Memory", etc.). |
| 109 | |
| 110 | ${fru_records}= Get Valid FRUs ${fru_type} |
| 111 | ${num_valid_frus}= Get length ${fru_records} |
| 112 | |
| 113 | [Return] ${num_valid_frus} |
Marissa Garza | d76b142 | 2019-09-13 16:31:54 -0500 | [diff] [blame] | 114 | |
| 115 | |
| 116 | Verify Valid Records |
| 117 | [Documentation] Verify all records retrieved with the given arguments are valid. |
| 118 | [Arguments] ${record_type} ${redfish_uri} ${reading_type} |
| 119 | |
| 120 | # Description of Argument(s): |
| 121 | # record_type The sensor record type (e.g. "PowerSupplies") |
| 122 | # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power) |
| 123 | # reading_type The power watt readings (e.g. "PowerInputWatts") |
| 124 | |
| 125 | # A valid record will have "State" key "Enabled" and "Health" key "OK". |
| 126 | ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type} |
| 127 | |
| 128 | Rprint Vars records |
| 129 | |
| 130 | # Example output: |
| 131 | # records: |
| 132 | # [0]: |
| 133 | # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0 |
| 134 | # [@odata.type]: #Power.v1_0_0.PowerControl |
| 135 | # [MemberId]: 0 |
| 136 | # [Name]: Chassis Power Control |
| 137 | # [PowerConsumedWatts]: 264.0 |
| 138 | # [PowerLimit]: |
| 139 | # [LimitInWatts]: None |
| 140 | # [PowerMetrics]: |
| 141 | # [AverageConsumedWatts]: 325 |
| 142 | # [IntervalInMin]: 3 |
| 143 | # [MaxConsumedWatts]: 538 |
| 144 | # [Status]: |
| 145 | # [Health]: OK |
| 146 | # [State]: Enabled |
| 147 | |
| 148 | ${invalid_records}= Filter Struct ${records} |
| 149 | ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1 |
| 150 | Valid Length invalid_records max_length=0 |
Marissa Garza | fdee1b0 | 2019-09-20 14:52:12 -0500 | [diff] [blame] | 151 | |
| 152 | [Return] ${records} |
Vijay | ff2c0bc | 2020-02-03 00:05:45 -0600 | [diff] [blame] | 153 | |
| 154 | |
| 155 | Redfish Create User |
| 156 | [Documentation] Redfish create user. |
| 157 | [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False} |
| 158 | |
| 159 | # Description of argument(s): |
| 160 | # user_name The user name to be created. |
| 161 | # password The password to be assigned. |
| 162 | # role_id The role ID of the user to be created. |
| 163 | # (e.g. "Administrator", "Operator", etc.). |
| 164 | # enabled Indicates whether the username being created. |
| 165 | # should be enabled (${True}, ${False}). |
| 166 | # force Delete user account and re-create if force is True. |
| 167 | |
| 168 | ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name} |
| 169 | # Ex: ${curr_role} = ('PASS', 'Administrator') |
| 170 | |
| 171 | ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS |
| 172 | |
| 173 | # Delete user account when force is True. |
| 174 | Run Keyword If ${force} == ${True} Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name} |
| 175 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}] |
| 176 | |
| 177 | # Create specified user when force is True or User does not exist. |
| 178 | ${payload}= Create Dictionary |
| 179 | ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled} |
| 180 | |
| 181 | Run Keyword If ${force} == ${True} or ${user_exists} == ${False} |
| 182 | ... Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload} |
| 183 | ... valid_status_codes=[${HTTP_CREATED}] |
| 184 | |
| 185 | |
| 186 | Get User Role |
| 187 | [Documentation] Get User Role. |
| 188 | [Arguments] ${user_name} |
| 189 | |
| 190 | # Description of argument(s): |
| 191 | # user_name User name to get it's role. |
| 192 | |
| 193 | ${role_config}= Redfish_Utils.Get Attribute |
| 194 | ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId |
| 195 | |
| 196 | [Return] ${role_config} |
| 197 | |
| 198 | |
| 199 | Create Users With Different Roles |
| 200 | [Documentation] Create users with different roles. |
| 201 | [Arguments] ${users} ${force}=${False} |
| 202 | |
| 203 | # Description of argument(s): |
| 204 | # users Dictionary of roles and user credentails to be created. |
| 205 | # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'} |
| 206 | # force Delete given user account if already exists when force is True. |
| 207 | |
| 208 | FOR ${role} IN @{users} |
| 209 | Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force} |
| 210 | END |
| 211 | |
Vijay | 3937315 | 2020-02-14 08:08:20 -0600 | [diff] [blame] | 212 | |
| 213 | Delete BMC Users Via Redfish |
| 214 | [Documentation] Delete BMC users via redfish. |
| 215 | [Arguments] ${users} |
| 216 | |
| 217 | # Description of argument(s): |
| 218 | # users Dictionary of roles and user credentials to be deleted. |
| 219 | |
| 220 | FOR ${role} IN @{users} |
| 221 | Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]} |
| 222 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}] |
| 223 | END |
| 224 | |