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