1*** Settings ***
2Documentation    Verify that Redfish software inventory can be collected.
3
4Resource         ../../lib/resource.robot
5Resource         ../../lib/bmc_redfish_resource.robot
6Resource         ../../lib/openbmc_ffdc.robot
7Resource         ../../lib/redfish_code_update_utils.robot
8Library          ../../lib/gen_robot_valid.py
9
10Test Setup       Test Setup Execution
11Test Teardown    Test Teardown Execution
12
13Force Tags     Firmware_Inventory
14
15*** Test Cases ***
16
17Verify Redfish Update Service Enabled
18    [Documentation]  Verify "ServiceEnabled" is enabled.
19    [Tags]  Verify_Redfish_Update_Service_Enabled
20
21    # Example:
22    # "HttpPushUri": "/redfish/v1/UpdateService",
23    # "Id": "UpdateService",
24    # "Name": "Update Service",
25    # "ServiceEnabled": true
26
27    ${resp}=  Redfish.Get  /redfish/v1/UpdateService
28    Should Be Equal As Strings  ${resp.dict["ServiceEnabled"]}  ${True}
29
30
31Verify Redfish Software Inventory Collection
32    [Documentation]  Verify software inventory collection member and object entries.
33    [Tags]  Verify_Redfish_Software_Inventory_Collection
34
35    # Example:
36    # {
37    #    "@odata.type": "#SoftwareInventoryCollection.SoftwareInventoryCollection",
38    #    "Members": [
39    #      {
40    #        "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/a3522998"
41    #      },
42    #      {
43    #        "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/a7c79f71"
44    #      },
45    #      {
46    #        "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/ace821ef"
47    #      }
48    #   ],
49    #   "Members@odata.count": 3,
50    #   "Name": "Software Inventory Collection"
51    # }
52
53    ${resp}=  Redfish.Get  /redfish/v1/UpdateService/FirmwareInventory
54
55    Should Be True  ${resp.dict["Members@odata.count"]} >= ${1}
56    Length Should Be  ${resp.dict["Members"]}  ${resp.dict["Members@odata.count"]}
57
58
59Redfish Software Inventory Status Check
60    [Documentation]  Get firmware inventory entries and do health check status.
61    [Tags]  Redfish_Software_Inventory_Status_Check
62
63    ${resp}=  Redfish.Get  /redfish/v1/UpdateService/FirmwareInventory
64
65    # Entries "Members@odata.count": 3,
66    # {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/a3522998'}
67    # {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/a7c79f71'}
68    # {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/ace821ef'}
69
70    FOR  ${entry}  IN RANGE  0  ${resp.dict["Members@odata.count"]}
71      ${resp_resource}=  Redfish.Get  ${resp.dict["Members"][${entry}]["@odata.id"]}
72    # Example:
73    # "Status": {
74    #     "Health": "OK",
75    #     "HealthRollup": "OK",
76    #     "State": "Enabled"
77    # },
78      Should Be Equal As Strings  ${resp_resource.dict["Status"]["Health"]}  OK
79      Should Be Equal As Strings  ${resp_resource.dict["Status"]["HealthRollup"]}  OK
80      Should Be Equal As Strings  ${resp_resource.dict["Status"]["State"]}  Enabled
81    END
82
83
84Verify BMC Version Matches With FirmwareInventory
85    [Documentation]  Verify BMC version from FirmwareInventory same as in manager.
86    [Tags]  Verify_BMC_Version_Matches_With_FirmwareInventory
87
88    ${bmc_manager}=  Redfish.Get  /redfish/v1/Managers/bmc
89    ${manager_bmc_version}=  Get BMC Version
90    # Check for manager version and cat /etc/os-release.
91    Should Be Equal As Strings
92    ...  ${bmc_manager.dict["FirmwareVersion"]}  ${manager_bmc_version.strip('"')}
93
94    ${resp}=  Redfish.Get  /redfish/v1/UpdateService/FirmwareInventory
95
96    # Entries "Members@odata.count": 3,
97    # {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/a3522998'}
98    # {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/a7c79f71'}
99    # {'@odata.id': '/redfish/v1/UpdateService/FirmwareInventory/ace821ef'}
100
101    ${actual_count}=  Evaluate  ${resp.dict["Members@odata.count"]}-1
102    FOR  ${entry}  IN RANGE  0  ${resp.dict["Members@odata.count"]}
103      ${resp_resource}=  Redfish.Get  ${resp.dict["Members"][${entry}]["@odata.id"]}
104    # 3rd comparison of BMC version and verify FirmwareInventory bmc version.
105    # Example:
106    # "Version": 2.7.0-dev-19-g9b44ea7
107      Exit For Loop If  '${resp_resource.dict["Version"]}' == '${manager_bmc_version.strip('"')}'
108      Run Keyword If  '${entry}' == '${actual_count}'  Fail  BMC version not there in Firmware Inventory
109    END
110
111
112Verify UpdateService Supports TransferProtocol TFTP
113    [Documentation]  Verify update service supported values have TFTP protocol.
114    [Tags]  Verify_UpdateService_Supports_TransferProtocol_TFTP
115
116    # Example:
117    #   "Actions": {
118    #     "#UpdateService.SimpleUpdate": {
119    #       "TransferProtocol@Redfish.AllowableValues": [
120    #         "TFTP"
121    #       ],
122    #       "target": "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate"
123    #     }
124    #  },
125
126    ${allowable_values}=  Redfish.Get Attribute  /redfish/v1/UpdateService  Actions
127
128    Valid Value
129    ...  allowable_values["#UpdateService.SimpleUpdate"]["TransferProtocol@Redfish.AllowableValues"][0]
130    ...  valid_values=['TFTP']
131    Valid Value  allowable_values["#UpdateService.SimpleUpdate"]["target"]
132    ...  valid_values=['/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate']
133
134
135Verify Redfish Software Hex ID
136    [Documentation]  Verify BMC images have valid 8-digit hex IDs.
137    [Tags]  Verify_Redfish_Software_Hex_ID
138
139    ${sw_inv_dict}=  Get Software Inventory State
140
141    FOR  ${id_key}  IN  @{sw_inv_dict}
142      ${sw_inv}=  Get From Dictionary  ${sw_inv_dict}  ${id_key}
143      Should Be Equal As Strings  ${id_key}  ${sw_inv['image_id']}
144      Length Should Be  ${sw_inv['image_id']}  ${8}
145      Should Match Regexp  ${sw_inv['image_id']}  [0-9a-f]*
146    END
147
148
149Verify Redfish FirmwareInventory Is Updateable
150    [Documentation]  Verify the redfish firmware inventory path is updateable.
151    [Tags]  Verify_Redfish_FirmwareInventory_Is_Updateable
152
153    ${sw_member_list}=  Redfish_Utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory
154
155    # sw_member_list:
156    #   [0]:                            /redfish/v1/UpdateService/FirmwareInventory/98744d76
157    #   [1]:                            /redfish/v1/UpdateService/FirmwareInventory/9a8028ec
158    #   [2]:                            /redfish/v1/UpdateService/FirmwareInventory/acc9e073
159
160    FOR  ${sw_member}  IN  @{sw_member_list}
161      ${resp}=  Redfish.Get Attribute  ${sw_member}  Updateable
162
163      # Example:
164      # "Updateable": true,
165
166      Should Be Equal As Strings  ${resp}  True
167    END
168
169
170Check Redfish Functional Image Version Is Same
171    [Documentation]  Verify functional image version is same as in Redfish managers.
172    [Tags]  Check_Redfish_Functional_Image_Version_Is_Same
173    [Template]  Verify Redfish Functional Image Version Is Same
174
175    # image
176    functional_image
177    backup_image
178
179
180Check Redfish Backup Image Version Is Same
181    [Documentation]  Switch to backup image and then verify functional image version
182    ...  is same as in Redfish managers..
183    [Tags]  Check_Redfish_Backup_Image_Version_Is_Same
184    [Template]  Verify Redfish Functional Image Version Is Same
185
186    # image
187    switch_backup_image
188
189
190Verify Redfish Software Image And Firmware Inventory Are Same
191    [Documentation]  Verify the firmware software inventory is same as software images of managers.
192    [Tags]  Verify_Redfish_Software_Image_And_Firmware_Inventory_Are_Same
193
194    # SoftwareImages
195    # /redfish/v1/UpdateService/FirmwareInventory/632c5114
196    # /redfish/v1/UpdateService/FirmwareInventory/e702a011
197
198    ${firmware_inv_path}=  Redfish.Get Properties  ${REDFISH_BASE_URI}Managers/bmc
199    ${firmware_inv_path}=  Get From Dictionary  ${firmware_inv_path}  Links
200    ${sw_image}=  Get From Dictionary  ${firmware_inv_path}  SoftwareImages
201
202    ${sw_member_list}=  Redfish_Utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory
203
204    FOR  ${sw_inv_path}  IN  @{sw_image}
205      List Should Contain Value  ${sw_member_list}  ${sw_inv_path['@odata.id']}
206    END
207
208    ${num_records_sw_image}=  Get Length  ${sw_image}
209    ${num_records_sw_inv}=  Get Length  ${sw_member_list}
210    Should Be Equal  ${num_records_sw_image}  ${num_records_sw_inv}
211
212
213Check If Firmware Image Is Same In Firmware Inventory And Redfish Read Operation
214    [Documentation]  Check the Redfish firmware inventory path is same as in
215    ...  active software image of Redfish managers and firmware inventory of update service.
216    [Tags]  Check_If_Firmware_Image_Is_Same_In_Firmware_Inventory_And_Redfish_Read_Operation
217
218    Verify Active Software Image And Firmware Inventory Is Same
219
220
221Check If Backup Firmware Image Is Same In Firmware Inventory And Redfish Read Operation
222    [Documentation]  Check the Redfish backup image firmware inventory path is same as in
223    ...  active software image of Redfish managers and firmware inventory of update service.
224    [Tags]  Check_If_Backup_Firmware_Image_Is_Same_In_Firmware_Inventory_And_Redfish_Read_Operation
225
226    Verify Active Software Image And Firmware Inventory Is Same
227    Set Backup Firmware Image As Functional
228    Verify Active Software Image And Firmware Inventory Is Same
229    Set Backup Firmware Image As Functional
230    Verify Active Software Image And Firmware Inventory Is Same
231
232
233Verify Redfish BIOS Version
234    [Documentation]  Get host firmware version from system inventory.
235    [Tags]  Verify_Redfish_BIOS_Version
236
237    ${bios_version}=  Redfish.Get Attribute  /redfish/v1/Systems/system/  BiosVersion
238    ${pnor_version}=  Get PNOR Version
239    Should Be Equal  ${pnor_version}  ${bios_version}
240
241
242*** Keywords ***
243
244Test Setup Execution
245    [Documentation]  Do test case setup tasks.
246
247    Redfish.Login
248
249
250Test Teardown Execution
251    [Documentation]  Do the post test teardown.
252
253    FFDC On Test Case Fail
254    Redfish.Logout
255
256
257Verify Firmware Version Same In Firmware Inventory And Managers
258    [Documentation]  Verify the Redfish firmware inventory path version is same as Redfish managers.
259
260    # User defined state for software objects.
261    # Note: "Functional" term refers to firmware which system is currently booted with.
262
263    # sw_inv_dict:
264    #   [b9101858]:
265    #     [image_type]:                 BMC update
266    #     [image_id]:                   b9101858
267    #     [functional]:                 True
268    #     [version]:                    2.8.0-dev-150-g04508dc9f
269
270    ${sw_inv_list}=  Get Functional Firmware  BMC image
271    ${sw_inv_dict}=  Get Non Functional Firmware  ${sw_inv_list}  True
272
273    # /redfish/v1/Managers/bmc
274    # "FirmwareVersion": "2.8.0-dev-150-g04508dc9f"
275
276    ${firmware_version}=  Redfish.Get Attribute
277    ...  ${REDFISH_BASE_URI}Managers/bmc  FirmwareVersion
278
279    Should Be Equal  ${sw_inv_dict['version']}  ${firmware_version}
280
281
282Verify Firmware Version Is Not Same In Firmware Inventory And Managers
283    [Documentation]  Verify the Redfish firmware inventory path version is not same as
284    ...  Redfish managers for backup image.
285
286    # User defined state for software objects.
287    # Note: "Functional" term refers to firmware which system is currently booted with.
288
289    # sw_inv_dict:
290    #   [b9101858]:
291    #     [image_type]:                 BMC update
292    #     [image_id]:                   b9101858
293    #     [functional]:                 True
294    #     [version]:                    2.8.0-dev-150-g04508dc9f
295
296    ${sw_inv_list}=  Get Functional Firmware  BMC image
297    ${sw_inv_list}=  Get Non Functional Firmware List  ${sw_inv_list}  False
298
299    # /redfish/v1/Managers/bmc
300    # "FirmwareVersion": "2.8.0-dev-150-g04508dc9f"
301
302    ${firmware_version}=  Redfish.Get Attribute
303    ...  ${REDFISH_BASE_URI}Managers/bmc  FirmwareVersion
304
305    FOR  ${sw_inv}  IN  @{sw_inv_list}
306      Should Not Be Equal  ${sw_inv['version']}  ${firmware_version}
307    END
308
309
310Set Backup Firmware Image As Functional
311    [Documentation]  Switch to the backup firmware image to make functional.
312
313    ${state}=  Get Pre Reboot State
314    Rprint Vars  state
315
316    Switch Backup Firmware Image To Functional
317    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
318
319
320Verify Redfish Functional Image Version Is Same
321    [Documentation]  Verify the functional image version is same as in firmware inventory and managers.
322    [Arguments]  ${image}
323
324    # Description of argument(s):
325    # image           Functional Image or Backup Image
326
327    Verify Firmware Version Same In Firmware Inventory And Managers
328
329    Run Keyword If  'backup_image' == '${image}'
330    ...  Verify Firmware Version Is Not Same In Firmware Inventory And Managers
331
332    Run Keyword If  'switch_backup_image' == '${image}'
333    ...  Run Keywords  Set Backup Firmware Image As Functional  AND
334    ...    Verify Firmware Version Same In Firmware Inventory And Managers  AND
335    ...    Set Backup Firmware Image As Functional  AND
336    ...    Verify Firmware Version Same In Firmware Inventory And Managers
337
338
339Verify Active Software Image And Firmware Inventory Is Same
340    [Documentation]  Verify Redfish firmware inventory path and active software image is same.
341
342    # ActiveSoftwareImage
343    # /redfish/v1/UpdateService/FirmwareInventory/632c5114
344
345    # Firmware Inventory
346    # /redfish/v1/UpdateService/FirmwareInventory
347    # /redfish/v1/UpdateService/FirmwareInventory/632c5114
348    # /redfish/v1/UpdateService/FirmwareInventory/632c5444
349
350    ${firmware_inv_path}=  Redfish.Get Properties  ${REDFISH_BASE_URI}Managers/bmc
351    ${firmware_inv_path}=  Get From Dictionary  ${firmware_inv_path}  Links
352    ${active_sw_image}=  Get From Dictionary  ${firmware_inv_path}  ActiveSoftwareImage
353    ${active_sw_image}=  Get From Dictionary  ${active_sw_image}  @odata.id
354
355    ${sw_member_list}=  Redfish_Utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory
356    List Should Contain Value  ${sw_member_list}  ${active_sw_image}
357