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 | e187964 | 2020-12-09 13:20:15 -0600 | [diff] [blame^] | 51 | ${session_info}= Redfish.Get Session Info |
| 52 | Log ${session_info} |
| 53 | |
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 |
George Keishing | 07fb41f | 2020-06-16 08:09:19 -0500 | [diff] [blame] | 56 | Redfish.Post ${target} body=&{payload} |
George Keishing | caa718b | 2019-03-10 00:08:33 -0600 | [diff] [blame] | 57 | |
| 58 | |
Anvesh Kumar Rayankula | 0296f1d | 2019-12-17 03:33:16 -0600 | [diff] [blame] | 59 | Reset 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 Singh | 87e984c | 2020-10-20 01:43:47 -0500 | [diff] [blame] | 66 | Redfish 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 | |
| 88 | Redfish 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 Keishing | caa718b | 2019-03-10 00:08:33 -0600 | [diff] [blame] | 113 | Delete All Redfish Sessions |
| 114 | [Documentation] Delete all active redfish sessions. |
| 115 | |
George Keishing | caa718b | 2019-03-10 00:08:33 -0600 | [diff] [blame] | 116 | ${saved_session_info}= Get Redfish Session Info |
| 117 | |
| 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 | |
Marissa Garza | 20ccfc7 | 2020-06-19 12:51:10 -0500 | [diff] [blame] | 124 | FOR ${session} IN @{resp_list} |
George Keishing | 74c1c85 | 2020-12-09 09:03:55 -0600 | [diff] [blame] | 125 | Run Keyword And Ignore Error Redfish.Delete ${session} |
Marissa Garza | 20ccfc7 | 2020-06-19 12:51:10 -0500 | [diff] [blame] | 126 | END |
Michael Walsh | cf16332 | 2019-05-22 16:56:17 -0500 | [diff] [blame] | 127 | |
Sushil Singh | 87e984c | 2020-10-20 01:43:47 -0500 | [diff] [blame] | 128 | |
Michael Walsh | cf16332 | 2019-05-22 16:56:17 -0500 | [diff] [blame] | 129 | Get Valid FRUs |
| 130 | [Documentation] Return a dictionary containing all of the valid FRU records for the given fru_type. |
| 131 | [Arguments] ${fru_type} |
| 132 | |
| 133 | # NOTE: A valid FRU record will have a "State" key of "Enabled" and a "Health" key of "OK". |
| 134 | |
| 135 | # Description of argument(s): |
| 136 | # fru_type The type of fru (e.g. "Processors", "Memory", etc.). |
| 137 | |
| 138 | ${fru_records}= Redfish_Utils.Enumerate Request |
| 139 | ... /redfish/v1/Systems/system/${fru_type} return_json=0 |
Michael Walsh | e256a4f | 2019-05-29 10:49:06 -0500 | [diff] [blame] | 140 | ${fru_records}= Filter Struct ${fru_records} [('State', 'Enabled'), ('Health', 'OK')] |
Michael Walsh | cf16332 | 2019-05-22 16:56:17 -0500 | [diff] [blame] | 141 | |
| 142 | [Return] ${fru_records} |
| 143 | |
| 144 | |
| 145 | Get Num Valid FRUs |
| 146 | [Documentation] Return the number of valid FRU records for the given fru_type. |
| 147 | [Arguments] ${fru_type} |
| 148 | |
| 149 | # Description of argument(s): |
| 150 | # fru_type The type of fru (e.g. "Processors", "Memory", etc.). |
| 151 | |
| 152 | ${fru_records}= Get Valid FRUs ${fru_type} |
| 153 | ${num_valid_frus}= Get length ${fru_records} |
| 154 | |
| 155 | [Return] ${num_valid_frus} |
Marissa Garza | d76b142 | 2019-09-13 16:31:54 -0500 | [diff] [blame] | 156 | |
| 157 | |
| 158 | Verify Valid Records |
| 159 | [Documentation] Verify all records retrieved with the given arguments are valid. |
| 160 | [Arguments] ${record_type} ${redfish_uri} ${reading_type} |
| 161 | |
| 162 | # Description of Argument(s): |
| 163 | # record_type The sensor record type (e.g. "PowerSupplies") |
| 164 | # redfish_uri The power supply URI (e.g. /redfish/v1/Chassis/chassis/Power) |
| 165 | # reading_type The power watt readings (e.g. "PowerInputWatts") |
| 166 | |
| 167 | # A valid record will have "State" key "Enabled" and "Health" key "OK". |
| 168 | ${records}= Redfish.Get Attribute ${redfish_uri} ${record_type} |
| 169 | |
| 170 | Rprint Vars records |
| 171 | |
| 172 | # Example output: |
| 173 | # records: |
| 174 | # [0]: |
| 175 | # [@odata.id]: /redfish/v1/Chassis/chassis/Power#/PowerControl/0 |
| 176 | # [@odata.type]: #Power.v1_0_0.PowerControl |
| 177 | # [MemberId]: 0 |
| 178 | # [Name]: Chassis Power Control |
| 179 | # [PowerConsumedWatts]: 264.0 |
| 180 | # [PowerLimit]: |
| 181 | # [LimitInWatts]: None |
| 182 | # [PowerMetrics]: |
| 183 | # [AverageConsumedWatts]: 325 |
| 184 | # [IntervalInMin]: 3 |
| 185 | # [MaxConsumedWatts]: 538 |
| 186 | # [Status]: |
| 187 | # [Health]: OK |
| 188 | # [State]: Enabled |
| 189 | |
| 190 | ${invalid_records}= Filter Struct ${records} |
| 191 | ... [('Health', '^OK$'), ('State', '^Enabled$'), ('${reading_type}', '')] regex=1 invert=1 |
| 192 | Valid Length invalid_records max_length=0 |
Marissa Garza | fdee1b0 | 2019-09-20 14:52:12 -0500 | [diff] [blame] | 193 | |
| 194 | [Return] ${records} |
Vijay | ff2c0bc | 2020-02-03 00:05:45 -0600 | [diff] [blame] | 195 | |
| 196 | |
| 197 | Redfish Create User |
| 198 | [Documentation] Redfish create user. |
| 199 | [Arguments] ${user_name} ${password} ${role_id} ${enabled} ${force}=${False} |
| 200 | |
| 201 | # Description of argument(s): |
| 202 | # user_name The user name to be created. |
| 203 | # password The password to be assigned. |
| 204 | # role_id The role ID of the user to be created. |
| 205 | # (e.g. "Administrator", "Operator", etc.). |
| 206 | # enabled Indicates whether the username being created. |
| 207 | # should be enabled (${True}, ${False}). |
| 208 | # force Delete user account and re-create if force is True. |
| 209 | |
| 210 | ${curr_role}= Run Keyword And Ignore Error Get User Role ${user_name} |
| 211 | # Ex: ${curr_role} = ('PASS', 'Administrator') |
| 212 | |
| 213 | ${user_exists}= Run Keyword And Return Status Should Be Equal As Strings ${curr_role}[0] PASS |
| 214 | |
| 215 | # Delete user account when force is True. |
| 216 | Run Keyword If ${force} == ${True} Redfish.Delete ${REDFISH_ACCOUNTS_URI}${user_name} |
| 217 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}] |
| 218 | |
| 219 | # Create specified user when force is True or User does not exist. |
| 220 | ${payload}= Create Dictionary |
| 221 | ... UserName=${user_name} Password=${password} RoleId=${role_id} Enabled=${enabled} |
| 222 | |
| 223 | Run Keyword If ${force} == ${True} or ${user_exists} == ${False} |
| 224 | ... Redfish.Post ${REDFISH_ACCOUNTS_URI} body=&{payload} |
| 225 | ... valid_status_codes=[${HTTP_CREATED}] |
| 226 | |
| 227 | |
| 228 | Get User Role |
| 229 | [Documentation] Get User Role. |
| 230 | [Arguments] ${user_name} |
| 231 | |
| 232 | # Description of argument(s): |
| 233 | # user_name User name to get it's role. |
| 234 | |
| 235 | ${role_config}= Redfish_Utils.Get Attribute |
| 236 | ... ${REDFISH_ACCOUNTS_URI}${user_name} RoleId |
| 237 | |
| 238 | [Return] ${role_config} |
| 239 | |
| 240 | |
| 241 | Create Users With Different Roles |
| 242 | [Documentation] Create users with different roles. |
| 243 | [Arguments] ${users} ${force}=${False} |
| 244 | |
| 245 | # Description of argument(s): |
| 246 | # users Dictionary of roles and user credentails to be created. |
| 247 | # Ex: {'Administrator': '[admin_user, TestPwd123]', 'Operator': '[operator_user, TestPwd123]'} |
| 248 | # force Delete given user account if already exists when force is True. |
| 249 | |
| 250 | FOR ${role} IN @{users} |
| 251 | Redfish Create User ${users['${role}'][0]} ${users['${role}']}[1] ${role} ${True} ${force} |
| 252 | END |
| 253 | |
Vijay | 3937315 | 2020-02-14 08:08:20 -0600 | [diff] [blame] | 254 | |
| 255 | Delete BMC Users Via Redfish |
| 256 | [Documentation] Delete BMC users via redfish. |
| 257 | [Arguments] ${users} |
| 258 | |
| 259 | # Description of argument(s): |
| 260 | # users Dictionary of roles and user credentials to be deleted. |
| 261 | |
| 262 | FOR ${role} IN @{users} |
| 263 | Redfish.Delete /redfish/v1/AccountService/Accounts/${users['${role}'][0]} |
| 264 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NOT_FOUND}] |
| 265 | END |
| 266 | |