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 perform switch
105    ...              to backup image multiple times.
106    ...              Then ensure no event and dump logs exist.
107    [Tags]  Post_BMC_Reset_Perform_Image_Switched_To_Backup_Multiple_Times
108
109    Redfish Delete All BMC Dumps
110    Redfish Purge Event Log
111
112    Redfish OBMC Reboot (off)
113
114    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
115
116    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
117      ${state}=  Get Pre Reboot State
118
119      # change to backup image and reset the BMC.
120      Switch Backup Firmware Image To Functional
121
122      Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
123    END
124
125    Event Log Should Not Exist
126    Redfish BMC Dump Should Not Exist
127
128
129Verify If The Modified Admin Credential Is Valid Post Image Switched To Backup
130    [Documentation]  Verify updated admin credential remain same post switch to back up image.
131    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Image_Switched_To_Backup
132    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
133    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
134
135    ${post_code_update_actions}=  Get Post Boot Action
136    ${state}=  Get Pre Reboot State
137    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
138
139    Redfish.Login
140    # change to backup image and reset the BMC.
141    Switch Backup Firmware Image To Functional
142    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
143
144    # verify modified admin password on backup image.
145    Redfish.Login  admin_user  0penBmc123
146    Redfish.Logout
147
148
149Verify If The Modified Admin Credential Is Valid Post Update
150    [Documentation]  Verify updated admin credential remain same post code update image.
151    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Update
152    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
153    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
154
155    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
156
157    Redfish.Login
158    # Flash latest firmware using redfish.
159    Redfish Update Firmware  OnReset
160
161    # verify modified admin credentails on latest image.
162    Redfish.Login  admin_user  0penBmc123
163    Redfish.Logout
164
165*** Keywords ***
166
167Suite Setup Execution
168    [Documentation]  Do the suite setup.
169
170    Valid File Path  IMAGE_FILE_PATH
171    Redfish.Login
172
173    Redfish Delete All BMC Dumps
174    Redfish Purge Event Log
175
176    Redfish Power Off  stack_mode=skip
177
178
179Redfish Update Firmware
180    [Documentation]  Update the BMC firmware via redfish interface.
181    [Arguments]  ${apply_time}
182
183    # Description of argument(s):
184    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
185
186    ${post_code_update_actions}=  Get Post Boot Action
187    ${state}=  Get Pre Reboot State
188    Rprint Vars  state
189    Set ApplyTime  policy=${apply_Time}
190
191    ${task_inv_dict}=  Get Task State from File
192
193    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
194
195    Log To Console   Start uploading image to BMC.
196    Upload Image To BMC  ${REDFISH_BASE_URI}UpdateService  timeout=${600}  data=${file_bin_data}
197    Log To Console   Completed image upload to BMC.
198
199    ${task_inv}=  Check Task With Match TargetUri  /redfish/v1/UpdateService
200
201    Rprint Vars  task_inv
202
203    Wait Until Keyword Succeeds  5 min  10 sec
204    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
205
206    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
207    Redfish.Login
208    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
209    Verify Get ApplyTime  ${apply_time}
210
211
212Redfish Multiple Upload Image And Check Progress State
213    [Documentation]  Update multiple BMC firmware via redfish interface and check status.
214    [Arguments]  ${apply_time}  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
215
216    # Description of argument(s):
217    # apply_time                 ApplyTime allowed values (e.g. "OnReset", "Immediate").
218    # IMAGE_FILE_PATH            The path to BMC image file.
219    # ALTERNATE_IMAGE_FILE_PATH  The path to alternate BMC image file.
220
221    ${post_code_update_actions}=  Get Post Boot Action
222    Valid File Path  ALTERNATE_IMAGE_FILE_PATH
223    ${state}=  Get Pre Reboot State
224    Rprint Vars  state
225
226    Set ApplyTime  policy=${apply_time}
227    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${IMAGE_FILE_PATH}
228
229    ${first_image_id}=  Get Latest Image ID
230    Rprint Vars  first_image_id
231    Sleep  5s
232    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${ALTERNATE_IMAGE_FILE_PATH}
233
234    ${second_image_id}=  Get Latest Image ID
235    Rprint Vars  second_image_id
236
237    Check Image Update Progress State
238    ...  match_state='Updating', 'Disabled'  image_id=${second_image_id}
239
240    Check Image Update Progress State
241    ...  match_state='Updating'  image_id=${first_image_id}
242
243    Wait Until Keyword Succeeds  8 min  20 sec
244    ...  Check Image Update Progress State
245    ...    match_state='Enabled'  image_id=${first_image_id}
246    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
247    Redfish.Login
248    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
249