1*** Settings ***
2Documentation            Update firmware 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/dump_utils.robot
18Resource                 ../../lib/logging_utils.robot
19Resource                 ../../lib/redfish_code_update_utils.robot
20Resource                 ../../lib/utils.robot
21Resource                 ../../lib/bmc_redfish_utils.robot
22Resource                 ../../lib/external_intf/management_console_utils.robot
23Library                  ../../lib/gen_robot_valid.py
24Library                  ../../lib/tftp_update_utils.py
25Library                  ../../lib/gen_robot_keyword.py
26
27Suite Setup              Suite Setup Execution
28Suite Teardown           Redfish.Logout
29Test Setup               Printn
30Test Teardown            FFDC On Test Case Fail
31
32Force Tags               BMC_Code_Update
33
34*** Variables ***
35
36@{ADMIN}          admin_user  TestPwd123
37&{USERS}          Administrator=${ADMIN}
38${LOOP_COUNT}     ${2}
39
40*** Test Cases ***
41
42Redfish Code Update With ApplyTime OnReset
43    [Documentation]  Update the firmware image with ApplyTime of OnReset.
44    [Tags]  Redfish_Code_Update_With_ApplyTime_OnReset
45    [Template]  Redfish Update Firmware
46
47    # policy
48    OnReset
49
50
51Redfish Code Update With ApplyTime Immediate
52    [Documentation]  Update the firmware image with ApplyTime of Immediate.
53    [Tags]  Redfish_Code_Update_With_ApplyTime_Immediate
54    [Template]  Redfish Update Firmware
55
56    # policy
57    Immediate
58
59
60Redfish Code Update Same Firmware Multiple Times
61    [Documentation]  Multiple times update the firmware image for update service.
62    [Tags]  Redfish_Code_Update_Same_Firmware_Multiple_Times
63
64    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
65
66    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
67       Print Timen  **************************************
68       Print Timen  * The Current Loop Count is ${count} of ${LOOP_COUNT} *
69       Print Timen  **************************************
70
71       Redfish Update Firmware  apply_time=OnReset
72    END
73
74
75
76Redfish Code Update With Multiple Firmware
77    [Documentation]  Update the firmware image with ApplyTime of Immediate.
78    [Tags]  Redfish_Code_Update_With_Multiple_Firmware
79    [Template]  Redfish Multiple Upload Image And Check Progress State
80
81    # policy   image_file_path     alternate_image_file_path
82    Immediate  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
83
84
85Post BMC Reset Perform Redfish Code Update
86    [Documentation]  Test to reset BMC at standby and then perform BMC firmware update and
87    ...              ensure there is not error or dump logs post update.
88    [Tags]  Post_BMC_Reset_Perform_Redfish_Code_Update
89
90    Redfish Delete All BMC Dumps
91    Redfish Purge Event Log
92
93    Redfish OBMC Reboot (off)
94
95    Redfish Update Firmware  apply_time=OnReset
96
97    Event Log Should Not Exist
98    Redfish BMC Dump Should Not Exist
99
100    Redfish Power Off
101
102
103Post BMC Reset Perform Image Switched To Backup Multiple Times
104    [Documentation]  Test to reset BMC at standby and then perfrom switch to backup image multiple times.
105    ...              Then ensure no event and dump logs exist.
106    [Tags]  Post_BMC_Reset_Perform_Image_Switched_To_Backup_Multiple_Times
107
108    Redfish Delete All BMC Dumps
109    Redfish Purge Event Log
110
111    Redfish OBMC Reboot (off)
112
113    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
114
115    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
116      ${state}=  Get Pre Reboot State
117
118      # change to backup image and reset the BMC.
119      Switch Backup Firmware Image To Functional
120
121      Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
122    END
123
124    Event Log Should Not Exist
125    Redfish BMC Dump Should Not Exist
126
127
128Verify If The Modified Admin Credential Is Valid Post Image Switched To Backup
129    [Documentation]  Verify updated admin credential remain same post switch to back up image.
130    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Image_Switched_To_Backup
131    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
132    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
133
134    ${post_code_update_actions}=  Get Post Boot Action
135    ${state}=  Get Pre Reboot State
136    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
137
138    Redfish.Login
139    # change to backup image and reset the BMC.
140    Switch Backup Firmware Image To Functional
141    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
142
143    # verify modified admin password on backup image.
144    Redfish.Login  admin_user  0penBmc123
145    Redfish.Logout
146
147
148Verify If The Modified Admin Credential Is Valid Post Update
149    [Documentation]  Verify updated admin credential remain same post code update image.
150    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Update
151    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
152    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
153
154    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
155
156    Redfish.Login
157    # Flash latest firmware using redfish.
158    Redfish Update Firmware  OnReset
159
160    # verify modified admin credentails on latest image.
161    Redfish.Login  admin_user  0penBmc123
162    Redfish.Logout
163
164*** Keywords ***
165
166Suite Setup Execution
167    [Documentation]  Do the suite setup.
168
169    Valid File Path  IMAGE_FILE_PATH
170    Redfish.Login
171
172    Redfish Delete All BMC Dumps
173    Redfish Purge Event Log
174
175    Redfish Power Off  stack_mode=skip
176
177
178Redfish Update Firmware
179    [Documentation]  Update the BMC firmware via redfish interface.
180    [Arguments]  ${apply_time}
181
182    # Description of argument(s):
183    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
184
185    ${post_code_update_actions}=  Get Post Boot Action
186    ${state}=  Get Pre Reboot State
187    Rprint Vars  state
188    Set ApplyTime  policy=${apply_Time}
189
190    ${task_inv_dict}=  Get Task State from File
191
192    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
193
194    Log To Console   Start uploading image to BMC.
195    Upload Image To BMC  ${REDFISH_BASE_URI}UpdateService  timeout=${600}  data=${file_bin_data}
196    Log To Console   Completed image upload to BMC.
197
198    ${task_inv}=  Check Task With Match TargetUri  /redfish/v1/UpdateService
199
200    Rprint Vars  task_inv
201
202    Wait Until Keyword Succeeds  5 min  10 sec
203    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
204
205    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
206    Redfish.Login
207    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
208    Verify Get ApplyTime  ${apply_time}
209
210
211Redfish Multiple Upload Image And Check Progress State
212    [Documentation]  Update multiple BMC firmware via redfish interface and check status.
213    [Arguments]  ${apply_time}  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
214
215    # Description of argument(s):
216    # apply_time                 ApplyTime allowed values (e.g. "OnReset", "Immediate").
217    # IMAGE_FILE_PATH            The path to BMC image file.
218    # ALTERNATE_IMAGE_FILE_PATH  The path to alternate BMC image file.
219
220    ${post_code_update_actions}=  Get Post Boot Action
221    Valid File Path  ALTERNATE_IMAGE_FILE_PATH
222    ${state}=  Get Pre Reboot State
223    Rprint Vars  state
224
225    Set ApplyTime  policy=${apply_time}
226    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${IMAGE_FILE_PATH}
227
228    ${first_image_id}=  Get Latest Image ID
229    Rprint Vars  first_image_id
230    Sleep  5s
231    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${ALTERNATE_IMAGE_FILE_PATH}
232
233    ${second_image_id}=  Get Latest Image ID
234    Rprint Vars  second_image_id
235
236    Check Image Update Progress State
237    ...  match_state='Updating', 'Disabled'  image_id=${second_image_id}
238
239    Check Image Update Progress State
240    ...  match_state='Updating'  image_id=${first_image_id}
241
242    Wait Until Keyword Succeeds  8 min  20 sec
243    ...  Check Image Update Progress State
244    ...    match_state='Enabled'  image_id=${first_image_id}
245    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
246    Redfish.Login
247    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
248