xref: /openbmc/openbmc-test-automation/extended/code_update/bmc_code_update.robot (revision 7e8547152fcbf63e67651b34f14e90330b1af0ea)
19f74d3afSCharles Paul Hofer*** Settings ***
29f74d3afSCharles Paul HoferDocumentation     Update the BMC code on a target BMC.
39f74d3afSCharles Paul Hofer...               Execution Method:
49f74d3afSCharles Paul Hofer...               python -m robot -v OPENBMC_HOST:<hostname>
59f74d3afSCharles Paul Hofer...               -v IMAGE_FILE_PATH:<path/*.tar>  bmc_code_update.robot
69f74d3afSCharles Paul Hofer
79f74d3afSCharles Paul HoferLibrary           ../../lib/code_update_utils.py
8e78a4431SMichael WalshLibrary           ../../lib/gen_robot_keyword.py
99f74d3afSCharles Paul HoferVariables         ../../data/variables.py
1077c6919bSSivas SRRResource          ../../lib/utils.robot
119f74d3afSCharles Paul HoferResource          ../../lib/boot_utils.robot
129f74d3afSCharles Paul HoferResource          code_update_utils.robot
139f74d3afSCharles Paul HoferResource          ../../lib/code_update_utils.robot
141eb85f57SGeorge KeishingResource          ../../lib/openbmc_ffdc.robot
151eb85f57SGeorge KeishingResource          ../../lib/dump_utils.robot
168b70ddd5SRahul MaheshwariResource          ../../lib/certificate_utils.robot
179f74d3afSCharles Paul Hofer
18d66c5dceSCharles Paul HoferSuite Setup       Suite Setup Execution
19d66c5dceSCharles Paul Hofer
20d66c5dceSCharles Paul HoferTest Teardown     Test Teardown Execution
219f74d3afSCharles Paul Hofer
22*7e854715SGeorge Keishing# Force the test to timedout to prevent test hanging.
23*7e854715SGeorge KeishingTest Timeout      30 minutes
24*7e854715SGeorge Keishing
2509712a1eSGeorge KeishingForce Tags        BMC_Code_Update
2609712a1eSGeorge Keishing
279f74d3afSCharles Paul Hofer*** Variables ***
289f74d3afSCharles Paul Hofer
299f74d3afSCharles Paul Hofer${QUIET}                          ${1}
309f74d3afSCharles Paul Hofer${IMAGE_FILE_PATH}                ${EMPTY}
31c1fa2bc9SCharles Paul Hofer${ALTERNATE_IMAGE_FILE_PATH}      ${EMPTY}
32b7842a59SCharles Paul Hofer${SKIP_UPDATE_IF_ACTIVE}          false
33d66c5dceSCharles Paul Hofer${dump_id}                        ${EMPTY}
34d66c5dceSCharles Paul Hofer${running_persistence_test}       ${FALSE}
35d66c5dceSCharles Paul Hofer${test_errlog_text}               AutoTestSimple
369f74d3afSCharles Paul Hofer
379f74d3afSCharles Paul Hofer*** Test Cases ***
389f74d3afSCharles Paul Hofer
3977c6919bSSivas SRRTest Basic BMC Performance Before BMC Code Update
4077c6919bSSivas SRR    [Documentation]  Check performance of memory, CPU & file system of BMC.
4177c6919bSSivas SRR    [Tags]  Test_Basic_BMC_Performance_Before_BMC_Code_Update
4277c6919bSSivas SRR
4377c6919bSSivas SRR    Open Connection And Log In
4477c6919bSSivas SRR    Check BMC Performance
4577c6919bSSivas SRR
46d66c5dceSCharles Paul HoferPrepare Persistent Data
47d66c5dceSCharles Paul Hofer    [Documentation]  Set data that should persist across the code update.
48d66c5dceSCharles Paul Hofer    [Tags]  Prepare_Persistent_Data
49d66c5dceSCharles Paul Hofer
50d66c5dceSCharles Paul Hofer    # Install the debug tarball.
51d66c5dceSCharles Paul Hofer    BMC Execute Command  rm -rf /tmp/tarball
52d66c5dceSCharles Paul Hofer    Install Debug Tarball On BMC  tarball_file_path=${DEBUG_TARBALL_PATH}
53d66c5dceSCharles Paul Hofer
54d66c5dceSCharles Paul Hofer    # Create a dummy error log and dump.
55d66c5dceSCharles Paul Hofer    BMC Execute Command  /tmp/tarball/bin/logging-test -c ${test_errlog_text}
56d66c5dceSCharles Paul Hofer    ${dump_id}=  Create User Initiated Dump
57d66c5dceSCharles Paul Hofer    Check Dump Existence  ${dump_id}
58d66c5dceSCharles Paul Hofer    Set Suite Variable  ${dump_id}
59d66c5dceSCharles Paul Hofer
60d66c5dceSCharles Paul Hofer    # Set persistent settings.
61d66c5dceSCharles Paul Hofer    ${autoreboot_dict}=  Create Dictionary  data=${0}
62d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
63d66c5dceSCharles Paul Hofer    ...  data=${autoreboot_dict}
64d66c5dceSCharles Paul Hofer    ${onetime_dict}=  Create Dictionary  data=${0}
65d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
66d66c5dceSCharles Paul Hofer    ...  data=${onetime_dict}
67d66c5dceSCharles Paul Hofer
68d66c5dceSCharles Paul Hofer    # Let the remaining test cases know we are doing a persistence test so we
69d66c5dceSCharles Paul Hofer    # do not delete logs.
70d66c5dceSCharles Paul Hofer    Set Suite Variable  ${running_persistence_test}  ${TRUE}
71d66c5dceSCharles Paul Hofer
72d66c5dceSCharles Paul Hofer
739f74d3afSCharles Paul HoferREST BMC Code Update
749f74d3afSCharles Paul Hofer    [Documentation]  Do a BMC code update by uploading image on BMC via REST.
759f74d3afSCharles Paul Hofer    [Tags]  REST_BMC_Code_Update
76d66c5dceSCharles Paul Hofer    [Teardown]  REST BMC Code Update Teardown
779f74d3afSCharles Paul Hofer
788c7ada42SSweta Potthuri    Run Keyword And Ignore Error  List Installed Images  BMC
79fe96e64eSGeorge Keishing    Run Keyword And Ignore Error  Set ApplyTime  policy=OnReset
808c7ada42SSweta Potthuri
818010d867SGeorge Keishing    ${image_version}=  Get Version Tar  ${IMAGE_FILE_PATH}
82c81c6aebSMichael Walsh    ${bmc_release_info}=  Get BMC Release Info
83c81c6aebSMichael Walsh    ${functional_version}=  Set Variable  ${bmc_release_info['version_id']}
84c81c6aebSMichael Walsh    Rprint Vars  image_version  functional_version
858010d867SGeorge Keishing
868010d867SGeorge Keishing    # Check if the existing firmware is functional.
87c81c6aebSMichael Walsh    Pass Execution If  '${functional_version}' == '${image_version}'
88c81c6aebSMichael Walsh    ...  The existing ${image_version} firmware is already functional.
898010d867SGeorge Keishing
9021845469SCharles Paul Hofer    Upload And Activate Image  ${IMAGE_FILE_PATH}
9121845469SCharles Paul Hofer    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
929f74d3afSCharles Paul Hofer    OBMC Reboot (off)
93e43fb2f7SCharles Paul Hofer    Verify Running BMC Image  ${IMAGE_FILE_PATH}
94da339e6cSSivas SRR    BMC Execute Command  cd /etc ; cat host.conf hosts hostname  print_out=1
959f74d3afSCharles Paul Hofer
969f74d3afSCharles Paul Hofer
97d66c5dceSCharles Paul HoferVerify Error Log Persistency
98d66c5dceSCharles Paul Hofer    [Documentation]  Check that the error log is still present after a
99d66c5dceSCharles Paul Hofer    ...              code update.
100d66c5dceSCharles Paul Hofer    [Tags]  Verify_Error_Log_Persistency
101d66c5dceSCharles Paul Hofer
102a8800da7SSteven Sombar    ${error_log_paths}=  Read Properties  ${BMC_LOGGING_ENTRY}list
103d66c5dceSCharles Paul Hofer    Log To Console  ${error_log_paths}
104d66c5dceSCharles Paul Hofer    ${test_error_message}=  Read Attribute  @{error_log_paths}[-1]  Message
105d66c5dceSCharles Paul Hofer    Should Be Equal  ${test_error_message}
106d66c5dceSCharles Paul Hofer    ...  example.xyz.openbmc_project.Example.Elog.${test_errlog_text}
107d66c5dceSCharles Paul Hofer    Delete Error Log Entry  @{error_log_paths}[-1]
108d66c5dceSCharles Paul Hofer
109d66c5dceSCharles Paul Hofer
110d66c5dceSCharles Paul HoferVerify BMC Dump Persistency
111d66c5dceSCharles Paul Hofer    [Documentation]  Check that the BMC dump present after a code update.
112d66c5dceSCharles Paul Hofer    [Tags]  Verify_BMC_Dump_Persistency
113d66c5dceSCharles Paul Hofer    [Teardown]  Set Suite Variable  ${running_persistence_test}  ${FALSE}
114d66c5dceSCharles Paul Hofer
115d66c5dceSCharles Paul Hofer    Check Dump Existence  ${dump_id}
116d66c5dceSCharles Paul Hofer    Delete BMC Dump  ${dump_id}
117d66c5dceSCharles Paul Hofer
118d66c5dceSCharles Paul Hofer
119d66c5dceSCharles Paul HoferVerify Settings Persistency
120d66c5dceSCharles Paul Hofer    [Documentation]  Verify that the settings from 'Prepare Persistent Data'
121d66c5dceSCharles Paul Hofer    ...              are still set correctly after the code update.
122d66c5dceSCharles Paul Hofer    [Tags]  Verify_Settings_Persistency
123d66c5dceSCharles Paul Hofer
124d66c5dceSCharles Paul Hofer    ${autoreboot_enabled}=  Read Attribute  ${CONTROL_HOST_URI}auto_reboot
125d66c5dceSCharles Paul Hofer    ...  AutoReboot
126d66c5dceSCharles Paul Hofer    Should Be Equal  ${autoreboot_enabled}  ${0}
127d66c5dceSCharles Paul Hofer    ${onetime_enabled}=  Read Attribute  ${CONTROL_HOST_URI}boot/one_time
128d66c5dceSCharles Paul Hofer    ...  Enabled
129d66c5dceSCharles Paul Hofer    Should Be Equal  ${onetime_enabled}  ${0}
130d66c5dceSCharles Paul Hofer
131d66c5dceSCharles Paul Hofer    # Set values back to their defaults
132d66c5dceSCharles Paul Hofer    ${autoreboot_dict}=  Create Dictionary  data=${1}
133d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
134d66c5dceSCharles Paul Hofer    ...  data=${autoreboot_dict}
135d66c5dceSCharles Paul Hofer    ${onetime_dict}=  Create Dictionary  data=${1}
136d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
137d66c5dceSCharles Paul Hofer    ...  data=${onetime_dict}
138d66c5dceSCharles Paul Hofer
139d66c5dceSCharles Paul Hofer
140c1fa2bc9SCharles Paul HoferUpload And Activate Multiple BMC Images
141c1fa2bc9SCharles Paul Hofer    [Documentation]  Upload another BMC image and verify that its state is
142c1fa2bc9SCharles Paul Hofer    ...              different from all others.
143c1fa2bc9SCharles Paul Hofer    [Tags]  Upload_And_Activate_Multiple_BMC_Images
144c1fa2bc9SCharles Paul Hofer    [Template]  Activate Image And Verify No Duplicate Priorities
145c1fa2bc9SCharles Paul Hofer    [Setup]  Upload And Activate Multiple BMC Images Setup
146c1fa2bc9SCharles Paul Hofer
147c1fa2bc9SCharles Paul Hofer    # Image File Path              Image Purpose
148c1fa2bc9SCharles Paul Hofer    ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_BMC}
149c1fa2bc9SCharles Paul Hofer
150c1fa2bc9SCharles Paul Hofer
15142f17468SCharles Paul HoferBMC Set Priority To Invalid Values
15242f17468SCharles Paul Hofer    [Documentation]  Attempt to set the priority of an image to an invalid
15342f17468SCharles Paul Hofer    ...              value and expect an error.
15442f17468SCharles Paul Hofer    [Tags]  BMC_Set_Priority_To_Invalid_Values
15542f17468SCharles Paul Hofer    [Template]  Set Priority To Invalid Value And Expect Error
15642f17468SCharles Paul Hofer
15742f17468SCharles Paul Hofer    # Version Type              Priority
15842f17468SCharles Paul Hofer    ${VERSION_PURPOSE_BMC}     ${-1}
15942f17468SCharles Paul Hofer    ${VERSION_PURPOSE_BMC}     ${256}
16042f17468SCharles Paul Hofer
16142f17468SCharles Paul Hofer
1629f74d3afSCharles Paul HoferDelete BMC Image
1639f74d3afSCharles Paul Hofer    [Documentation]  Delete a BMC image from the BMC flash chip.
1649f74d3afSCharles Paul Hofer    [Tags]  Delete_BMC_Image
1659f74d3afSCharles Paul Hofer
1669f74d3afSCharles Paul Hofer    ${software_object}=  Get Non Running BMC Software Object
1679f74d3afSCharles Paul Hofer    Delete Image And Verify  ${software_object}  ${VERSION_PURPOSE_BMC}
168c1fa2bc9SCharles Paul Hofer
169c1fa2bc9SCharles Paul Hofer
17097ecb270SGeorge KeishingBMC Image Priority Attribute Test
17197ecb270SGeorge Keishing    [Documentation]  Set "Priority" attribute.
17297ecb270SGeorge Keishing    [Tags]  BMC_Image_Priority_Attribute_Test
17397ecb270SGeorge Keishing    [Template]  Temporarily Set BMC Attribute
17497ecb270SGeorge Keishing
17597ecb270SGeorge Keishing    # Property        Value
176872d69faSGeorge Keishing    Priority          ${False}
177872d69faSGeorge Keishing    Priority          ${True}
17897ecb270SGeorge Keishing    Priority          ${0}
17997ecb270SGeorge Keishing    Priority          ${1}
18097ecb270SGeorge Keishing    Priority          ${127}
18197ecb270SGeorge Keishing    Priority          ${255}
18297ecb270SGeorge Keishing
18397ecb270SGeorge Keishing
184e8dc5253SCharles Paul HoferDelete All Non Running BMC Images
185e8dc5253SCharles Paul Hofer    [Documentation]  Delete all non running BMC images.
186e8dc5253SCharles Paul Hofer    [Tags]  Delete_All_Non_Running_BMC_Images
187e8dc5253SCharles Paul Hofer
188e8dc5253SCharles Paul Hofer    ${version_id}=  Upload And Activate Image  ${ALTERNATE_IMAGE_FILE_PATH}
1890889d43bSGeorge Keishing    ...  skip_if_active=true
190e8dc5253SCharles Paul Hofer    Delete All Non Running BMC Images
191e8dc5253SCharles Paul Hofer
192e8dc5253SCharles Paul Hofer    ${software_ids}=  Get Software Objects Id
193e8dc5253SCharles Paul Hofer    ...  version_type=${VERSION_PURPOSE_BMC}
194e8dc5253SCharles Paul Hofer    Should Not Contain  ${software_ids}  ${version_id}
195e8dc5253SCharles Paul Hofer
1961659f59eSGeorge Keishing
1978b70ddd5SRahul MaheshwariTest Certificate Persistency After BMC Code Update
1988b70ddd5SRahul Maheshwari    [Documentation]  Test certificate persistency after BMC update.
1998b70ddd5SRahul Maheshwari    [Tags]  Test_Certificate_Persistency_After_BMC_Code_Update
2008b70ddd5SRahul Maheshwari
201fa146c43SRahul Maheshwari    # Create certificate sub-directory in current working directory.
202fa146c43SRahul Maheshwari    Create Directory  certificate_dir
203fa146c43SRahul Maheshwari    OperatingSystem.Directory Should Exist  ${EXECDIR}${/}certificate_dir
204fa146c43SRahul Maheshwari
2058b70ddd5SRahul Maheshwari    ${cert_file_path}=  Generate Certificate File Via Openssl
2068b70ddd5SRahul Maheshwari    ...  Valid Certificate Valid Privatekey
2078b70ddd5SRahul Maheshwari    ${file_data}=  OperatingSystem.Get Binary File  ${cert_file_path}
2088b70ddd5SRahul Maheshwari    ${cert_file_content}=  OperatingSystem.Get File  ${cert_file_path}
2098b70ddd5SRahul Maheshwari
2106a849ad2SRahul Maheshwari    Redfish.Login
2116a849ad2SRahul Maheshwari    ${cert_id}=  Install Certificate File On BMC  ${REDFISH_CA_CERTIFICATE_URI}  ok  data=${file_data}
2126a849ad2SRahul Maheshwari    Logging  Installed certificate id: ${cert_id}
2138b70ddd5SRahul Maheshwari
2146a849ad2SRahul Maheshwari    # Adding delay after certificate installation.
2156a849ad2SRahul Maheshwari    Sleep  30s
2166a849ad2SRahul Maheshwari
2176a849ad2SRahul Maheshwari    ${bmc_cert_content}=  redfish_utils.Get Attribute
2186a849ad2SRahul Maheshwari    ...  /redfish/v1/Managers/bmc/Truststore/Certificates/${cert_id}  CertificateString
2198b70ddd5SRahul Maheshwari    Should Contain  ${cert_file_content}  ${bmc_cert_content}
2208b70ddd5SRahul Maheshwari
2218b70ddd5SRahul Maheshwari    Upload And Activate Image  ${IMAGE_FILE_PATH}
2228b70ddd5SRahul Maheshwari    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
2238b70ddd5SRahul Maheshwari    OBMC Reboot (off)
2248b70ddd5SRahul Maheshwari    Verify Running BMC Image  ${IMAGE_FILE_PATH}
2258b70ddd5SRahul Maheshwari
2266a849ad2SRahul Maheshwari    Redfish.Login
2276a849ad2SRahul Maheshwari    ${bmc_cert_content}=  redfish_utils.Get Attribute
2286a849ad2SRahul Maheshwari    ...  ${REDFISH_CA_CERTIFICATE_URI}/${cert_id}  CertificateString
2298b70ddd5SRahul Maheshwari    Should Contain  ${cert_file_content}  ${bmc_cert_content}
2308b70ddd5SRahul Maheshwari
2316a849ad2SRahul Maheshwari    Redfish.Logout
2326a849ad2SRahul Maheshwari
2338b70ddd5SRahul Maheshwari
23477c6919bSSivas SRRTest Basic BMC Performance After Code Update
23577c6919bSSivas SRR    [Documentation]  Check performance of memory, CPU & file system of BMC.
23677c6919bSSivas SRR    [Tags]  Test_Basic_BMC_Performance_After_Code_Update
23777c6919bSSivas SRR
23877c6919bSSivas SRR    Open Connection And Log In
23977c6919bSSivas SRR    Check BMC Performance
24077c6919bSSivas SRR
241e8dc5253SCharles Paul Hofer
242c1fa2bc9SCharles Paul Hofer*** Keywords ***
243c1fa2bc9SCharles Paul Hofer
24497ecb270SGeorge KeishingTemporarily Set BMC Attribute
24597ecb270SGeorge Keishing    [Documentation]  Update the BMC attribute value.
24697ecb270SGeorge Keishing    [Arguments]  ${attribute_name}  ${attribute_value}
24797ecb270SGeorge Keishing
24897ecb270SGeorge Keishing    # Description of argument(s):
24997ecb270SGeorge Keishing    # attribute_name    BMC software attribute name (e.g. "Priority").
25097ecb270SGeorge Keishing    # attribute_value   Value to be written.
25197ecb270SGeorge Keishing
25297ecb270SGeorge Keishing    ${image_ids}=  Get Software Objects  ${VERSION_PURPOSE_BMC}
25397ecb270SGeorge Keishing    ${init_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
25497ecb270SGeorge Keishing    ${initial_priority}=  Set Variable  ${init_bmc_properties["Priority"]}
25597ecb270SGeorge Keishing
25697ecb270SGeorge Keishing    Set Host Software Property  ${image_ids[0]}  ${attribute_name}
25797ecb270SGeorge Keishing    ...  ${attribute_value}
25897ecb270SGeorge Keishing
25997ecb270SGeorge Keishing    ${cur_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
26097ecb270SGeorge Keishing    Should Be Equal As Integers  ${cur_bmc_properties["Priority"]}
26197ecb270SGeorge Keishing    ...  ${attribute_value}
26297ecb270SGeorge Keishing
26397ecb270SGeorge Keishing    # Revert to to initial value.
26497ecb270SGeorge Keishing    Set Host Software Property
26597ecb270SGeorge Keishing    ...  ${image_ids[0]}  ${attribute_name}  ${initial_priority}
26697ecb270SGeorge Keishing
26797ecb270SGeorge Keishing
268c1fa2bc9SCharles Paul HoferUpload And Activate Multiple BMC Images Setup
269c1fa2bc9SCharles Paul Hofer    [Documentation]  Check that the ALTERNATE_FILE_PATH variable is set.
270c1fa2bc9SCharles Paul Hofer
271c1fa2bc9SCharles Paul Hofer    Should Not Be Empty  ${ALTERNATE_IMAGE_FILE_PATH}
2721eb85f57SGeorge Keishing
273d66c5dceSCharles Paul Hofer
274d66c5dceSCharles Paul HoferREST BMC Code Update Teardown
275d66c5dceSCharles Paul Hofer    [Documentation]  Do code update test teardown.
276d66c5dceSCharles Paul Hofer
277d66c5dceSCharles Paul Hofer    FFDC On Test Case Fail
278d66c5dceSCharles Paul Hofer    Run Keyword If Test Failed  Fatal Error  msg=Code update failed.
279d66c5dceSCharles Paul Hofer
280d66c5dceSCharles Paul Hofer
281d66c5dceSCharles Paul HoferSuite Setup Execution
2821eb85f57SGeorge Keishing    [Documentation]  Do code update test case setup.
2831eb85f57SGeorge Keishing    # - Clean up all existing BMC dumps.
2841eb85f57SGeorge Keishing
285e78a4431SMichael Walsh    Run Key  Delete All Dumps  ignore=1
286b926408eSCharles Paul Hofer    Run Keyword And Ignore Error  Smart Power Off
2870071549eSGeorge Keishing
288d66c5dceSCharles Paul HoferTest Teardown Execution
2890071549eSGeorge Keishing    [Documentation]  Do code update test case teardown.
2900071549eSGeorge Keishing    # 1. Collect FFDC if test case failed.
2910071549eSGeorge Keishing    # 2. Collect FFDC if test PASS but error log exists.
2920071549eSGeorge Keishing
293d66c5dceSCharles Paul Hofer    # Don't delete our logs if we want to persist them for tests.
294d66c5dceSCharles Paul Hofer    Return From Keyword If  ${running_persistence_test}
295d66c5dceSCharles Paul Hofer
2960071549eSGeorge Keishing    FFDC On Test Case Fail
2970071549eSGeorge Keishing    Run Keyword If  '${TEST_STATUS}' == 'PASS'  Check Error And Collect FFDC
29877c6919bSSivas SRR    Close All Connections
299