| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 1 | *** Settings *** | 
|  | 2 | Documentation   Redfish BMC and PNOR software utilities keywords. | 
|  | 3 |  | 
|  | 4 | Library         code_update_utils.py | 
|  | 5 | Library         gen_robot_valid.py | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 6 | Library         tftp_update_utils.py | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 7 | Resource        bmc_redfish_utils.robot | 
| Sushil Singh | 32e2b58 | 2019-08-16 04:58:24 -0500 | [diff] [blame] | 8 | Resource        boot_utils.robot | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 9 |  | 
|  | 10 | *** Keywords *** | 
|  | 11 |  | 
|  | 12 | Get Software Functional State | 
|  | 13 | [Documentation]  Return functional or active state of the software (i.e. True/False). | 
|  | 14 | [Arguments]  ${image_id} | 
|  | 15 |  | 
|  | 16 | # Description of argument(s): | 
|  | 17 | # image_id   The image ID (e.g. "acc9e073"). | 
|  | 18 |  | 
|  | 19 | ${image_info}=  Redfish.Get Properties  /redfish/v1/UpdateService/FirmwareInventory/${image_id} | 
|  | 20 |  | 
| Sushil Singh | 8469a48 | 2020-07-30 04:19:10 -0500 | [diff] [blame] | 21 | ${sw_functional}=  Run Keyword If | 
|  | 22 | ...   '${image_info["Description"]}' == 'BMC image' or '${image_info["Description"]}' == 'BMC update' | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 23 | ...    Redfish.Get Attribute  /redfish/v1/Managers/bmc  FirmwareVersion | 
|  | 24 | ...  ELSE | 
|  | 25 | ...    Redfish.Get Attribute  /redfish/v1/Systems/system  BiosVersion | 
|  | 26 |  | 
|  | 27 | ${functional}=  Run Keyword And Return Status | 
|  | 28 | ...   Should Be Equal  ${sw_functional}  ${image_info["Version"]} | 
|  | 29 |  | 
|  | 30 | [Return]  ${functional} | 
|  | 31 |  | 
|  | 32 |  | 
|  | 33 | Get Software Inventory State | 
|  | 34 | [Documentation]  Return dictionary of the image type, version and functional state | 
|  | 35 | ...  of the software objects active on the system. | 
|  | 36 |  | 
|  | 37 | # User defined state for software objects. | 
|  | 38 | # Note: "Functional" term refers to firmware which system is currently booted with. | 
|  | 39 | # sw_inv_dict: | 
|  | 40 | #   [ace821ef]: | 
|  | 41 | #     [image_type]:                 Host update | 
| George Keishing | 3102949 | 2019-07-30 13:14:13 -0500 | [diff] [blame] | 42 | #     [image_id]:                   ace821ef | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 43 | #     [functional]:                 True | 
|  | 44 | #     [version]:                    witherspoon-xx.xx.xx.xx | 
|  | 45 | #   [b9101858]: | 
|  | 46 | #     [image_type]:                 BMC update | 
| George Keishing | 3102949 | 2019-07-30 13:14:13 -0500 | [diff] [blame] | 47 | #     [image_id]:                   b9101858 | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 48 | #     [functional]:                 True | 
|  | 49 | #     [version]:                    2.8.0-dev-150-g04508dc9f | 
|  | 50 | #   [c45eafa5]: | 
|  | 51 | #     [image_type]:                 BMC update | 
| George Keishing | 3102949 | 2019-07-30 13:14:13 -0500 | [diff] [blame] | 52 | #     [image_id]:                   c45eafa5 | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 53 | #     [functional]:                 False | 
|  | 54 | #     [version]:                    2.8.0-dev-149-g1a8df5077 | 
|  | 55 |  | 
|  | 56 | ${sw_member_list}=  Redfish_Utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory | 
|  | 57 | &{sw_inv_dict}=  Create Dictionary | 
|  | 58 |  | 
|  | 59 | # sw_member_list: | 
|  | 60 | #   [0]:                            /redfish/v1/UpdateService/FirmwareInventory/98744d76 | 
|  | 61 | #   [1]:                            /redfish/v1/UpdateService/FirmwareInventory/9a8028ec | 
|  | 62 | #   [2]:                            /redfish/v1/UpdateService/FirmwareInventory/acc9e073 | 
|  | 63 |  | 
|  | 64 | FOR  ${uri_path}  IN  @{sw_member_list} | 
|  | 65 | &{tmp_dict}=  Create Dictionary | 
|  | 66 | ${image_info}=  Redfish.Get Properties  ${uri_path} | 
|  | 67 | Set To Dictionary  ${tmp_dict}  image_type  ${image_info["Description"]} | 
| George Keishing | 3102949 | 2019-07-30 13:14:13 -0500 | [diff] [blame] | 68 | Set To Dictionary  ${tmp_dict}  image_id  ${uri_path.split("/")[-1]} | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 69 | ${functional}=  Get Software Functional State  ${uri_path.split("/")[-1]} | 
|  | 70 | Set To Dictionary  ${tmp_dict}  functional  ${functional} | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 71 | Set To Dictionary  ${tmp_dict}  version  ${image_info["Version"]} | 
| George Keishing | 3102949 | 2019-07-30 13:14:13 -0500 | [diff] [blame] | 72 | Set To Dictionary  ${sw_inv_dict}  ${uri_path.split("/")[-1]}  ${tmp_dict} | 
| George Keishing | 72abe82 | 2019-07-29 08:03:40 -0500 | [diff] [blame] | 73 | END | 
|  | 74 |  | 
|  | 75 | [Return]  &{sw_inv_dict} | 
| George Keishing | 3102949 | 2019-07-30 13:14:13 -0500 | [diff] [blame] | 76 |  | 
|  | 77 |  | 
|  | 78 | Get Software Inventory State By Version | 
|  | 79 | [Documentation]  Return the software inventory record that matches the given software version. | 
|  | 80 | [Arguments]  ${software_version} | 
|  | 81 |  | 
|  | 82 | # If no matchine record can be found, return ${EMPTY}. | 
|  | 83 |  | 
|  | 84 | # Example of returned data: | 
|  | 85 | # software_inventory_record: | 
|  | 86 | #   [image_type]:      BMC update | 
|  | 87 | #   [image_id]:        1e662ba8 | 
|  | 88 | #   [functional]:      True | 
|  | 89 | #   [version]:         2.8.0-dev-150-g04508dc9f | 
|  | 90 |  | 
|  | 91 | # Description of argument(s): | 
|  | 92 | # software_version     A BMC or Host version (e.g "2.8.0-dev-150-g04508dc9f"). | 
|  | 93 |  | 
|  | 94 | ${software_inventory}=  Get Software Inventory State | 
|  | 95 | # Filter out entries that don't match the criterion.. | 
|  | 96 | ${software_inventory}=  Filter Struct  ${software_inventory}  [('version', '${software_version}')] | 
|  | 97 | # Convert from dictionary to list. | 
|  | 98 | ${software_inventory}=  Get Dictionary Values  ${software_inventory} | 
|  | 99 | ${num_records}=  Get Length  ${software_inventory} | 
|  | 100 |  | 
|  | 101 | Return From Keyword If  ${num_records} == ${0}  ${EMPTY} | 
|  | 102 |  | 
|  | 103 | # Return the first list entry. | 
|  | 104 | [Return]  ${software_inventory}[0] | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 105 |  | 
|  | 106 |  | 
| Sushil Singh | b2150da | 2020-12-07 07:05:42 -0600 | [diff] [blame] | 107 | Get BMC Functional Firmware | 
|  | 108 | [Documentation]  Get BMC functional firmware details. | 
|  | 109 |  | 
|  | 110 | ${sw_inv}=  Get Functional Firmware  BMC update | 
|  | 111 | ${sw_inv}=  Get Non Functional Firmware  ${sw_inv}  True | 
|  | 112 |  | 
|  | 113 | [Return]  ${sw_inv} | 
|  | 114 |  | 
|  | 115 |  | 
|  | 116 | Get Functional Firmware | 
|  | 117 | [Documentation]  Get all the BMC firmware details. | 
|  | 118 | [Arguments]  ${image_type} | 
|  | 119 |  | 
|  | 120 | # Description of argument(s): | 
|  | 121 | # image_type    Image value can be either BMC update or Host update. | 
|  | 122 |  | 
|  | 123 | ${software_inventory}=  Get Software Inventory State | 
|  | 124 | ${bmc_inv}=  Get BMC Firmware  ${image_type}  ${software_inventory} | 
|  | 125 |  | 
|  | 126 | [Return]  ${bmc_inv} | 
|  | 127 |  | 
|  | 128 |  | 
|  | 129 | Get Non Functional Firmware | 
| George Keishing | 16b3c7b | 2021-01-28 09:23:37 -0600 | [diff] [blame] | 130 | [Documentation]  Get BMC non functional firmware details. | 
| Sushil Singh | 41540ea | 2021-01-07 06:59:17 -0600 | [diff] [blame] | 131 | [Arguments]  ${sw_inv}  ${functional_state} | 
| Sushil Singh | b2150da | 2020-12-07 07:05:42 -0600 | [diff] [blame] | 132 |  | 
|  | 133 | # Description of argument(s): | 
| George Keishing | 16b3c7b | 2021-01-28 09:23:37 -0600 | [diff] [blame] | 134 | # sw_inv            This dictionary contains all the BMC firmware details. | 
| Sushil Singh | 41540ea | 2021-01-07 06:59:17 -0600 | [diff] [blame] | 135 | # functional_state  Functional state can be either True or False. | 
| Sushil Singh | b2150da | 2020-12-07 07:05:42 -0600 | [diff] [blame] | 136 |  | 
| Sushil Singh | 41540ea | 2021-01-07 06:59:17 -0600 | [diff] [blame] | 137 | ${resp}=  Filter Struct  ${sw_inv}  [('functional', ${functional_state})] | 
| Sushil Singh | 3b6f916 | 2021-05-20 06:47:47 -0500 | [diff] [blame] | 138 |  | 
|  | 139 | ${num_records}=  Get Length  ${resp} | 
|  | 140 | Set Global Variable  ${num_records} | 
|  | 141 | Return From Keyword If  ${num_records} == ${0}  ${EMPTY} | 
|  | 142 |  | 
| Sushil Singh | b2150da | 2020-12-07 07:05:42 -0600 | [diff] [blame] | 143 | ${list_inv_dict}=  Get Dictionary Values  ${resp} | 
|  | 144 |  | 
|  | 145 | [Return]  ${list_inv_dict}[0] | 
|  | 146 |  | 
|  | 147 |  | 
| Sushil Singh | 50a1be9 | 2021-06-15 06:52:36 -0500 | [diff] [blame] | 148 | Get Non Functional Firmware List | 
|  | 149 | [Documentation]  Get BMC non functional firmware details. | 
|  | 150 | [Arguments]  ${sw_inv}  ${functional_state} | 
|  | 151 |  | 
|  | 152 | # Description of argument(s): | 
|  | 153 | # sw_inv            This dictionary contains all the BMC firmware details. | 
|  | 154 | # functional_state  Functional state can be either True or False. | 
|  | 155 |  | 
|  | 156 | ${list_inv}=  Create List | 
|  | 157 |  | 
|  | 158 | FOR  ${key}  IN  @{sw_inv.keys()} | 
|  | 159 | Run Keyword If  '${sw_inv['${key}']['functional']}' == '${functional_state}' | 
|  | 160 | ...  Append To List  ${list_inv}  ${sw_inv['${key}']} | 
|  | 161 | END | 
|  | 162 |  | 
|  | 163 | [Return]  ${list_inv} | 
|  | 164 |  | 
|  | 165 |  | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 166 | Redfish Upload Image And Check Progress State | 
|  | 167 | [Documentation]  Code update with ApplyTime. | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 168 |  | 
| George Keishing | e25113a | 2021-06-18 13:50:43 -0500 | [diff] [blame] | 169 | Log To Console   Start uploading image to BMC. | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 170 | Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${IMAGE_FILE_PATH} | 
| George Keishing | e25113a | 2021-06-18 13:50:43 -0500 | [diff] [blame] | 171 | Log To Console   Completed image upload to BMC. | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 172 |  | 
|  | 173 | ${image_id}=  Get Latest Image ID | 
|  | 174 | Rprint Vars  image_id | 
|  | 175 |  | 
| George Keishing | fd32e33 | 2021-09-17 02:20:32 -0500 | [diff] [blame^] | 176 | # We have noticed firmware inventory state Enabled quickly as soon the image | 
|  | 177 | # is uploaded via redfish. | 
|  | 178 | Wait Until Keyword Succeeds  1 min  03 sec | 
|  | 179 | ...  Check Image Update Progress State  match_state='Disabled', 'Updating', 'Enabled'  image_id=${image_id} | 
| Sushil Singh | 8469a48 | 2020-07-30 04:19:10 -0500 | [diff] [blame] | 180 |  | 
| George Keishing | e25113a | 2021-06-18 13:50:43 -0500 | [diff] [blame] | 181 | Wait Until Keyword Succeeds  8 min  10 sec | 
| Sushil Singh | 87dcee1 | 2019-08-07 13:13:13 -0500 | [diff] [blame] | 182 | ...  Check Image Update Progress State | 
|  | 183 | ...    match_state='Enabled'  image_id=${image_id} | 
|  | 184 |  | 
|  | 185 |  | 
| Sushil Singh | 32e2b58 | 2019-08-16 04:58:24 -0500 | [diff] [blame] | 186 | Get Host Power State | 
|  | 187 | [Documentation]  Get host power state. | 
|  | 188 | [Arguments]  ${quiet}=0 | 
|  | 189 |  | 
|  | 190 | # Description of arguments: | 
|  | 191 | # quiet    Indicates whether results should be printed. | 
|  | 192 |  | 
|  | 193 | ${state}=  Redfish.Get Attribute | 
|  | 194 | ...  ${REDFISH_BASE_URI}Systems/system  PowerState | 
|  | 195 | Rqprint Vars  state | 
|  | 196 |  | 
|  | 197 | [Return]  ${state} | 
|  | 198 |  | 
|  | 199 |  | 
|  | 200 | Check Host Power State | 
|  | 201 | [Documentation]  Check that the machine's host state matches | 
|  | 202 | ...  the caller's required host state. | 
|  | 203 | [Arguments]  ${match_state} | 
|  | 204 |  | 
|  | 205 | # Description of argument(s): | 
|  | 206 | # match_state    The expected state. This may be one or more | 
|  | 207 | #                comma-separated values (e.g. "On", "Off"). | 
|  | 208 | #                If the actual state matches any of the | 
|  | 209 | #                states named in this argument, | 
|  | 210 | #                this keyword passes. | 
|  | 211 |  | 
|  | 212 | ${state}=  Get Host Power State | 
|  | 213 | Rvalid Value  state  valid_values=[${match_state}] | 
|  | 214 |  | 
| Sushil Singh | f17a7f6 | 2020-02-03 01:09:30 -0600 | [diff] [blame] | 215 |  | 
|  | 216 | Get System Firmware Details | 
|  | 217 | [Documentation]  Return dictionary of system firmware details. | 
|  | 218 |  | 
|  | 219 | # { | 
|  | 220 | #    FirmwareVersion: 2.8.0-dev-1067-gdc66ce1c5, | 
|  | 221 | #    BiosVersion: witherspoon-XXX-XX.X-X | 
|  | 222 | # } | 
|  | 223 |  | 
|  | 224 | ${firmware_version}=  Redfish Get BMC Version | 
|  | 225 | ${bios_version}=  Redfish Get Host Version | 
|  | 226 |  | 
|  | 227 | &{sys_firmware_dict}=  Create Dictionary | 
|  | 228 | Set To Dictionary | 
|  | 229 | ...  ${sys_firmware_dict}  FirmwareVersion  ${firmware_version}  BiosVersion  ${bios_version} | 
|  | 230 | Rprint Vars  sys_firmware_dict | 
|  | 231 |  | 
|  | 232 | [Return]  &{sys_firmware_dict} | 
|  | 233 |  | 
| Sushil Singh | 41540ea | 2021-01-07 06:59:17 -0600 | [diff] [blame] | 234 |  | 
|  | 235 | Switch Backup Firmware Image To Functional | 
|  | 236 | [Documentation]  Switch the backup firmware image to make functional. | 
|  | 237 |  | 
|  | 238 | ${sw_inv}=  Get Functional Firmware  BMC image | 
|  | 239 | ${nonfunctional_sw_inv}=  Get Non Functional Firmware  ${sw_inv}  False | 
|  | 240 |  | 
| George Keishing | f924895 | 2021-05-28 07:52:37 -0500 | [diff] [blame] | 241 | ${firmware_inv_path}= | 
|  | 242 | ...  Set Variable  /redfish/v1/UpdateService/FirmwareInventory/${nonfunctional_sw_inv['image_id']} | 
| Sushil Singh | 41540ea | 2021-01-07 06:59:17 -0600 | [diff] [blame] | 243 |  | 
|  | 244 | # Below URI, change to backup image and reset the BMC. | 
|  | 245 | Redfish.Patch  /redfish/v1/Managers/bmc | 
|  | 246 | ...  body={'Links': {'ActiveSoftwareImage': {'@odata.id': '${firmware_inv_path}'}}} | 
|  | 247 |  |