blob: 17ffbe0ec8fb077de51c3d5fa73e7091829e07fd [file] [log] [blame]
George Keishing72abe822019-07-29 08:03:40 -05001*** Settings ***
2Documentation Redfish BMC and PNOR software utilities keywords.
3
4Library code_update_utils.py
5Library gen_robot_valid.py
Sushil Singh87dcee12019-08-07 13:13:13 -05006Library tftp_update_utils.py
George Keishing72abe822019-07-29 08:03:40 -05007Resource bmc_redfish_utils.robot
Sushil Singh32e2b582019-08-16 04:58:24 -05008Resource boot_utils.robot
George Keishing72abe822019-07-29 08:03:40 -05009
10*** Keywords ***
11
12Get 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
Sushil Singh89a26542022-02-17 10:08:31 -060019 ${resp}= Redfish.Get /redfish/v1/UpdateService/FirmwareInventory/${image_id}
20 ... valid_status_codes=[${HTTP_OK}, ${HTTP_INTERNAL_SERVER_ERROR}]
21 ${image_info} Set Variable ${resp.dict}
George Keishing33be3592022-03-08 08:52:25 -060022
Sushil Singh8469a482020-07-30 04:19:10 -050023 ${sw_functional}= Run Keyword If
24 ... '${image_info["Description"]}' == 'BMC image' or '${image_info["Description"]}' == 'BMC update'
George Keishing72abe822019-07-29 08:03:40 -050025 ... Redfish.Get Attribute /redfish/v1/Managers/bmc FirmwareVersion
26 ... ELSE
27 ... Redfish.Get Attribute /redfish/v1/Systems/system BiosVersion
28
29 ${functional}= Run Keyword And Return Status
30 ... Should Be Equal ${sw_functional} ${image_info["Version"]}
31
George Keishingfb33edf2022-07-14 04:39:22 -050032 # If they are not same, return from here.
33 Return From Keyword If '${functional}' == 'False' ${functional}
34
35 # WHen the functional and backup firmware versions are same, this ensure, we rightly set the
36 # test inventory dictionary for the firmware functional status.
37 Run Keyword If
38 ... '${image_info["Description"]}' == 'BMC image' or '${image_info["Description"]}' == 'BMC update'
39 ... Run Keyword And Return Find Active Software Image ${image_id}
40
George Keishing72abe822019-07-29 08:03:40 -050041 [Return] ${functional}
42
43
George Keishingfb33edf2022-07-14 04:39:22 -050044Find Active Software Image
45 [Documentation] Match the firmware id of ActiveSoftwareImage attribute with the input id.
46 ... The ActiveSoftwareImage id is the current functional BMC firmware.
47 [Arguments] ${image_id}
48
49 # Description of argument(s):
50 # image_id The image ID (e.g. "acc9e073").
51
52 # This attribute tells which is the firmware version currently functional.
53 # "ActiveSoftwareImage": {
54 # "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/5ca9fec0"
55 # },
56 ${active_sw_img}= Redfish.Get Attribute /redfish/v1/Managers/bmc Links
57
58 ${active_id}= Set Variable ${active_sw_img["ActiveSoftwareImage"]["@odata.id"].split("/")[-1]}
59
60 ${matched_functional}= Run Keyword And Return Status
61 ... Should Be Equal As Strings ${image_id} ${active_id}
62
63 # Returns True if matched else False.
64 [Return] ${matched_functional}
65
66
George Keishing72abe822019-07-29 08:03:40 -050067Get Software Inventory State
68 [Documentation] Return dictionary of the image type, version and functional state
69 ... of the software objects active on the system.
70
71 # User defined state for software objects.
72 # Note: "Functional" term refers to firmware which system is currently booted with.
73 # sw_inv_dict:
74 # [ace821ef]:
75 # [image_type]: Host update
George Keishing31029492019-07-30 13:14:13 -050076 # [image_id]: ace821ef
George Keishing72abe822019-07-29 08:03:40 -050077 # [functional]: True
78 # [version]: witherspoon-xx.xx.xx.xx
79 # [b9101858]:
80 # [image_type]: BMC update
George Keishing31029492019-07-30 13:14:13 -050081 # [image_id]: b9101858
George Keishing72abe822019-07-29 08:03:40 -050082 # [functional]: True
83 # [version]: 2.8.0-dev-150-g04508dc9f
84 # [c45eafa5]:
85 # [image_type]: BMC update
George Keishing31029492019-07-30 13:14:13 -050086 # [image_id]: c45eafa5
George Keishing72abe822019-07-29 08:03:40 -050087 # [functional]: False
88 # [version]: 2.8.0-dev-149-g1a8df5077
89
90 ${sw_member_list}= Redfish_Utils.Get Member List /redfish/v1/UpdateService/FirmwareInventory
91 &{sw_inv_dict}= Create Dictionary
92
93 # sw_member_list:
94 # [0]: /redfish/v1/UpdateService/FirmwareInventory/98744d76
95 # [1]: /redfish/v1/UpdateService/FirmwareInventory/9a8028ec
96 # [2]: /redfish/v1/UpdateService/FirmwareInventory/acc9e073
97
98 FOR ${uri_path} IN @{sw_member_list}
99 &{tmp_dict}= Create Dictionary
Sushil Singh89a26542022-02-17 10:08:31 -0600100
101 ${resp}= Redfish.Get ${uri_path} valid_status_codes=[${HTTP_OK}, ${HTTP_INTERNAL_SERVER_ERROR}]
102 ${image_info} Set Variable ${resp.dict}
103
George Keishing72abe822019-07-29 08:03:40 -0500104 Set To Dictionary ${tmp_dict} image_type ${image_info["Description"]}
George Keishing31029492019-07-30 13:14:13 -0500105 Set To Dictionary ${tmp_dict} image_id ${uri_path.split("/")[-1]}
Sushil Singh89a26542022-02-17 10:08:31 -0600106
George Keishing72abe822019-07-29 08:03:40 -0500107 ${functional}= Get Software Functional State ${uri_path.split("/")[-1]}
Sushil Singh89a26542022-02-17 10:08:31 -0600108
George Keishing72abe822019-07-29 08:03:40 -0500109 Set To Dictionary ${tmp_dict} functional ${functional}
George Keishing72abe822019-07-29 08:03:40 -0500110 Set To Dictionary ${tmp_dict} version ${image_info["Version"]}
George Keishing31029492019-07-30 13:14:13 -0500111 Set To Dictionary ${sw_inv_dict} ${uri_path.split("/")[-1]} ${tmp_dict}
George Keishing72abe822019-07-29 08:03:40 -0500112 END
113
114 [Return] &{sw_inv_dict}
George Keishing31029492019-07-30 13:14:13 -0500115
116
117Get Software Inventory State By Version
118 [Documentation] Return the software inventory record that matches the given software version.
119 [Arguments] ${software_version}
120
121 # If no matchine record can be found, return ${EMPTY}.
122
123 # Example of returned data:
124 # software_inventory_record:
125 # [image_type]: BMC update
126 # [image_id]: 1e662ba8
127 # [functional]: True
128 # [version]: 2.8.0-dev-150-g04508dc9f
129
130 # Description of argument(s):
131 # software_version A BMC or Host version (e.g "2.8.0-dev-150-g04508dc9f").
132
133 ${software_inventory}= Get Software Inventory State
134 # Filter out entries that don't match the criterion..
135 ${software_inventory}= Filter Struct ${software_inventory} [('version', '${software_version}')]
136 # Convert from dictionary to list.
137 ${software_inventory}= Get Dictionary Values ${software_inventory}
138 ${num_records}= Get Length ${software_inventory}
139
140 Return From Keyword If ${num_records} == ${0} ${EMPTY}
141
142 # Return the first list entry.
143 [Return] ${software_inventory}[0]
Sushil Singh87dcee12019-08-07 13:13:13 -0500144
145
Sushil Singhb2150da2020-12-07 07:05:42 -0600146Get BMC Functional Firmware
147 [Documentation] Get BMC functional firmware details.
148
149 ${sw_inv}= Get Functional Firmware BMC update
150 ${sw_inv}= Get Non Functional Firmware ${sw_inv} True
151
152 [Return] ${sw_inv}
153
154
155Get Functional Firmware
156 [Documentation] Get all the BMC firmware details.
157 [Arguments] ${image_type}
158
159 # Description of argument(s):
160 # image_type Image value can be either BMC update or Host update.
161
162 ${software_inventory}= Get Software Inventory State
163 ${bmc_inv}= Get BMC Firmware ${image_type} ${software_inventory}
164
165 [Return] ${bmc_inv}
166
167
168Get Non Functional Firmware
George Keishing16b3c7b2021-01-28 09:23:37 -0600169 [Documentation] Get BMC non functional firmware details.
Sushil Singh41540ea2021-01-07 06:59:17 -0600170 [Arguments] ${sw_inv} ${functional_state}
Sushil Singhb2150da2020-12-07 07:05:42 -0600171
172 # Description of argument(s):
George Keishing16b3c7b2021-01-28 09:23:37 -0600173 # sw_inv This dictionary contains all the BMC firmware details.
Sushil Singh41540ea2021-01-07 06:59:17 -0600174 # functional_state Functional state can be either True or False.
Sushil Singhb2150da2020-12-07 07:05:42 -0600175
Sushil Singh41540ea2021-01-07 06:59:17 -0600176 ${resp}= Filter Struct ${sw_inv} [('functional', ${functional_state})]
Sushil Singh3b6f9162021-05-20 06:47:47 -0500177
178 ${num_records}= Get Length ${resp}
179 Set Global Variable ${num_records}
180 Return From Keyword If ${num_records} == ${0} ${EMPTY}
181
Sushil Singhb2150da2020-12-07 07:05:42 -0600182 ${list_inv_dict}= Get Dictionary Values ${resp}
183
184 [Return] ${list_inv_dict}[0]
185
186
Sushil Singh50a1be92021-06-15 06:52:36 -0500187Get Non Functional Firmware List
188 [Documentation] Get BMC non functional firmware details.
189 [Arguments] ${sw_inv} ${functional_state}
190
191 # Description of argument(s):
192 # sw_inv This dictionary contains all the BMC firmware details.
193 # functional_state Functional state can be either True or False.
194
195 ${list_inv}= Create List
196
197 FOR ${key} IN @{sw_inv.keys()}
198 Run Keyword If '${sw_inv['${key}']['functional']}' == '${functional_state}'
199 ... Append To List ${list_inv} ${sw_inv['${key}']}
200 END
201
202 [Return] ${list_inv}
203
204
Sushil Singh87dcee12019-08-07 13:13:13 -0500205Redfish Upload Image And Check Progress State
206 [Documentation] Code update with ApplyTime.
Sushil Singh87dcee12019-08-07 13:13:13 -0500207
George Keishinge25113a2021-06-18 13:50:43 -0500208 Log To Console Start uploading image to BMC.
Sushil Singh87dcee12019-08-07 13:13:13 -0500209 Redfish Upload Image ${REDFISH_BASE_URI}UpdateService ${IMAGE_FILE_PATH}
George Keishinge25113a2021-06-18 13:50:43 -0500210 Log To Console Completed image upload to BMC.
Sushil Singh87dcee12019-08-07 13:13:13 -0500211
212 ${image_id}= Get Latest Image ID
213 Rprint Vars image_id
214
George Keishingfd32e332021-09-17 02:20:32 -0500215 # We have noticed firmware inventory state Enabled quickly as soon the image
216 # is uploaded via redfish.
George Keishingcbf55b12021-09-29 23:33:15 -0500217 Wait Until Keyword Succeeds 2 min 05 sec
George Keishingfd32e332021-09-17 02:20:32 -0500218 ... Check Image Update Progress State match_state='Disabled', 'Updating', 'Enabled' image_id=${image_id}
Sushil Singh8469a482020-07-30 04:19:10 -0500219
George Keishinge25113a2021-06-18 13:50:43 -0500220 Wait Until Keyword Succeeds 8 min 10 sec
Sushil Singh87dcee12019-08-07 13:13:13 -0500221 ... Check Image Update Progress State
222 ... match_state='Enabled' image_id=${image_id}
223
224
Sushil Singh32e2b582019-08-16 04:58:24 -0500225Get Host Power State
226 [Documentation] Get host power state.
227 [Arguments] ${quiet}=0
228
229 # Description of arguments:
230 # quiet Indicates whether results should be printed.
231
232 ${state}= Redfish.Get Attribute
233 ... ${REDFISH_BASE_URI}Systems/system PowerState
234 Rqprint Vars state
235
236 [Return] ${state}
237
238
239Check Host Power State
240 [Documentation] Check that the machine's host state matches
241 ... the caller's required host state.
242 [Arguments] ${match_state}
243
244 # Description of argument(s):
245 # match_state The expected state. This may be one or more
246 # comma-separated values (e.g. "On", "Off").
247 # If the actual state matches any of the
248 # states named in this argument,
249 # this keyword passes.
250
251 ${state}= Get Host Power State
252 Rvalid Value state valid_values=[${match_state}]
253
Sushil Singhf17a7f62020-02-03 01:09:30 -0600254
255Get System Firmware Details
256 [Documentation] Return dictionary of system firmware details.
257
258 # {
259 # FirmwareVersion: 2.8.0-dev-1067-gdc66ce1c5,
260 # BiosVersion: witherspoon-XXX-XX.X-X
261 # }
262
263 ${firmware_version}= Redfish Get BMC Version
264 ${bios_version}= Redfish Get Host Version
265
266 &{sys_firmware_dict}= Create Dictionary
267 Set To Dictionary
268 ... ${sys_firmware_dict} FirmwareVersion ${firmware_version} BiosVersion ${bios_version}
269 Rprint Vars sys_firmware_dict
270
271 [Return] &{sys_firmware_dict}
272
Sushil Singh41540ea2021-01-07 06:59:17 -0600273
274Switch Backup Firmware Image To Functional
275 [Documentation] Switch the backup firmware image to make functional.
276
277 ${sw_inv}= Get Functional Firmware BMC image
278 ${nonfunctional_sw_inv}= Get Non Functional Firmware ${sw_inv} False
279
George Keishingf9248952021-05-28 07:52:37 -0500280 ${firmware_inv_path}=
281 ... Set Variable /redfish/v1/UpdateService/FirmwareInventory/${nonfunctional_sw_inv['image_id']}
Sushil Singh41540ea2021-01-07 06:59:17 -0600282
283 # Below URI, change to backup image and reset the BMC.
284 Redfish.Patch /redfish/v1/Managers/bmc
285 ... body={'Links': {'ActiveSoftwareImage': {'@odata.id': '${firmware_inv_path}'}}}
286