xref: /openbmc/openbmc-test-automation/redfish/update_service/test_redfish_bmc_code_update.robot (revision d1e05077daece46f266209fbf8cc47b827405cb7)
1cdebdd5fSSushil Singh*** Settings ***
2cdebdd5fSSushil SinghDocumentation            Update firmware on a target BMC via Redifsh.
3cdebdd5fSSushil Singh
4cdebdd5fSSushil Singh# Test Parameters:
5cdebdd5fSSushil Singh# IMAGE_FILE_PATH        The path to the BMC image file.
6cdebdd5fSSushil Singh#
7cdebdd5fSSushil Singh# Firmware update states:
8cdebdd5fSSushil Singh#     Enabled            Image is installed and either functional or active.
9cdebdd5fSSushil Singh#     Disabled           Image installation failed or ready for activation.
10cdebdd5fSSushil Singh#     Updating           Image installation currently in progress.
11cdebdd5fSSushil Singh
12cdebdd5fSSushil SinghResource                 ../../lib/resource.robot
13cdebdd5fSSushil SinghResource                 ../../lib/bmc_redfish_resource.robot
14cdebdd5fSSushil SinghResource                 ../../lib/openbmc_ffdc.robot
15cdebdd5fSSushil SinghResource                 ../../lib/common_utils.robot
16cdebdd5fSSushil SinghResource                 ../../lib/code_update_utils.robot
17cdebdd5fSSushil SinghResource                 ../../lib/dump_utils.robot
18cdebdd5fSSushil SinghResource                 ../../lib/logging_utils.robot
19cdebdd5fSSushil SinghResource                 ../../lib/redfish_code_update_utils.robot
20b13fc369SSushil SinghResource                 ../../lib/utils.robot
217ed1ae88SAnves Kumar rayankulaResource                 ../../lib/bmc_redfish_utils.robot
22c8526a2eSSushil SinghResource                 ../../lib/external_intf/management_console_utils.robot
2344bfc20aSSushil SinghResource                 ../../lib/bmc_network_utils.robot
241ee3c939SSushil SinghResource                 ../../lib/certificate_utils.robot
25cdebdd5fSSushil SinghLibrary                  ../../lib/gen_robot_valid.py
26cdebdd5fSSushil SinghLibrary                  ../../lib/tftp_update_utils.py
27f7674a54SSushil SinghLibrary                  ../../lib/gen_robot_keyword.py
28cdebdd5fSSushil Singh
29cdebdd5fSSushil SinghSuite Setup              Suite Setup Execution
30cdebdd5fSSushil SinghSuite Teardown           Redfish.Logout
31cdebdd5fSSushil SinghTest Setup               Printn
32cdebdd5fSSushil SinghTest Teardown            FFDC On Test Case Fail
33cdebdd5fSSushil Singh
346fb70d98SMatt FischerTest Tags               Redfish_Bmc_Code_Update
35cdebdd5fSSushil Singh
367ed1ae88SAnves Kumar rayankula*** Variables ***
377ed1ae88SAnves Kumar rayankula
387ed1ae88SAnves Kumar rayankula@{ADMIN}                 admin_user  TestPwd123
397ed1ae88SAnves Kumar rayankula&{USERS}                 Administrator=${ADMIN}
40c915f5edSSushil Singh${LOOP_COUNT}            ${2}
4144bfc20aSSushil Singh@{HOSTNAME}              bmc_system01  bmc_system02  bmc_system03  bmc_system04  bmc_system05
427ed1ae88SAnves Kumar rayankula
43cdebdd5fSSushil Singh*** Test Cases ***
44cdebdd5fSSushil Singh
45cdebdd5fSSushil SinghRedfish Code Update With ApplyTime OnReset
4616b3c7bfSGeorge Keishing    [Documentation]  Update the firmware image with ApplyTime of OnReset.
47cdebdd5fSSushil Singh    [Tags]  Redfish_Code_Update_With_ApplyTime_OnReset
48cdebdd5fSSushil Singh    [Template]  Redfish Update Firmware
49cdebdd5fSSushil Singh
50cdebdd5fSSushil Singh    # policy
51cdebdd5fSSushil Singh    OnReset
52cdebdd5fSSushil Singh
53cdebdd5fSSushil Singh
54cdebdd5fSSushil SinghRedfish Code Update With ApplyTime Immediate
5516b3c7bfSGeorge Keishing    [Documentation]  Update the firmware image with ApplyTime of Immediate.
56cdebdd5fSSushil Singh    [Tags]  Redfish_Code_Update_With_ApplyTime_Immediate
57cdebdd5fSSushil Singh    [Template]  Redfish Update Firmware
58cdebdd5fSSushil Singh
59cdebdd5fSSushil Singh    # policy
60cdebdd5fSSushil Singh    Immediate
61cdebdd5fSSushil Singh
62cdebdd5fSSushil Singh
63c915f5edSSushil SinghRedfish Code Update Same Firmware Multiple Times
64c915f5edSSushil Singh    [Documentation]  Multiple times update the firmware image for update service.
65c915f5edSSushil Singh    [Tags]  Redfish_Code_Update_Same_Firmware_Multiple_Times
66c915f5edSSushil Singh
67c915f5edSSushil Singh    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
68c915f5edSSushil Singh
69c915f5edSSushil Singh    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
70a83bba0aSSushil Singh       Print Timen  ***************************************
71c915f5edSSushil Singh       Print Timen  * The Current Loop Count is ${count} of ${LOOP_COUNT} *
72a83bba0aSSushil Singh       Print Timen  ***************************************
73c915f5edSSushil Singh
74c915f5edSSushil Singh       Redfish Update Firmware  apply_time=OnReset
75c915f5edSSushil Singh    END
76c915f5edSSushil Singh
77c915f5edSSushil Singh
78c915f5edSSushil Singh
79ffbfedf2SSushil SinghRedfish Code Update With Multiple Firmware
8016b3c7bfSGeorge Keishing    [Documentation]  Update the firmware image with ApplyTime of Immediate.
81ffbfedf2SSushil Singh    [Tags]  Redfish_Code_Update_With_Multiple_Firmware
82ffbfedf2SSushil Singh    [Template]  Redfish Multiple Upload Image And Check Progress State
83ffbfedf2SSushil Singh
84ffbfedf2SSushil Singh    # policy   image_file_path     alternate_image_file_path
856209865aSSushil Singh    OnReset  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
86ffbfedf2SSushil Singh
87ffbfedf2SSushil Singh
88c8526a2eSSushil SinghPost BMC Reset Perform Redfish Code Update
89c8526a2eSSushil Singh    [Documentation]  Test to reset BMC at standby and then perform BMC firmware update and
90c8526a2eSSushil Singh    ...              ensure there is not error or dump logs post update.
91c8526a2eSSushil Singh    [Tags]  Post_BMC_Reset_Perform_Redfish_Code_Update
92c8526a2eSSushil Singh
93c8526a2eSSushil Singh    Redfish Delete All BMC Dumps
94c8526a2eSSushil Singh    Redfish Purge Event Log
95c8526a2eSSushil Singh
96c8526a2eSSushil Singh    Redfish OBMC Reboot (off)
97c8526a2eSSushil Singh
98c8526a2eSSushil Singh    Redfish Update Firmware  apply_time=OnReset
99c8526a2eSSushil Singh
100c8526a2eSSushil Singh    Event Log Should Not Exist
101c8526a2eSSushil Singh    Redfish BMC Dump Should Not Exist
102c8526a2eSSushil Singh
103c8526a2eSSushil Singh    Redfish Power Off
104c8526a2eSSushil Singh
105c8526a2eSSushil Singh
106c8526a2eSSushil SinghPost BMC Reset Perform Image Switched To Backup Multiple Times
1070d930e9eSGeorge Keishing    [Documentation]  Test to reset BMC at standby and then perform switch
1080d930e9eSGeorge Keishing    ...              to backup image multiple times.
109c8526a2eSSushil Singh    ...              Then ensure no event and dump logs exist.
110c8526a2eSSushil Singh    [Tags]  Post_BMC_Reset_Perform_Image_Switched_To_Backup_Multiple_Times
111c8526a2eSSushil Singh
112c8526a2eSSushil Singh    Redfish Delete All BMC Dumps
113c8526a2eSSushil Singh    Redfish Purge Event Log
114c8526a2eSSushil Singh
115c8526a2eSSushil Singh    Redfish OBMC Reboot (off)
116c8526a2eSSushil Singh
117c8526a2eSSushil Singh    ${temp_update_loop_count}=  Evaluate  ${LOOP_COUNT} + 1
118c8526a2eSSushil Singh
119c8526a2eSSushil Singh    FOR  ${count}  IN RANGE  1  ${temp_update_loop_count}
120c8526a2eSSushil Singh      ${state}=  Get Pre Reboot State
121c8526a2eSSushil Singh
122c8526a2eSSushil Singh      # change to backup image and reset the BMC.
123c8526a2eSSushil Singh      Switch Backup Firmware Image To Functional
124c8526a2eSSushil Singh
125c8526a2eSSushil Singh      Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
126c8526a2eSSushil Singh    END
127c8526a2eSSushil Singh
128c8526a2eSSushil Singh    Event Log Should Not Exist
129c8526a2eSSushil Singh    Redfish BMC Dump Should Not Exist
130c8526a2eSSushil Singh
131c8526a2eSSushil Singh
1327ed1ae88SAnves Kumar rayankulaVerify If The Modified Admin Credential Is Valid Post Image Switched To Backup
1335166ebd5SSushil Singh    [Documentation]  Verify updated admin credential remain same post switch to back up image.
1345236ec54SGeorge Keishing    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Image_Switched_To_Backup
1357ed1ae88SAnves Kumar rayankula    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
1367ed1ae88SAnves Kumar rayankula    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
1377ed1ae88SAnves Kumar rayankula
1387ed1ae88SAnves Kumar rayankula    ${post_code_update_actions}=  Get Post Boot Action
1397ed1ae88SAnves Kumar rayankula    ${state}=  Get Pre Reboot State
1407ed1ae88SAnves Kumar rayankula    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
1417ed1ae88SAnves Kumar rayankula
1427ed1ae88SAnves Kumar rayankula    Redfish.Login
1437ed1ae88SAnves Kumar rayankula    # change to backup image and reset the BMC.
1447ed1ae88SAnves Kumar rayankula    Switch Backup Firmware Image To Functional
1457ed1ae88SAnves Kumar rayankula    Wait For Reboot  start_boot_seconds=${state['epoch_seconds']}
1467ed1ae88SAnves Kumar rayankula
1477ed1ae88SAnves Kumar rayankula    # verify modified admin password on backup image.
1487ed1ae88SAnves Kumar rayankula    Redfish.Login  admin_user  0penBmc123
1497ed1ae88SAnves Kumar rayankula    Redfish.Logout
1507ed1ae88SAnves Kumar rayankula
1515166ebd5SSushil Singh
1527ed1ae88SAnves Kumar rayankulaVerify If The Modified Admin Credential Is Valid Post Update
1535166ebd5SSushil Singh    [Documentation]  Verify updated admin credential remain same post code update image.
1545236ec54SGeorge Keishing    [Tags]  Verify_If_The_Modified_Admin_Credential_Is_Valid_Post_Update
1557ed1ae88SAnves Kumar rayankula    [Setup]  Create Users With Different Roles  users=${USERS}  force=${True}
1567ed1ae88SAnves Kumar rayankula    [Teardown]  Run Keywords  Redfish.Login  AND  Delete BMC Users Via Redfish  users=${USERS}
1577ed1ae88SAnves Kumar rayankula
1587ed1ae88SAnves Kumar rayankula    Expire And Update New Password Via Redfish  ${ADMIN[0]}  ${ADMIN[1]}  0penBmc123
1597ed1ae88SAnves Kumar rayankula
1607ed1ae88SAnves Kumar rayankula    Redfish.Login
1617ed1ae88SAnves Kumar rayankula    # Flash latest firmware using redfish.
1627ed1ae88SAnves Kumar rayankula    Redfish Update Firmware  OnReset
1637ed1ae88SAnves Kumar rayankula
1649bfdf8a7SGeorge Keishing    # verify modified admin credentials on latest image.
1657ed1ae88SAnves Kumar rayankula    Redfish.Login  admin_user  0penBmc123
1667ed1ae88SAnves Kumar rayankula    Redfish.Logout
1677ed1ae88SAnves Kumar rayankula
16844bfc20aSSushil Singh
16910385710SSushil SinghVerify Redfish Code Update Completion In Spite Of Changing Hostname
17010385710SSushil Singh    [Documentation]  Ensure firmware update is successful when interrupted operation performed like
17110385710SSushil Singh    ...              change the hostname.
17210385710SSushil Singh    [Tags]  Verify_Redfish_Code_Update_Completion_In_Spite_Of_Changing_Hostname
17344bfc20aSSushil Singh    [Template]  Verify Redfish Code Update With Different Interrupted Operation
1748689506eSSushil Singh    [Teardown]  Code Update Interrupted Operation Teardown
17544bfc20aSSushil Singh
17644bfc20aSSushil Singh    # operation          count
17744bfc20aSSushil Singh    host_name            1
17810385710SSushil Singh
17910385710SSushil Singh
18010385710SSushil SinghVerify Redfish Code Update Completion In Spite Of Performing Kernel Panic
18110385710SSushil Singh    [Documentation]  Ensure firmware update is successful when interrupted operation performed like
18210385710SSushil Singh    ...              firmware update fail when kernel panic.
18310385710SSushil Singh    [Tags]  Verify_Redfish_Code_Update_Completion_In_Spite_Of_Performing_Kernel_Panic
18410385710SSushil Singh    [Template]  Verify Redfish Code Update With Different Interrupted Operation
18510385710SSushil Singh    [Teardown]  Code Update Interrupted Operation Teardown
18610385710SSushil Singh
18710385710SSushil Singh    # operation          count
18844bfc20aSSushil Singh    kernel_panic         1
18910385710SSushil Singh
19010385710SSushil Singh
19110385710SSushil SinghVerify Redfish Code Update Completion In Spite Of Updating HTTPS Certificate
19210385710SSushil Singh    [Documentation]  Ensure firmware update is successful when interrupted operation performed like
19310385710SSushil Singh    ...              updating https certificate.
19410385710SSushil Singh    [Tags]  Verify_Redfish_Code_Update_Completion_In_Spite_Of_Updating_HTTPS_Certificate
19510385710SSushil Singh    [Template]  Verify Redfish Code Update With Different Interrupted Operation
19610385710SSushil Singh    [Teardown]  Code Update Interrupted Operation Teardown
19710385710SSushil Singh
19810385710SSushil Singh    # operation          count
1991ee3c939SSushil Singh    https_certificate    1
20044bfc20aSSushil Singh
201cdebdd5fSSushil Singh*** Keywords ***
202cdebdd5fSSushil Singh
203cdebdd5fSSushil SinghSuite Setup Execution
204cdebdd5fSSushil Singh    [Documentation]  Do the suite setup.
205cdebdd5fSSushil Singh
206cdebdd5fSSushil Singh    Valid File Path  IMAGE_FILE_PATH
207cdebdd5fSSushil Singh    Redfish.Login
208c8526a2eSSushil Singh
2094aff2d02STim Lee    Redfish Delete All BMC Dumps
210cdebdd5fSSushil Singh    Redfish Purge Event Log
211cdebdd5fSSushil Singh
212c8526a2eSSushil Singh    Redfish Power Off  stack_mode=skip
213c8526a2eSSushil Singh
214759f1489SSushil Singh
2158689506eSSushil SinghCode Update Interrupted Operation Teardown
2168689506eSSushil Singh    [Documentation]  Code update interrupted operation teardown.
2178689506eSSushil Singh
2188689506eSSushil Singh    ${task_inv_dict}=  Get Task State from File
2198689506eSSushil Singh
2208689506eSSushil Singh    ${redfish_update_uri}=  Get Redfish Update Service URI
2218689506eSSushil Singh
2228689506eSSushil Singh    IF  '${TEST STATUS}' == 'FAIL'
2238689506eSSushil Singh
2248689506eSSushil Singh      ${task_inv}=  Check Task With Match TargetUri  ${redfish_update_uri}
2258689506eSSushil Singh      Rprint Vars  task_inv
2268689506eSSushil Singh
2278689506eSSushil Singh      Wait Until Keyword Succeeds  2 min  10 sec
2288689506eSSushil Singh      ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskStarting']}
2298689506eSSushil Singh
2308689506eSSushil Singh      Wait Until Keyword Succeeds  5 min  10 sec
2318689506eSSushil Singh      ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
2328689506eSSushil Singh
2338689506eSSushil Singh      Redfish BMC Reset Operation
2348689506eSSushil Singh      Is BMC Standby
2358689506eSSushil Singh
2368689506eSSushil Singh    END
2378689506eSSushil Singh
2388689506eSSushil Singh
239514a840cSSushil SinghGet Redfish Update Service URI
240514a840cSSushil Singh    [Documentation]  Get Redfish firmware update URI.
241759f1489SSushil Singh
242514a840cSSushil Singh    ${update_url}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}UpdateService  HttpPushUri
243759f1489SSushil Singh
244514a840cSSushil Singh    Log To Console  Firmware update URI: ${update_url}
245514a840cSSushil Singh
246409df05dSGeorge Keishing    RETURN  ${update_url}
247759f1489SSushil Singh
248cdebdd5fSSushil Singh
249ffbfedf2SSushil SinghRedfish Multiple Upload Image And Check Progress State
250ffbfedf2SSushil Singh    [Documentation]  Update multiple BMC firmware via redfish interface and check status.
251ffbfedf2SSushil Singh    [Arguments]  ${apply_time}  ${IMAGE_FILE_PATH}  ${ALTERNATE_IMAGE_FILE_PATH}
252ffbfedf2SSushil Singh
253ffbfedf2SSushil Singh    # Description of argument(s):
254ffbfedf2SSushil Singh    # apply_time                 ApplyTime allowed values (e.g. "OnReset", "Immediate").
255ffbfedf2SSushil Singh    # IMAGE_FILE_PATH            The path to BMC image file.
256ffbfedf2SSushil Singh    # ALTERNATE_IMAGE_FILE_PATH  The path to alternate BMC image file.
257ffbfedf2SSushil Singh
2586209865aSSushil Singh
2596209865aSSushil Singh    ${task_inv_dict}=  Get Task State from File
2606209865aSSushil Singh
261b13fc369SSushil Singh    ${post_code_update_actions}=  Get Post Boot Action
2626209865aSSushil Singh
263ffbfedf2SSushil Singh    Valid File Path  ALTERNATE_IMAGE_FILE_PATH
2646209865aSSushil Singh
265ffbfedf2SSushil Singh    ${state}=  Get Pre Reboot State
266ffbfedf2SSushil Singh    Rprint Vars  state
267ffbfedf2SSushil Singh
268ffbfedf2SSushil Singh    Set ApplyTime  policy=${apply_time}
269514a840cSSushil Singh
270514a840cSSushil Singh    # URI : /redfish/v1/UpdateService
271514a840cSSushil Singh    # "HttpPushUri": "/redfish/v1/UpdateService/update",
272514a840cSSushil Singh
273514a840cSSushil Singh    ${redfish_update_uri}=  Get Redfish Update Service URI
274ffbfedf2SSushil Singh
2756209865aSSushil Singh    ${file_bin_data1}=  OperatingSystem.Get Binary File  ${IMAGE_FILE_PATH}
2766209865aSSushil Singh    ${file_bin_data2}=  OperatingSystem.Get Binary File  ${ALTERNATE_IMAGE_FILE_PATH}
277ffbfedf2SSushil Singh
2786209865aSSushil Singh    Log To Console  Uploading first image.
2796209865aSSushil Singh    ${resp1}=  Upload Image To BMC  ${redfish_update_uri}  timeout=${600}  data=${file_bin_data1}
280ffbfedf2SSushil Singh
2816209865aSSushil Singh    Log To Console  Uploading second image.
2826209865aSSushil Singh    ${resp2}=  Upload Image To BMC  ${redfish_update_uri}  timeout=${600}  data=${file_bin_data2}
283ffbfedf2SSushil Singh
2846209865aSSushil Singh    ${task_info2}=    evaluate    json.loads('''${resp2.content}''')    json
285ffbfedf2SSushil Singh
2866209865aSSushil Singh    Sleep  3s
2876209865aSSushil Singh
2886209865aSSushil Singh    ${task_inv2}=  Get Task Inventory  ${task_info2}
2896209865aSSushil Singh    Log  ${task_inv2}
2906209865aSSushil Singh
2916209865aSSushil Singh    Wait Until Keyword Succeeds  5 min  10 sec
2926209865aSSushil Singh    ...  Verify Task Progress State  ${task_inv2}  ${task_inv_dict['TaskException']}
2936209865aSSushil Singh
2946209865aSSushil Singh    ${task_info1}=    evaluate    json.loads('''${resp1.content}''')    json
2956209865aSSushil Singh    Log  ${task_info1}
2966209865aSSushil Singh
2976209865aSSushil Singh    ${task_inv1}=  Get Task Inventory  ${task_info1}
2986209865aSSushil Singh    Log  ${task_inv1}
2996209865aSSushil Singh
3006209865aSSushil Singh    Wait Until Keyword Succeeds  5 min  10 sec
3016209865aSSushil Singh    ...  Verify Task Progress State  ${task_inv1}  ${task_inv_dict['TaskCompleted']}
3026209865aSSushil Singh
303b13fc369SSushil Singh    Run Key  ${post_code_update_actions['BMC image']['${apply_time}']}
304b13fc369SSushil Singh    Redfish.Login
305b13fc369SSushil Singh    Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
306a83bba0aSSushil Singh
307a83bba0aSSushil Singh
30844bfc20aSSushil SinghRun Configure BMC Hostname In Loop
30944bfc20aSSushil Singh    [Documentation]  Update hostname in loop.
31044bfc20aSSushil Singh    [Arguments]  ${count}
31144bfc20aSSushil Singh
31244bfc20aSSushil Singh    # Description of argument(s):
31344bfc20aSSushil Singh    # count    Loop count.
31444bfc20aSSushil Singh
31544bfc20aSSushil Singh    FOR  ${index}  IN RANGE  ${count}
316514a840cSSushil Singh      Configure Hostname  hostname=${HOSTNAME}[${index}]  status_code=[${HTTP_OK}]
31744bfc20aSSushil Singh    END
31844bfc20aSSushil Singh
31944bfc20aSSushil Singh
3201ee3c939SSushil SinghRedfish Update Certificate Upload In Loop
3211ee3c939SSushil Singh    [Documentation]  Upload HTTPS server certificate via Redfish and verify using OpenSSL.
3221ee3c939SSushil Singh    [Arguments]  ${count}
3231ee3c939SSushil Singh
3241ee3c939SSushil Singh    # Description of argument(s):
3251ee3c939SSushil Singh    # count    Loop count.
3261ee3c939SSushil Singh
3271ee3c939SSushil Singh    FOR  ${index}  IN RANGE  ${count}
3281ee3c939SSushil Singh      ${resp}=  Run Keyword And Return Status  Redfish.Get  ${REDFISH_HTTPS_CERTIFICATE_URI}/1  valid_status_codes=[${HTTP_OK}]
3291ee3c939SSushil Singh      Should Be Equal As Strings  ${resp}  ${True}
3301ee3c939SSushil Singh
3311ee3c939SSushil Singh      ${cert_file_path}=  Generate Certificate File Via Openssl  Valid Certificate Valid Privatekey
3321ee3c939SSushil Singh      ${bytes}=  OperatingSystem.Get Binary File  ${cert_file_path}
3331ee3c939SSushil Singh      ${file_data}=  Decode Bytes To String  ${bytes}  UTF-8
3341ee3c939SSushil Singh
3351ee3c939SSushil Singh      ${certificate_dict}=  Create Dictionary
3361ee3c939SSushil Singh      ...  @odata.id=${REDFISH_HTTPS_CERTIFICATE_URI}/1
3371ee3c939SSushil Singh      ${payload}=  Create Dictionary  CertificateString=${file_data}
3381ee3c939SSushil Singh      ...  CertificateType=PEM  CertificateUri=${certificate_dict}
3391ee3c939SSushil Singh
3401ee3c939SSushil Singh      ${resp}=  Redfish.Post  /redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate
3411ee3c939SSushil Singh      ...  body=${payload}
3421ee3c939SSushil Singh
3431ee3c939SSushil Singh      Verify Certificate Visible Via OpenSSL  ${cert_file_path}
3441ee3c939SSushil Singh    END
3451ee3c939SSushil Singh
3461ee3c939SSushil Singh
34744bfc20aSSushil SinghRun Operation On BMC
34844bfc20aSSushil Singh    [Documentation]  Run operation on BMC.
34944bfc20aSSushil Singh    [Arguments]  ${operation}  ${count}
35044bfc20aSSushil Singh
35144bfc20aSSushil Singh    # Description of argument(s):
352ee0103d5SGeorge Keishing    # operation    Supports different variables.
3538689506eSSushil Singh    #              If host_name then change hostname,
3548689506eSSushil Singh    #              If kernel_panic then perform kernel panic,
3558689506eSSushil Singh    #              If https_certificate then change the https certificate.
35644bfc20aSSushil Singh    # count        Loop count.
35744bfc20aSSushil Singh
3588689506eSSushil Singh    # Below directory is required by keyword.
3598689506eSSushil Singh    # Redfish Update Certificate Upload In Loop
3608689506eSSushil Singh
3618689506eSSushil Singh    IF  '${operation}' == 'https_certificate'
3628689506eSSushil Singh      Run  rm -r certificate_dir
3638689506eSSushil Singh      Run  mkdir certificate_dir
3648689506eSSushil Singh    END
3658689506eSSushil Singh
366*d1e05077SGeorge Keishing    IF  '${operation}' == 'host_name'
367*d1e05077SGeorge Keishing        Run Configure BMC Hostname In Loop  count=${count}
368*d1e05077SGeorge Keishing    ELSE IF  '${operation}' == 'kernel_panic'
369*d1e05077SGeorge Keishing        Kernel Panic BMC Reset Operation
370*d1e05077SGeorge Keishing        Is BMC Unpingable
371*d1e05077SGeorge Keishing    ELSE IF  '${operation}' == 'https_certificate'
372*d1e05077SGeorge Keishing        Redfish Update Certificate Upload In Loop  count=${count}
373*d1e05077SGeorge Keishing    ELSE
374*d1e05077SGeorge Keishing        Fail  msg=Operation not handled.
375*d1e05077SGeorge Keishing    END
37644bfc20aSSushil Singh
37744bfc20aSSushil Singh
37844bfc20aSSushil SinghGet Active Firmware Image
37944bfc20aSSushil Singh    [Documentation]  Return get active firmware image.
38044bfc20aSSushil Singh
3814d430283Sganesanb    ${active_image}=  Redfish.Get Attribute  /redfish/v1/Managers/${MANAGER_ID}  Links
38244bfc20aSSushil Singh    Rprint Vars  active_image
38344bfc20aSSushil Singh
384409df05dSGeorge Keishing    RETURN  ${active_image}
38544bfc20aSSushil Singh
38644bfc20aSSushil Singh
3871ee3c939SSushil SinghGet New Image ID
3881ee3c939SSushil Singh    [Documentation]  Return the ID of the most recently extracted image.
3891ee3c939SSushil Singh
3901ee3c939SSushil Singh    ${image_id}=   Get Image Id   Updating
3911ee3c939SSushil Singh
392409df05dSGeorge Keishing    RETURN  ${image_id}
3931ee3c939SSushil Singh
3941ee3c939SSushil Singh
39544bfc20aSSushil SinghVerify Redfish Code Update With Different Interrupted Operation
3964611b818SGeorge Keishing    [Documentation]  Verify code update is successful when other operation
3971ee3c939SSushil Singh    ...              getting executed i.e. change the hostname, updating http certificate
3981ee3c939SSushil Singh    ...              and code update will fail for kernel panic.
39944bfc20aSSushil Singh    [Arguments]  ${operation}  ${count}
40044bfc20aSSushil Singh
40144bfc20aSSushil Singh    # Description of argument(s):
40244bfc20aSSushil Singh    # operation    host_name to change Hostname, kernel_panic to perform kernel panic.
40344bfc20aSSushil Singh    # count        Number of times loop will get executed.
40444bfc20aSSushil Singh
40544bfc20aSSushil Singh    ${before_update_activeswimage}=  Get Active Firmware Image
40644bfc20aSSushil Singh
40744bfc20aSSushil Singh    ${post_code_update_actions}=  Get Post Boot Action
40844bfc20aSSushil Singh
40944bfc20aSSushil Singh    Set ApplyTime  policy=OnReset
41044bfc20aSSushil Singh
41144bfc20aSSushil Singh    ${task_inv_dict}=  Get Task State from File
41244bfc20aSSushil Singh
41344bfc20aSSushil Singh    ${file_bin_data}=  OperatingSystem.Get Binary File  ${image_file_path}
41444bfc20aSSushil Singh
41544bfc20aSSushil Singh    Log To Console   Start uploading image to BMC.
416514a840cSSushil Singh
417514a840cSSushil Singh    # URI : /redfish/v1/UpdateService
418514a840cSSushil Singh    # "HttpPushUri": "/redfish/v1/UpdateService/update",
419514a840cSSushil Singh
420514a840cSSushil Singh    ${redfish_update_uri}=  Get Redfish Update Service URI
421514a840cSSushil Singh    Upload Image To BMC  ${redfish_update_uri}  timeout=${600}  data=${file_bin_data}
42244bfc20aSSushil Singh    Log To Console   Completed image upload to BMC.
42344bfc20aSSushil Singh
4248689506eSSushil Singh    Sleep  8
4251ee3c939SSushil Singh
4261ee3c939SSushil Singh    ${image_id}=  Get New Image ID
4271ee3c939SSushil Singh    Rprint Vars  image_id
4281ee3c939SSushil Singh
429514a840cSSushil Singh    ${task_inv}=  Check Task With Match TargetUri  ${redfish_update_uri}
43044bfc20aSSushil Singh    Rprint Vars  task_inv
43144bfc20aSSushil Singh
432514a840cSSushil Singh    Wait Until Keyword Succeeds  2 min  10 sec
43344bfc20aSSushil Singh    ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskStarting']}
43444bfc20aSSushil Singh
43544bfc20aSSushil Singh    Run Operation On BMC  ${operation}  ${count}
43644bfc20aSSushil Singh
4371ee3c939SSushil Singh    IF  '${operation}' == 'kernel_panic'
4381ee3c939SSushil Singh        Wait Until Keyword Succeeds  10 min  10 sec  Is BMC Standby
4391ee3c939SSushil Singh    ELSE IF  '${operation}' == 'host_name'
4401ee3c939SSushil Singh        Wait Until Keyword Succeeds  5 min  10 sec
4411ee3c939SSushil Singh        ...  Verify Task Progress State  ${task_inv}  ${task_inv_dict['TaskCompleted']}
4421ee3c939SSushil Singh        Run Key  ${post_code_update_actions['BMC image']['OnReset']}
4431ee3c939SSushil Singh        Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
4441ee3c939SSushil Singh    ELSE IF  '${operation}' == 'https_certificate'
4451ee3c939SSushil Singh        Check Image Update Progress State
4461ee3c939SSushil Singh        ...  match_state='Updating'  image_id=${image_id}
4471ee3c939SSushil Singh        Wait Until Keyword Succeeds  8 min  20 sec
4481ee3c939SSushil Singh        ...  Check Image Update Progress State
4491ee3c939SSushil Singh        ...  match_state='Enabled'  image_id=${image_id}
4501ee3c939SSushil Singh        Run Key  ${post_code_update_actions['BMC image']['OnReset']}
4511ee3c939SSushil Singh        Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
4521ee3c939SSushil Singh    ELSE
4531ee3c939SSushil Singh        Fail  msg=Operation not handled.
4541ee3c939SSushil Singh    END
45544bfc20aSSushil Singh
45644bfc20aSSushil Singh    ${after_update_activeswimage}=  Get Active Firmware Image
45744bfc20aSSushil Singh
45844bfc20aSSushil Singh    ${status}=  Run Keyword And Return Status  Should Be Equal As Strings
45944bfc20aSSushil Singh    ...  ${before_update_activeswimage['ActiveSoftwareImage']['@odata.id']}
46044bfc20aSSushil Singh    ...  ${after_update_activeswimage['ActiveSoftwareImage']['@odata.id']}
46144bfc20aSSushil Singh
462*d1e05077SGeorge Keishing    IF  '${operation}' == 'kernel_panic'
463*d1e05077SGeorge Keishing        Should Be True  ${status}
464*d1e05077SGeorge Keishing    ELSE
465*d1e05077SGeorge Keishing        Should Not Be True  ${status}
466*d1e05077SGeorge Keishing    END
46744bfc20aSSushil Singh
46844bfc20aSSushil Singh    Verify Get ApplyTime  OnReset
46944bfc20aSSushil Singh
470