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
22
23Suite Setup              Suite Setup Execution
24Suite Teardown           Redfish.Logout
25Test Setup               Printn
26Test Teardown            FFDC On Test Case Fail
27
28Force Tags               BMC_Code_Update
29
30*** Variables ***
31
32${FORCE_UPDATE}          ${0}
33
34
35*** Test Cases ***
36
37Redfish BMC Code Update
38    [Documentation]  Update the firmware image.
39    [Tags]  Redfish_BMC_Code_Update
40
41    ${image_version}=  Get Version Tar  ${IMAGE_FILE_PATH}
42    Rprint Vars  image_version
43
44    Run Keyword If  not ${FORCE_UPDATE}
45    ...  Activate Existing Firmware  ${image_version}
46    Redfish Update Firmware
47
48*** Keywords ***
49
50Suite Setup Execution
51    [Documentation]  Do the suite setup.
52
53    Redfish.Login
54    # Delete BMC dump and Error logs.
55    Delete All BMC Dump
56    Redfish Purge Event Log
57    # Checking for file existence.
58    Valid File Path  IMAGE_FILE_PATH
59
60Activate Existing Firmware
61    [Documentation]  Set fimware image to lower priority.
62    [Arguments]  ${image_version}
63
64    # Description of argument(s):
65    # image_version     Version of image.
66
67    ${software_inventory_record}=  Get Software Inventory State By Version
68    ...  ${image_version}
69    ${num_keys}=  Get Length  ${software_inventory_record}
70
71    Rprint Vars  software_inventory_record
72
73    # If no software inventory record was found, there is no existing
74    # firmware for the given version and therefore no action to be taken.
75    Return From Keyword If  not ${num_keys}
76
77    # Check if the existing firmware is functional.
78    Pass Execution If  ${software_inventory_record['functional']}
79    ...  The existing ${image_version} firmware is already functional.
80
81    # If existing firmware is not functional, then set the priority to least.
82    Print Timen  The existing ${image_version} firmware is not yet functional.
83    Set BMC Image Priority To Least  ${image_version}  ${software_inventory_record}
84
85    Pass Execution  The existing ${image_version} firmware is now functional.
86
87
88Get Image Priority
89    [Documentation]  Get Current Image Priority.
90    [Arguments]  ${image_version}
91
92    # Description of argument(s):
93    # image_version       The Fimware image version (e.g. 2.8.0-dev-1107-g512028d95).
94
95    ${software_info}=  Read Properties
96    ...  ${SOFTWARE_VERSION_URI}/enumerate  quiet=1
97    # Get only the record associated with our image_version.
98
99    ${software_info}=  Filter Struct
100    ...  ${software_info}  [('Version', '${image_version}')]
101    # Convert from dict to list.
102    ${software_info}=  Get Dictionary Values  ${software_info}
103
104    [Return]  ${software_info[0]['Priority']}
105
106
107Set BMC Image Priority To Least
108    [Documentation]  Set BMC image priority to least value.
109    [Arguments]  ${image_version}  ${software_inventory}
110
111    # Description of argument(s):
112    # image_version       The Fimware image version (e.g. 2.8.0-dev-1107-g512028d95).
113    # software_inventory  Software inventory details.
114
115    ${least_priority}=  Get Least Value Priority Image  ${VERSION_PURPOSE_BMC}
116    ${cur_priority}=  Get Image Priority  ${image_version}
117    Rprint Vars  least_priority  cur_priority
118
119    Return From Keyword If  '${least_priority}' == ${cur_priority}
120    Set Host Software Property
121    ...  ${SOFTWARE_VERSION_URI}${software_inventory['image_id']}
122    ...  Priority  ${least_priority}
123
124    # Reboot BMC And Login
125    Redfish OBMC Reboot (off)
126    Redfish.Login
127
128
129Redfish Update Firmware
130    [Documentation]  Update the BMC firmware via redfish interface.
131
132    ${post_code_update_actions}=  Get Post Boot Action
133    ${state}=  Get Pre Reboot State
134    Rprint Vars  state
135    Run Keyword And Ignore Error  Set ApplyTime  policy=OnReset
136    Redfish Upload Image And Check Progress State
137    ${tar_version}=  Get Version Tar  ${IMAGE_FILE_PATH}
138    ${image_info}=  Get Software Inventory State By Version  ${tar_version}
139    Run Key  ${post_code_update_actions['${image_info["image_type"]}']['OnReset']}
140    Redfish.Login
141    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
142
143