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