1*** Settings ***
2Documentation            Update the BMC code on a target BMC via Redifsh.
3
4# Test Parameters:
5# IMAGE_FILE_PATH        The path to the BMC image file.
6#
7# Firmware update states:
8#     Enabled            Image is installed and either functional or active.
9#     Disabled           Image installation failed or ready for activation.
10#     Updating           Image installation currently in progress.
11
12Resource                 ../../lib/resource.robot
13Resource                 ../../lib/bmc_redfish_resource.robot
14Resource                 ../../lib/openbmc_ffdc.robot
15Resource                 ../../lib/common_utils.robot
16Resource                 ../../lib/code_update_utils.robot
17Resource                 ../../lib/redfish_code_update_utils.robot
18Resource                 ../../lib/utils.robot
19Library                  ../../lib/gen_robot_valid.py
20Library                  ../../lib/var_funcs.py
21Library                  ../../lib/gen_robot_keyword.py
22Library                  ../../lib/code_update_utils.py
23
24Suite Setup              Suite Setup Execution
25Suite Teardown           Redfish.Logout
26Test Setup               Printn
27Test Teardown            FFDC On Test Case Fail
28
29# Force the test to timedout to prevent test hanging.
30Test Timeout             30 minutes
31
32*** Test Cases ***
33
34Redfish Host Code Update
35    [Documentation]  Update the firmware image.
36    [Tags]  Redfish_Host_Code_Update
37
38    ${image_version}=  Get Version Tar  ${IMAGE_FILE_PATH}
39    Rprint Vars  image_version
40
41    ${sw_inv}=  Get Functional Firmware  Host image
42    ${functional_sw_inv}=  Get Non Functional Firmware  ${sw_inv}  True
43
44    ${num_records}=  Get Length  ${functional_sw_inv}
45
46    Run Keyword If  ${num_records} != 0  Pass Execution If  '${functional_sw_inv['version']}' == '${image_version}'
47    ...  The existing ${image_version} firmware is already functional.
48
49    ${post_code_update_actions}=  Get Post Boot Action
50    ${state}=  Get Pre Reboot State
51    Rprint Vars  state
52
53   Print Timen  Performing firmware update ${image_version}.
54
55   Redfish Update Firmware
56
57
58*** Keywords ***
59
60Suite Setup Execution
61    [Documentation]  Do the suite setup.
62
63    Redfish.Login
64    # Delete BMC dump and Error logs.
65    Run Keyword And Ignore Error  Redfish Delete All BMC Dumps
66    Run Keyword And Ignore Error  Redfish Purge Event Log
67    # Checking for file existence.
68    Valid File Path  IMAGE_FILE_PATH
69
70
71Redfish Update Firmware
72    [Documentation]  Update the BMC firmware via redfish interface.
73
74    Redfish.Login
75    ${post_code_update_actions}=  Get Post Boot Action
76    Rprint Vars  post_code_update_actions
77    Run Keyword And Ignore Error  Set ApplyTime  policy=OnReset
78    Redfish Upload Image And Check Progress State
79    ${tar_version}=  Get Version Tar  ${IMAGE_FILE_PATH}
80    ${image_info}=  Get Software Inventory State By Version  ${tar_version}
81    Run Key  ${post_code_update_actions['${image_info["image_type"]}']['OnReset']}
82    Redfish.Login
83    Redfish Verify Host Version  ${IMAGE_FILE_PATH}
84
85