xref: /openbmc/openbmc-test-automation/redfish/update_service/test_redfish_bmc_code_update.robot (revision d1e05077daece46f266209fbf8cc47b827405cb7)
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
34Test 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    OnReset  ${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 credentials on latest image.
165    Redfish.Login  admin_user  0penBmc123
166    Redfish.Logout
167
168
169Verify Redfish Code Update Completion In Spite Of Changing Hostname
170    [Documentation]  Ensure firmware update is successful when interrupted operation performed like
171    ...              change the hostname.
172    [Tags]  Verify_Redfish_Code_Update_Completion_In_Spite_Of_Changing_Hostname
173    [Template]  Verify Redfish Code Update With Different Interrupted Operation
174    [Teardown]  Code Update Interrupted Operation Teardown
175
176    # operation          count
177    host_name            1
178
179
180Verify Redfish Code Update Completion In Spite Of Performing Kernel Panic
181    [Documentation]  Ensure firmware update is successful when interrupted operation performed like
182    ...              firmware update fail when kernel panic.
183    [Tags]  Verify_Redfish_Code_Update_Completion_In_Spite_Of_Performing_Kernel_Panic
184    [Template]  Verify Redfish Code Update With Different Interrupted Operation
185    [Teardown]  Code Update Interrupted Operation Teardown
186
187    # operation          count
188    kernel_panic         1
189
190
191Verify Redfish Code Update Completion In Spite Of Updating HTTPS Certificate
192    [Documentation]  Ensure firmware update is successful when interrupted operation performed like
193    ...              updating https certificate.
194    [Tags]  Verify_Redfish_Code_Update_Completion_In_Spite_Of_Updating_HTTPS_Certificate
195    [Template]  Verify Redfish Code Update With Different Interrupted Operation
196    [Teardown]  Code Update Interrupted Operation Teardown
197
198    # operation          count
199    https_certificate    1
200
201*** Keywords ***
202
203Suite Setup Execution
204    [Documentation]  Do the suite setup.
205
206    Valid File Path  IMAGE_FILE_PATH
207    Redfish.Login
208
209    Redfish Delete All BMC Dumps
210    Redfish Purge Event Log
211
212    Redfish Power Off  stack_mode=skip
213
214
215Code Update Interrupted Operation Teardown
216    [Documentation]  Code update interrupted operation teardown.
217
218    ${task_inv_dict}=  Get Task State from File
219
220    ${redfish_update_uri}=  Get Redfish Update Service URI
221
222    IF  '${TEST STATUS}' == 'FAIL'
223
224      ${task_inv}=  Check Task With Match TargetUri  ${redfish_update_uri}
225      Rprint Vars  task_inv
226
227      Wait Until Keyword Succeeds  2 min  10 sec
228      ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskStarting']}
229
230      Wait Until Keyword Succeeds  5 min  10 sec
231      ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
232
233      Redfish BMC Reset Operation
234      Is BMC Standby
235
236    END
237
238
239Get Redfish Update Service URI
240    [Documentation]  Get Redfish firmware update URI.
241
242    ${update_url}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}UpdateService  HttpPushUri
243
244    Log To Console  Firmware update URI: ${update_url}
245
246    RETURN  ${update_url}
247
248
249Redfish Multiple Upload Image And Check Progress State
250    [Documentation]  Update multiple BMC firmware via redfish interface and check status.
251    [Arguments]  ${apply_time}  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
252
253    # Description of argument(s):
254    # apply_time                 ApplyTime allowed values (e.g. "OnReset", "Immediate").
255    # IMAGE_FILE_PATH            The path to BMC image file.
256    # ALTERNATE_IMAGE_FILE_PATH  The path to alternate BMC image file.
257
258
259    ${task_inv_dict}=  Get Task State from File
260
261    ${post_code_update_actions}=  Get Post Boot Action
262
263    Valid File Path  ALTERNATE_IMAGE_FILE_PATH
264
265    ${state}=  Get Pre Reboot State
266    Rprint Vars  state
267
268    Set ApplyTime  policy=${apply_time}
269
270    # URI : /redfish/v1/UpdateService
271    # "HttpPushUri": "/redfish/v1/UpdateService/update",
272
273    ${redfish_update_uri}=  Get Redfish Update Service URI
274
275    ${file_bin_data1}=  OperatingSystem.Get Binary File  ${IMAGE_FILE_PATH}
276    ${file_bin_data2}=  OperatingSystem.Get Binary File  ${ALTERNATE_IMAGE_FILE_PATH}
277
278    Log To Console  Uploading first image.
279    ${resp1}=  Upload Image To BMC  ${redfish_update_uri}  timeout=${600}  data=${file_bin_data1}
280
281    Log To Console  Uploading second image.
282    ${resp2}=  Upload Image To BMC  ${redfish_update_uri}  timeout=${600}  data=${file_bin_data2}
283
284    ${task_info2}=    evaluate    json.loads('''${resp2.content}''')    json
285
286    Sleep  3s
287
288    ${task_inv2}=  Get Task Inventory  ${task_info2}
289    Log  ${task_inv2}
290
291    Wait Until Keyword Succeeds  5 min  10 sec
292    ...  Verify Task Progress State  ${task_inv2}  ${task_inv_dict['TaskException']}
293
294    ${task_info1}=    evaluate    json.loads('''${resp1.content}''')    json
295    Log  ${task_info1}
296
297    ${task_inv1}=  Get Task Inventory  ${task_info1}
298    Log  ${task_inv1}
299
300    Wait Until Keyword Succeeds  5 min  10 sec
301    ...  Verify Task Progress State  ${task_inv1}  ${task_inv_dict['TaskCompleted']}
302
303    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
304    Redfish.Login
305    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
306
307
308Run Configure BMC Hostname In Loop
309    [Documentation]  Update hostname in loop.
310    [Arguments]  ${count}
311
312    # Description of argument(s):
313    # count    Loop count.
314
315    FOR  ${index}  IN RANGE  ${count}
316      Configure Hostname  hostname=${HOSTNAME}[${index}]  status_code=[${HTTP_OK}]
317    END
318
319
320Redfish Update Certificate Upload In Loop
321    [Documentation]  Upload HTTPS server certificate via Redfish and verify using OpenSSL.
322    [Arguments]  ${count}
323
324    # Description of argument(s):
325    # count    Loop count.
326
327    FOR  ${index}  IN RANGE  ${count}
328      ${resp}=  Run Keyword And Return Status  Redfish.Get  ${REDFISH_HTTPS_CERTIFICATE_URI}/1  valid_status_codes=[${HTTP_OK}]
329      Should Be Equal As Strings  ${resp}  ${True}
330
331      ${cert_file_path}=  Generate Certificate File Via Openssl  Valid Certificate Valid Privatekey
332      ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
333      ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8
334
335      ${certificate_dict}=  Create Dictionary
336      ...  @odata.id=${REDFISH_HTTPS_CERTIFICATE_URI}/1
337      ${payload}=  Create Dictionary  CertificateString=${file_data}
338      ...  CertificateType=PEM  CertificateUri=${certificate_dict}
339
340      ${resp}=  Redfish.Post  /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
341      ...  body=${payload}
342
343      Verify Certificate Visible Via OpenSSL  ${cert_file_path}
344    END
345
346
347Run Operation On BMC
348    [Documentation]  Run operation on BMC.
349    [Arguments]  ${operation}  ${count}
350
351    # Description of argument(s):
352    # operation    Supports different variables.
353    #              If host_name then change hostname,
354    #              If kernel_panic then perform kernel panic,
355    #              If https_certificate then change the https certificate.
356    # count        Loop count.
357
358    # Below directory is required by keyword.
359    # Redfish Update Certificate Upload In Loop
360
361    IF  '${operation}' == 'https_certificate'
362      Run  rm -r certificate_dir
363      Run  mkdir certificate_dir
364    END
365
366    IF  '${operation}' == 'host_name'
367        Run Configure BMC Hostname In Loop  count=${count}
368    ELSE IF  '${operation}' == 'kernel_panic'
369        Kernel Panic BMC Reset Operation
370        Is BMC Unpingable
371    ELSE IF  '${operation}' == 'https_certificate'
372        Redfish Update Certificate Upload In Loop  count=${count}
373    ELSE
374        Fail  msg=Operation not handled.
375    END
376
377
378Get Active Firmware Image
379    [Documentation]  Return get active firmware image.
380
381    ${active_image}=  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  Links
382    Rprint Vars  active_image
383
384    RETURN  ${active_image}
385
386
387Get New Image ID
388    [Documentation]  Return the ID of the most recently extracted image.
389
390    ${image_id}=   Get Image Id   Updating
391
392    RETURN  ${image_id}
393
394
395Verify Redfish Code Update With Different Interrupted Operation
396    [Documentation]  Verify code update is successful when other operation
397    ...              getting executed i.e. change the hostname, updating http certificate
398    ...              and code update will fail for kernel panic.
399    [Arguments]  ${operation}  ${count}
400
401    # Description of argument(s):
402    # operation    host_name to change Hostname, kernel_panic to perform kernel panic.
403    # count        Number of times loop will get executed.
404
405    ${before_update_activeswimage}=  Get Active Firmware Image
406
407    ${post_code_update_actions}=  Get Post Boot Action
408
409    Set ApplyTime  policy=OnReset
410
411    ${task_inv_dict}=  Get Task State from File
412
413    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
414
415    Log To Console   Start uploading image to BMC.
416
417    # URI : /redfish/v1/UpdateService
418    # "HttpPushUri": "/redfish/v1/UpdateService/update",
419
420    ${redfish_update_uri}=  Get Redfish Update Service URI
421    Upload Image To BMC  ${redfish_update_uri}  timeout=${600}  data=${file_bin_data}
422    Log To Console   Completed image upload to BMC.
423
424    Sleep  8
425
426    ${image_id}=  Get New Image ID
427    Rprint Vars  image_id
428
429    ${task_inv}=  Check Task With Match TargetUri  ${redfish_update_uri}
430    Rprint Vars  task_inv
431
432    Wait Until Keyword Succeeds  2 min  10 sec
433    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskStarting']}
434
435    Run Operation On BMC  ${operation}  ${count}
436
437    IF  '${operation}' == 'kernel_panic'
438        Wait Until Keyword Succeeds  10 min  10 sec  Is BMC Standby
439    ELSE IF  '${operation}' == 'host_name'
440        Wait Until Keyword Succeeds  5 min  10 sec
441        ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
442        Run Key  ${post_code_update_actions['BMC image']['OnReset']}
443        Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
444    ELSE IF  '${operation}' == 'https_certificate'
445        Check Image Update Progress State
446        ...  match_state='Updating'  image_id=${image_id}
447        Wait Until Keyword Succeeds  8 min  20 sec
448        ...  Check Image Update Progress State
449        ...  match_state='Enabled'  image_id=${image_id}
450        Run Key  ${post_code_update_actions['BMC image']['OnReset']}
451        Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
452    ELSE
453        Fail  msg=Operation not handled.
454    END
455
456    ${after_update_activeswimage}=  Get Active Firmware Image
457
458    ${status}=  Run Keyword And Return Status  Should Be Equal As Strings
459    ...  ${before_update_activeswimage['ActiveSoftwareImage']['@odata.id']}
460    ...  ${after_update_activeswimage['ActiveSoftwareImage']['@odata.id']}
461
462    IF  '${operation}' == 'kernel_panic'
463        Should Be True  ${status}
464    ELSE
465        Should Not Be True  ${status}
466    END
467
468    Verify Get ApplyTime  OnReset
469
470