xref: /openbmc/openbmc-test-automation/extended/code_update/bmc_code_update.robot (revision c81c6aeb2f630d534d8d9848654c90c0ffb58f45)
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
2209712a1eSGeorge KeishingForce Tags        BMC_Code_Update
2309712a1eSGeorge Keishing
249f74d3afSCharles Paul Hofer*** Variables ***
259f74d3afSCharles Paul Hofer
269f74d3afSCharles Paul Hofer${QUIET}                          ${1}
279f74d3afSCharles Paul Hofer${IMAGE_FILE_PATH}                ${EMPTY}
28c1fa2bc9SCharles Paul Hofer${ALTERNATE_IMAGE_FILE_PATH}      ${EMPTY}
29b7842a59SCharles Paul Hofer${SKIP_UPDATE_IF_ACTIVE}          false
30d66c5dceSCharles Paul Hofer${dump_id}                        ${EMPTY}
31d66c5dceSCharles Paul Hofer${running_persistence_test}       ${FALSE}
32d66c5dceSCharles Paul Hofer${test_errlog_text}               AutoTestSimple
339f74d3afSCharles Paul Hofer
349f74d3afSCharles Paul Hofer*** Test Cases ***
359f74d3afSCharles Paul Hofer
3677c6919bSSivas SRRTest Basic BMC Performance Before BMC Code Update
3777c6919bSSivas SRR    [Documentation]  Check performance of memory, CPU & file system of BMC.
3877c6919bSSivas SRR    [Tags]  Test_Basic_BMC_Performance_Before_BMC_Code_Update
3977c6919bSSivas SRR
4077c6919bSSivas SRR    Open Connection And Log In
4177c6919bSSivas SRR    Check BMC Performance
4277c6919bSSivas SRR
43d66c5dceSCharles Paul HoferPrepare Persistent Data
44d66c5dceSCharles Paul Hofer    [Documentation]  Set data that should persist across the code update.
45d66c5dceSCharles Paul Hofer    [Tags]  Prepare_Persistent_Data
46d66c5dceSCharles Paul Hofer
47d66c5dceSCharles Paul Hofer    # Install the debug tarball.
48d66c5dceSCharles Paul Hofer    BMC Execute Command  rm -rf /tmp/tarball
49d66c5dceSCharles Paul Hofer    Install Debug Tarball On BMC  tarball_file_path=${DEBUG_TARBALL_PATH}
50d66c5dceSCharles Paul Hofer
51d66c5dceSCharles Paul Hofer    # Create a dummy error log and dump.
52d66c5dceSCharles Paul Hofer    BMC Execute Command  /tmp/tarball/bin/logging-test -c ${test_errlog_text}
53d66c5dceSCharles Paul Hofer    ${dump_id}=  Create User Initiated Dump
54d66c5dceSCharles Paul Hofer    Check Dump Existence  ${dump_id}
55d66c5dceSCharles Paul Hofer    Set Suite Variable  ${dump_id}
56d66c5dceSCharles Paul Hofer
57d66c5dceSCharles Paul Hofer    # Set persistent settings.
58d66c5dceSCharles Paul Hofer    ${autoreboot_dict}=  Create Dictionary  data=${0}
59d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
60d66c5dceSCharles Paul Hofer    ...  data=${autoreboot_dict}
61d66c5dceSCharles Paul Hofer    ${onetime_dict}=  Create Dictionary  data=${0}
62d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
63d66c5dceSCharles Paul Hofer    ...  data=${onetime_dict}
64d66c5dceSCharles Paul Hofer
65d66c5dceSCharles Paul Hofer    # Let the remaining test cases know we are doing a persistence test so we
66d66c5dceSCharles Paul Hofer    # do not delete logs.
67d66c5dceSCharles Paul Hofer    Set Suite Variable  ${running_persistence_test}  ${TRUE}
68d66c5dceSCharles Paul Hofer
69d66c5dceSCharles Paul Hofer
709f74d3afSCharles Paul HoferREST BMC Code Update
719f74d3afSCharles Paul Hofer    [Documentation]  Do a BMC code update by uploading image on BMC via REST.
729f74d3afSCharles Paul Hofer    [Tags]  REST_BMC_Code_Update
73d66c5dceSCharles Paul Hofer    [Teardown]  REST BMC Code Update Teardown
749f74d3afSCharles Paul Hofer
758c7ada42SSweta Potthuri    Run Keyword And Ignore Error  List Installed Images  BMC
768c7ada42SSweta Potthuri
778010d867SGeorge Keishing    ${image_version}=  Get Version Tar  ${IMAGE_FILE_PATH}
78*c81c6aebSMichael Walsh    ${bmc_release_info}=  Get BMC Release Info
79*c81c6aebSMichael Walsh    ${functional_version}=  Set Variable  ${bmc_release_info['version_id']}
80*c81c6aebSMichael Walsh    Rprint Vars  image_version  functional_version
818010d867SGeorge Keishing
82c23d4247SGeorge Keishing    # TODO: openbmc/phosphor-bmc-code-mgmt/issues/4
838010d867SGeorge Keishing    # Check if the existing firmware is functional.
84*c81c6aebSMichael Walsh    Pass Execution If  '${functional_version}' == '${image_version}'
85*c81c6aebSMichael Walsh    ...  The existing ${image_version} firmware is already functional.
868010d867SGeorge Keishing
8721845469SCharles Paul Hofer    Upload And Activate Image  ${IMAGE_FILE_PATH}
8821845469SCharles Paul Hofer    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
899f74d3afSCharles Paul Hofer    OBMC Reboot (off)
90e43fb2f7SCharles Paul Hofer    Verify Running BMC Image  ${IMAGE_FILE_PATH}
91da339e6cSSivas SRR    BMC Execute Command  cd /etc ; cat host.conf hosts hostname  print_out=1
929f74d3afSCharles Paul Hofer
939f74d3afSCharles Paul Hofer
94d66c5dceSCharles Paul HoferVerify Error Log Persistency
95d66c5dceSCharles Paul Hofer    [Documentation]  Check that the error log is still present after a
96d66c5dceSCharles Paul Hofer    ...              code update.
97d66c5dceSCharles Paul Hofer    [Tags]  Verify_Error_Log_Persistency
98d66c5dceSCharles Paul Hofer
99a8800da7SSteven Sombar    ${error_log_paths}=  Read Properties  ${BMC_LOGGING_ENTRY}list
100d66c5dceSCharles Paul Hofer    Log To Console  ${error_log_paths}
101d66c5dceSCharles Paul Hofer    ${test_error_message}=  Read Attribute  @{error_log_paths}[-1]  Message
102d66c5dceSCharles Paul Hofer    Should Be Equal  ${test_error_message}
103d66c5dceSCharles Paul Hofer    ...  example.xyz.openbmc_project.Example.Elog.${test_errlog_text}
104d66c5dceSCharles Paul Hofer    Delete Error Log Entry  @{error_log_paths}[-1]
105d66c5dceSCharles Paul Hofer
106d66c5dceSCharles Paul Hofer
107d66c5dceSCharles Paul HoferVerify BMC Dump Persistency
108d66c5dceSCharles Paul Hofer    [Documentation]  Check that the BMC dump present after a code update.
109d66c5dceSCharles Paul Hofer    [Tags]  Verify_BMC_Dump_Persistency
110d66c5dceSCharles Paul Hofer    [Teardown]  Set Suite Variable  ${running_persistence_test}  ${FALSE}
111d66c5dceSCharles Paul Hofer
112d66c5dceSCharles Paul Hofer    Check Dump Existence  ${dump_id}
113d66c5dceSCharles Paul Hofer    Delete BMC Dump  ${dump_id}
114d66c5dceSCharles Paul Hofer
115d66c5dceSCharles Paul Hofer
116d66c5dceSCharles Paul HoferVerify Settings Persistency
117d66c5dceSCharles Paul Hofer    [Documentation]  Verify that the settings from 'Prepare Persistent Data'
118d66c5dceSCharles Paul Hofer    ...              are still set correctly after the code update.
119d66c5dceSCharles Paul Hofer    [Tags]  Verify_Settings_Persistency
120d66c5dceSCharles Paul Hofer
121d66c5dceSCharles Paul Hofer    ${autoreboot_enabled}=  Read Attribute  ${CONTROL_HOST_URI}auto_reboot
122d66c5dceSCharles Paul Hofer    ...  AutoReboot
123d66c5dceSCharles Paul Hofer    Should Be Equal  ${autoreboot_enabled}  ${0}
124d66c5dceSCharles Paul Hofer    ${onetime_enabled}=  Read Attribute  ${CONTROL_HOST_URI}boot/one_time
125d66c5dceSCharles Paul Hofer    ...  Enabled
126d66c5dceSCharles Paul Hofer    Should Be Equal  ${onetime_enabled}  ${0}
127d66c5dceSCharles Paul Hofer
128d66c5dceSCharles Paul Hofer    # Set values back to their defaults
129d66c5dceSCharles Paul Hofer    ${autoreboot_dict}=  Create Dictionary  data=${1}
130d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
131d66c5dceSCharles Paul Hofer    ...  data=${autoreboot_dict}
132d66c5dceSCharles Paul Hofer    ${onetime_dict}=  Create Dictionary  data=${1}
133d66c5dceSCharles Paul Hofer    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
134d66c5dceSCharles Paul Hofer    ...  data=${onetime_dict}
135d66c5dceSCharles Paul Hofer
136d66c5dceSCharles Paul Hofer
137c1fa2bc9SCharles Paul HoferUpload And Activate Multiple BMC Images
138c1fa2bc9SCharles Paul Hofer    [Documentation]  Upload another BMC image and verify that its state is
139c1fa2bc9SCharles Paul Hofer    ...              different from all others.
140c1fa2bc9SCharles Paul Hofer    [Tags]  Upload_And_Activate_Multiple_BMC_Images
141c1fa2bc9SCharles Paul Hofer    [Template]  Activate Image And Verify No Duplicate Priorities
142c1fa2bc9SCharles Paul Hofer    [Setup]  Upload And Activate Multiple BMC Images Setup
143c1fa2bc9SCharles Paul Hofer
144c1fa2bc9SCharles Paul Hofer    # Image File Path              Image Purpose
145c1fa2bc9SCharles Paul Hofer    ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_BMC}
146c1fa2bc9SCharles Paul Hofer
147c1fa2bc9SCharles Paul Hofer
14842f17468SCharles Paul HoferBMC Set Priority To Invalid Values
14942f17468SCharles Paul Hofer    [Documentation]  Attempt to set the priority of an image to an invalid
15042f17468SCharles Paul Hofer    ...              value and expect an error.
15142f17468SCharles Paul Hofer    [Tags]  BMC_Set_Priority_To_Invalid_Values
15242f17468SCharles Paul Hofer    [Template]  Set Priority To Invalid Value And Expect Error
15342f17468SCharles Paul Hofer
15442f17468SCharles Paul Hofer    # Version Type              Priority
15542f17468SCharles Paul Hofer    ${VERSION_PURPOSE_BMC}     ${-1}
15642f17468SCharles Paul Hofer    ${VERSION_PURPOSE_BMC}     ${256}
15742f17468SCharles Paul Hofer
15842f17468SCharles Paul Hofer
1599f74d3afSCharles Paul HoferDelete BMC Image
1609f74d3afSCharles Paul Hofer    [Documentation]  Delete a BMC image from the BMC flash chip.
1619f74d3afSCharles Paul Hofer    [Tags]  Delete_BMC_Image
1629f74d3afSCharles Paul Hofer
1639f74d3afSCharles Paul Hofer    ${software_object}=  Get Non Running BMC Software Object
1649f74d3afSCharles Paul Hofer    Delete Image And Verify  ${software_object}  ${VERSION_PURPOSE_BMC}
165c1fa2bc9SCharles Paul Hofer
166c1fa2bc9SCharles Paul Hofer
16797ecb270SGeorge KeishingBMC Image Priority Attribute Test
16897ecb270SGeorge Keishing    [Documentation]  Set "Priority" attribute.
16997ecb270SGeorge Keishing    [Tags]  BMC_Image_Priority_Attribute_Test
17097ecb270SGeorge Keishing    [Template]  Temporarily Set BMC Attribute
17197ecb270SGeorge Keishing
17297ecb270SGeorge Keishing    # Property        Value
173872d69faSGeorge Keishing    Priority          ${False}
174872d69faSGeorge Keishing    Priority          ${True}
17597ecb270SGeorge Keishing    Priority          ${0}
17697ecb270SGeorge Keishing    Priority          ${1}
17797ecb270SGeorge Keishing    Priority          ${127}
17897ecb270SGeorge Keishing    Priority          ${255}
17997ecb270SGeorge Keishing
18097ecb270SGeorge Keishing
181e8dc5253SCharles Paul HoferDelete All Non Running BMC Images
182e8dc5253SCharles Paul Hofer    [Documentation]  Delete all non running BMC images.
183e8dc5253SCharles Paul Hofer    [Tags]  Delete_All_Non_Running_BMC_Images
184e8dc5253SCharles Paul Hofer
185e8dc5253SCharles Paul Hofer    ${version_id}=  Upload And Activate Image  ${ALTERNATE_IMAGE_FILE_PATH}
1860889d43bSGeorge Keishing    ...  skip_if_active=true
187e8dc5253SCharles Paul Hofer    Delete All Non Running BMC Images
188e8dc5253SCharles Paul Hofer
189e8dc5253SCharles Paul Hofer    ${software_ids}=  Get Software Objects Id
190e8dc5253SCharles Paul Hofer    ...  version_type=${VERSION_PURPOSE_BMC}
191e8dc5253SCharles Paul Hofer    Should Not Contain  ${software_ids}  ${version_id}
192e8dc5253SCharles Paul Hofer
1931659f59eSGeorge Keishing
1948b70ddd5SRahul MaheshwariTest Certificate Persistency After BMC Code Update
1958b70ddd5SRahul Maheshwari    [Documentation]  Test certificate persistency after BMC update.
1968b70ddd5SRahul Maheshwari    [Tags]  Test_Certificate_Persistency_After_BMC_Code_Update
1978b70ddd5SRahul Maheshwari
198fa146c43SRahul Maheshwari    # Create certificate sub-directory in current working directory.
199fa146c43SRahul Maheshwari    Create Directory  certificate_dir
200fa146c43SRahul Maheshwari    OperatingSystem.Directory Should Exist  ${EXECDIR}${/}certificate_dir
201fa146c43SRahul Maheshwari
2028b70ddd5SRahul Maheshwari    ${cert_file_path}=  Generate Certificate File Via Openssl
2038b70ddd5SRahul Maheshwari    ...  Valid Certificate Valid Privatekey
2048b70ddd5SRahul Maheshwari    ${file_data}=  OperatingSystem.Get Binary File  ${cert_file_path}
2058b70ddd5SRahul Maheshwari    ${cert_file_content}=  OperatingSystem.Get File  ${cert_file_path}
2068b70ddd5SRahul Maheshwari
2076a849ad2SRahul Maheshwari    Redfish.Login
2086a849ad2SRahul Maheshwari    ${cert_id}=  Install Certificate File On BMC  ${REDFISH_CA_CERTIFICATE_URI}  ok  data=${file_data}
2096a849ad2SRahul Maheshwari    Logging  Installed certificate id: ${cert_id}
2108b70ddd5SRahul Maheshwari
2116a849ad2SRahul Maheshwari    # Adding delay after certificate installation.
2126a849ad2SRahul Maheshwari    Sleep  30s
2136a849ad2SRahul Maheshwari
2146a849ad2SRahul Maheshwari    ${bmc_cert_content}=  redfish_utils.Get Attribute
2156a849ad2SRahul Maheshwari    ...  /redfish/v1/Managers/bmc/Truststore/Certificates/${cert_id}  CertificateString
2168b70ddd5SRahul Maheshwari    Should Contain  ${cert_file_content}  ${bmc_cert_content}
2178b70ddd5SRahul Maheshwari
2188b70ddd5SRahul Maheshwari    Upload And Activate Image  ${IMAGE_FILE_PATH}
2198b70ddd5SRahul Maheshwari    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
2208b70ddd5SRahul Maheshwari    OBMC Reboot (off)
2218b70ddd5SRahul Maheshwari    Verify Running BMC Image  ${IMAGE_FILE_PATH}
2228b70ddd5SRahul Maheshwari
2236a849ad2SRahul Maheshwari    Redfish.Login
2246a849ad2SRahul Maheshwari    ${bmc_cert_content}=  redfish_utils.Get Attribute
2256a849ad2SRahul Maheshwari    ...  ${REDFISH_CA_CERTIFICATE_URI}/${cert_id}  CertificateString
2268b70ddd5SRahul Maheshwari    Should Contain  ${cert_file_content}  ${bmc_cert_content}
2278b70ddd5SRahul Maheshwari
2286a849ad2SRahul Maheshwari    Redfish.Logout
2296a849ad2SRahul Maheshwari
2308b70ddd5SRahul Maheshwari
23177c6919bSSivas SRRTest Basic BMC Performance After Code Update
23277c6919bSSivas SRR    [Documentation]  Check performance of memory, CPU & file system of BMC.
23377c6919bSSivas SRR    [Tags]  Test_Basic_BMC_Performance_After_Code_Update
23477c6919bSSivas SRR
23577c6919bSSivas SRR    Open Connection And Log In
23677c6919bSSivas SRR    Check BMC Performance
23777c6919bSSivas SRR
238e8dc5253SCharles Paul Hofer
239c1fa2bc9SCharles Paul Hofer*** Keywords ***
240c1fa2bc9SCharles Paul Hofer
24197ecb270SGeorge KeishingTemporarily Set BMC Attribute
24297ecb270SGeorge Keishing    [Documentation]  Update the BMC attribute value.
24397ecb270SGeorge Keishing    [Arguments]  ${attribute_name}  ${attribute_value}
24497ecb270SGeorge Keishing
24597ecb270SGeorge Keishing    # Description of argument(s):
24697ecb270SGeorge Keishing    # attribute_name    BMC software attribute name (e.g. "Priority").
24797ecb270SGeorge Keishing    # attribute_value   Value to be written.
24897ecb270SGeorge Keishing
24997ecb270SGeorge Keishing    ${image_ids}=  Get Software Objects  ${VERSION_PURPOSE_BMC}
25097ecb270SGeorge Keishing    ${init_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
25197ecb270SGeorge Keishing    ${initial_priority}=  Set Variable  ${init_bmc_properties["Priority"]}
25297ecb270SGeorge Keishing
25397ecb270SGeorge Keishing    Set Host Software Property  ${image_ids[0]}  ${attribute_name}
25497ecb270SGeorge Keishing    ...  ${attribute_value}
25597ecb270SGeorge Keishing
25697ecb270SGeorge Keishing    ${cur_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
25797ecb270SGeorge Keishing    Should Be Equal As Integers  ${cur_bmc_properties["Priority"]}
25897ecb270SGeorge Keishing    ...  ${attribute_value}
25997ecb270SGeorge Keishing
26097ecb270SGeorge Keishing    # Revert to to initial value.
26197ecb270SGeorge Keishing    Set Host Software Property
26297ecb270SGeorge Keishing    ...  ${image_ids[0]}  ${attribute_name}  ${initial_priority}
26397ecb270SGeorge Keishing
26497ecb270SGeorge Keishing
265c1fa2bc9SCharles Paul HoferUpload And Activate Multiple BMC Images Setup
266c1fa2bc9SCharles Paul Hofer    [Documentation]  Check that the ALTERNATE_FILE_PATH variable is set.
267c1fa2bc9SCharles Paul Hofer
268c1fa2bc9SCharles Paul Hofer    Should Not Be Empty  ${ALTERNATE_IMAGE_FILE_PATH}
2691eb85f57SGeorge Keishing
270d66c5dceSCharles Paul Hofer
271d66c5dceSCharles Paul HoferREST BMC Code Update Teardown
272d66c5dceSCharles Paul Hofer    [Documentation]  Do code update test teardown.
273d66c5dceSCharles Paul Hofer
274d66c5dceSCharles Paul Hofer    FFDC On Test Case Fail
275d66c5dceSCharles Paul Hofer    Run Keyword If Test Failed  Fatal Error  msg=Code update failed.
276d66c5dceSCharles Paul Hofer
277d66c5dceSCharles Paul Hofer
278d66c5dceSCharles Paul HoferSuite Setup Execution
2791eb85f57SGeorge Keishing    [Documentation]  Do code update test case setup.
2801eb85f57SGeorge Keishing    # - Clean up all existing BMC dumps.
2811eb85f57SGeorge Keishing
282e78a4431SMichael Walsh    Run Key  Delete All Dumps  ignore=1
283b926408eSCharles Paul Hofer    Run Keyword And Ignore Error  Smart Power Off
2840071549eSGeorge Keishing
285d66c5dceSCharles Paul HoferTest Teardown Execution
2860071549eSGeorge Keishing    [Documentation]  Do code update test case teardown.
2870071549eSGeorge Keishing    # 1. Collect FFDC if test case failed.
2880071549eSGeorge Keishing    # 2. Collect FFDC if test PASS but error log exists.
2890071549eSGeorge Keishing
290d66c5dceSCharles Paul Hofer    # Don't delete our logs if we want to persist them for tests.
291d66c5dceSCharles Paul Hofer    Return From Keyword If  ${running_persistence_test}
292d66c5dceSCharles Paul Hofer
2930071549eSGeorge Keishing    FFDC On Test Case Fail
2940071549eSGeorge Keishing    Run Keyword If  '${TEST_STATUS}' == 'PASS'  Check Error And Collect FFDC
29577c6919bSSivas SRR    Close All Connections
296