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
23Resource                 ../../lib/bmc_network_utils.robot
24Library                  ../../lib/gen_robot_valid.py
25Library                  ../../lib/tftp_update_utils.py
26Library                  ../../lib/gen_robot_keyword.py
27
28Suite Setup              Suite Setup Execution
29Suite Teardown           Redfish.Logout
30Test Setup               Printn
31Test Teardown            FFDC On Test Case Fail
32
33Force Tags               BMC_Code_Update
34
35*** Variables ***
36
37@{ADMIN}          admin_user  TestPwd123
38&{USERS}          Administrator=${ADMIN}
39${LOOP_COUNT}     ${2}
40@{HOSTNAME}       bmc_system01  bmc_system02  bmc_system03  bmc_system04  bmc_system05
41
42*** Test Cases ***
43
44Redfish Code Update With ApplyTime OnReset
45    [Documentation]  Update the firmware image with ApplyTime of OnReset.
46    [Tags]  Redfish_Code_Update_With_ApplyTime_OnReset
47    [Template]  Redfish Update Firmware
48
49    # policy
50    OnReset
51
52
53Redfish Code Update With ApplyTime Immediate
54    [Documentation]  Update the firmware image with ApplyTime of Immediate.
55    [Tags]  Redfish_Code_Update_With_ApplyTime_Immediate
56    [Template]  Redfish Update Firmware
57
58    # policy
59    Immediate
60
61
62Redfish Code Update Same Firmware Multiple Times
63    [Documentation]  Multiple times update the firmware image for update service.
64    [Tags]  Redfish_Code_Update_Same_Firmware_Multiple_Times
65
66    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
67
68    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
69       Print Timen  ***************************************
70       Print Timen  * The Current Loop Count is ${count} of ${LOOP_COUNT} *
71       Print Timen  ***************************************
72
73       Redfish Update Firmware  apply_time=OnReset
74    END
75
76
77
78Redfish Code Update With Multiple Firmware
79    [Documentation]  Update the firmware image with ApplyTime of Immediate.
80    [Tags]  Redfish_Code_Update_With_Multiple_Firmware
81    [Template]  Redfish Multiple Upload Image And Check Progress State
82
83    # policy   image_file_path     alternate_image_file_path
84    Immediate  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
85
86
87Post BMC Reset Perform Redfish Code Update
88    [Documentation]  Test to reset BMC at standby and then perform BMC firmware update and
89    ...              ensure there is not error or dump logs post update.
90    [Tags]  Post_BMC_Reset_Perform_Redfish_Code_Update
91
92    Redfish Delete All BMC Dumps
93    Redfish Purge Event Log
94
95    Redfish OBMC Reboot (off)
96
97    Redfish Update Firmware  apply_time=OnReset
98
99    Event Log Should Not Exist
100    Redfish BMC Dump Should Not Exist
101
102    Redfish Power Off
103
104
105Post BMC Reset Perform Image Switched To Backup Multiple Times
106    [Documentation]  Test to reset BMC at standby and then perform switch
107    ...              to backup image multiple times.
108    ...              Then ensure no event and dump logs exist.
109    [Tags]  Post_BMC_Reset_Perform_Image_Switched_To_Backup_Multiple_Times
110
111    Redfish Delete All BMC Dumps
112    Redfish Purge Event Log
113
114    Redfish OBMC Reboot (off)
115
116    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
117
118    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
119      ${state}=  Get Pre Reboot State
120
121      # change to backup image and reset the BMC.
122      Switch Backup Firmware Image To Functional
123
124      Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
125    END
126
127    Event Log Should Not Exist
128    Redfish BMC Dump Should Not Exist
129
130
131Verify If The Modified Admin Credential Is Valid Post Image Switched To Backup
132    [Documentation]  Verify updated admin credential remain same post switch to back up image.
133    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Image_Switched_To_Backup
134    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
135    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
136
137    ${post_code_update_actions}=  Get Post Boot Action
138    ${state}=  Get Pre Reboot State
139    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
140
141    Redfish.Login
142    # change to backup image and reset the BMC.
143    Switch Backup Firmware Image To Functional
144    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
145
146    # verify modified admin password on backup image.
147    Redfish.Login  admin_user  0penBmc123
148    Redfish.Logout
149
150
151Verify If The Modified Admin Credential Is Valid Post Update
152    [Documentation]  Verify updated admin credential remain same post code update image.
153    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Update
154    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
155    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
156
157    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
158
159    Redfish.Login
160    # Flash latest firmware using redfish.
161    Redfish Update Firmware  OnReset
162
163    # verify modified admin credentails on latest image.
164    Redfish.Login  admin_user  0penBmc123
165    Redfish.Logout
166
167
168Redfish Code Update With Different Interrupted Operation
169    [Documentation]  Ensure firmware update is successful when different interrupted operation executed
170    ...              i.e. change the hostname.
171    [Tags]  Redfish_Code_Update_With_Different_Interrupted_Operation
172    [Template]  Verify Redfish Code Update With Different Interrupted Operation
173
174    # operation    count
175    host_name       1
176    kernel_panic    1
177
178*** Keywords ***
179
180Suite Setup Execution
181    [Documentation]  Do the suite setup.
182
183    Valid File Path  IMAGE_FILE_PATH
184    Redfish.Login
185
186    Redfish Delete All BMC Dumps
187    Redfish Purge Event Log
188
189    Redfish Power Off  stack_mode=skip
190
191
192Redfish Update Firmware
193    [Documentation]  Update the BMC firmware via redfish interface.
194    [Arguments]  ${apply_time}
195
196    # Description of argument(s):
197    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
198
199    ${post_code_update_actions}=  Get Post Boot Action
200    ${state}=  Get Pre Reboot State
201    Rprint Vars  state
202    Set ApplyTime  policy=${apply_Time}
203
204    ${task_inv_dict}=  Get Task State from File
205
206    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
207
208    Log To Console   Start uploading image to BMC.
209    Upload Image To BMC  ${REDFISH_BASE_URI}UpdateService  timeout=${600}  data=${file_bin_data}
210    Log To Console   Completed image upload to BMC.
211
212    ${task_inv}=  Check Task With Match TargetUri  /redfish/v1/UpdateService
213
214    Rprint Vars  task_inv
215
216    Wait Until Keyword Succeeds  5 min  10 sec
217    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
218
219    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
220    Redfish.Login
221    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
222    Verify Get ApplyTime  ${apply_time}
223
224
225Redfish Multiple Upload Image And Check Progress State
226    [Documentation]  Update multiple BMC firmware via redfish interface and check status.
227    [Arguments]  ${apply_time}  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
228
229    # Description of argument(s):
230    # apply_time                 ApplyTime allowed values (e.g. "OnReset", "Immediate").
231    # IMAGE_FILE_PATH            The path to BMC image file.
232    # ALTERNATE_IMAGE_FILE_PATH  The path to alternate BMC image file.
233
234    ${post_code_update_actions}=  Get Post Boot Action
235    Valid File Path  ALTERNATE_IMAGE_FILE_PATH
236    ${state}=  Get Pre Reboot State
237    Rprint Vars  state
238
239    Set ApplyTime  policy=${apply_time}
240    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${IMAGE_FILE_PATH}
241
242    ${first_image_id}=  Get Latest Image ID
243    Rprint Vars  first_image_id
244    Sleep  5s
245    Redfish Upload Image  ${REDFISH_BASE_URI}UpdateService  ${ALTERNATE_IMAGE_FILE_PATH}
246
247    ${second_image_id}=  Get Latest Image ID
248    Rprint Vars  second_image_id
249
250    Check Image Update Progress State
251    ...  match_state='Updating', 'Disabled'  image_id=${second_image_id}
252
253    Check Image Update Progress State
254    ...  match_state='Updating'  image_id=${first_image_id}
255
256    Wait Until Keyword Succeeds  8 min  20 sec
257    ...  Check Image Update Progress State
258    ...    match_state='Enabled'  image_id=${first_image_id}
259    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
260    Redfish.Login
261    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
262
263
264Run Configure BMC Hostname In Loop
265    [Documentation]  Update hostname in loop.
266    [Arguments]  ${count}
267
268    # Description of argument(s):
269    # count    Loop count.
270
271    FOR  ${index}  IN RANGE  ${count}
272      Configure Hostname  hostname=${HOSTNAME}[${index}]  status_code=[${HTTP_INTERNAL_SERVER_ERROR}]
273    END
274
275
276Run Operation On BMC
277    [Documentation]  Run operation on BMC.
278    [Arguments]  ${operation}  ${count}
279
280    # Description of argument(s):
281    # operation    If host_name then change hostname.
282    # count        Loop count.
283
284    Run Keyword If  '${operation}' == 'host_name'  Run Configure BMC Hostname In Loop  count=${count}
285    Run Keyword If  '${operation}' == 'kernel_panic'
286    ...  Run Keywords  Kernel Panic BMC Reset Operation  AND
287    ...  Is BMC Unpingable
288
289
290Get Active Firmware Image
291    [Documentation]  Return get active firmware image.
292
293    ${active_image}=  Redfish.Get Attribute  /redfish/v1/Managers/bmc  Links
294    Rprint Vars  active_image
295
296    [Return]  ${active_image}
297
298
299Verify Redfish Code Update With Different Interrupted Operation
300    [Documentation]  Verify code update is successful when other operation
301    ...              getting executed i.e. change the hostname.
302    [Arguments]  ${operation}  ${count}
303
304    # Description of argument(s):
305    # operation    host_name to change Hostname, kernel_panic to perform kernel panic.
306    # count        Number of times loop will get executed.
307
308    ${before_update_activeswimage}=  Get Active Firmware Image
309
310    ${post_code_update_actions}=  Get Post Boot Action
311
312    Set ApplyTime  policy=OnReset
313
314    ${task_inv_dict}=  Get Task State from File
315
316    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
317
318    Log To Console   Start uploading image to BMC.
319    Upload Image To BMC  ${REDFISH_BASE_URI}UpdateService  timeout=${600}  data=${file_bin_data}
320    Log To Console   Completed image upload to BMC.
321
322    ${task_inv}=  Check Task With Match TargetUri  /redfish/v1/UpdateService
323    Rprint Vars  task_inv
324
325    Wait Until Keyword Succeeds  1 min  10 sec
326    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskStarting']}
327
328    Run Operation On BMC  ${operation}  ${count}
329
330    Run Keyword If  '${operation}' == 'kernel_panic'
331    ...  Wait Until Keyword Succeeds  10 min  10 sec  Is BMC Standby
332
333    Run Keyword If  '${operation}' == 'host_name'
334    ...  Run Keywords  Wait Until Keyword Succeeds  5 min  10 sec
335    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}  AND
336    ...  Run Key  ${post_code_update_actions['BMC image']['OnReset']}  AND
337    ...  Redfish.Login  AND
338    ...  Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
339
340    ${after_update_activeswimage}=  Get Active Firmware Image
341
342    ${status}=  Run Keyword And Return Status  Should Be Equal As Strings
343    ...  ${before_update_activeswimage['ActiveSoftwareImage']['@odata.id']}
344    ...  ${after_update_activeswimage['ActiveSoftwareImage']['@odata.id']}
345
346    Run Keyword If  '${operation}' == 'kernel_panic'
347    ...    Should Be True  ${status}
348    ...  ELSE
349    ...    Should Not Be True  ${status}
350
351    Verify Get ApplyTime  OnReset
352
353