xref: /openbmc/openbmc-test-automation/extended/code_update/bmc_code_update.robot (revision d66c5dce3125bfa10efa5b5324ddd07f5e24ee2f)
1*** Settings ***
2Documentation     Update the BMC code on a target BMC.
3...               Execution Method:
4...               python -m robot -v OPENBMC_HOST:<hostname>
5...               -v IMAGE_FILE_PATH:<path/*.tar>  bmc_code_update.robot
6
7Library           ../../lib/code_update_utils.py
8Variables         ../../data/variables.py
9Resource          ../../lib/boot_utils.robot
10Resource          code_update_utils.robot
11Resource          ../../lib/code_update_utils.robot
12Resource          ../../lib/openbmc_ffdc.robot
13Resource          ../../lib/dump_utils.robot
14
15Suite Setup       Suite Setup Execution
16
17Test Teardown     Test Teardown Execution
18
19Force Tags        BMC_Code_Update
20
21*** Variables ***
22
23${QUIET}                          ${1}
24${IMAGE_FILE_PATH}                ${EMPTY}
25${ALTERNATE_IMAGE_FILE_PATH}      ${EMPTY}
26${SKIP_UPDATE_IF_ACTIVE}          false
27${dump_id}                        ${EMPTY}
28${running_persistence_test}       ${FALSE}
29${test_errlog_text}               AutoTestSimple
30
31*** Test Cases ***
32
33Prepare Persistent Data
34    [Documentation]  Set data that should persist across the code update.
35    [Tags]  Prepare_Persistent_Data
36
37    # Install the debug tarball.
38    BMC Execute Command  rm -rf /tmp/tarball
39    Install Debug Tarball On BMC  tarball_file_path=${DEBUG_TARBALL_PATH}
40
41    # Create a dummy error log and dump.
42    BMC Execute Command  /tmp/tarball/bin/logging-test -c ${test_errlog_text}
43    ${dump_id}=  Create User Initiated Dump
44    Check Dump Existence  ${dump_id}
45    Set Suite Variable  ${dump_id}
46
47    # Set persistent settings.
48    ${autoreboot_dict}=  Create Dictionary  data=${0}
49    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
50    ...  data=${autoreboot_dict}
51    ${onetime_dict}=  Create Dictionary  data=${0}
52    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
53    ...  data=${onetime_dict}
54
55    # Let the remaining test cases know we are doing a persistence test so we
56    # do not delete logs.
57    Set Suite Variable  ${running_persistence_test}  ${TRUE}
58
59
60REST BMC Code Update
61    [Documentation]  Do a BMC code update by uploading image on BMC via REST.
62    [Tags]  REST_BMC_Code_Update
63    [Teardown]  REST BMC Code Update Teardown
64
65    Upload And Activate Image  ${IMAGE_FILE_PATH}
66    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
67    OBMC Reboot (off)
68    Verify Running BMC Image  ${IMAGE_FILE_PATH}
69
70
71Verify Error Log Persistency
72    [Documentation]  Check that the error log is still present after a
73    ...              code update.
74    [Tags]  Verify_Error_Log_Persistency
75
76    ${error_log_paths}=  Read Properties  ${BMC_LOGGING_URI}/list
77    Log To Console  ${error_log_paths}
78    ${test_error_message}=  Read Attribute  @{error_log_paths}[-1]  Message
79    Should Be Equal  ${test_error_message}
80    ...  example.xyz.openbmc_project.Example.Elog.${test_errlog_text}
81    Delete Error Log Entry  @{error_log_paths}[-1]
82
83
84Verify BMC Dump Persistency
85    [Documentation]  Check that the BMC dump present after a code update.
86    [Tags]  Verify_BMC_Dump_Persistency
87    [Teardown]  Set Suite Variable  ${running_persistence_test}  ${FALSE}
88
89    Check Dump Existence  ${dump_id}
90    Delete BMC Dump  ${dump_id}
91
92
93Verify Settings Persistency
94    [Documentation]  Verify that the settings from 'Prepare Persistent Data'
95    ...              are still set correctly after the code update.
96    [Tags]  Verify_Settings_Persistency
97
98    ${autoreboot_enabled}=  Read Attribute  ${CONTROL_HOST_URI}auto_reboot
99    ...  AutoReboot
100    Should Be Equal  ${autoreboot_enabled}  ${0}
101    ${onetime_enabled}=  Read Attribute  ${CONTROL_HOST_URI}boot/one_time
102    ...  Enabled
103    Should Be Equal  ${onetime_enabled}  ${0}
104
105    # Set values back to their defaults
106    ${autoreboot_dict}=  Create Dictionary  data=${1}
107    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
108    ...  data=${autoreboot_dict}
109    ${onetime_dict}=  Create Dictionary  data=${1}
110    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
111    ...  data=${onetime_dict}
112
113
114Upload And Activate Multiple BMC Images
115    [Documentation]  Upload another BMC image and verify that its state is
116    ...              different from all others.
117    [Tags]  Upload_And_Activate_Multiple_BMC_Images
118    [Template]  Activate Image And Verify No Duplicate Priorities
119    [Setup]  Upload And Activate Multiple BMC Images Setup
120
121    # Image File Path              Image Purpose
122    ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_BMC}
123
124
125BMC Set Priority To Invalid Values
126    [Documentation]  Attempt to set the priority of an image to an invalid
127    ...              value and expect an error.
128    [Tags]  BMC_Set_Priority_To_Invalid_Values
129    [Template]  Set Priority To Invalid Value And Expect Error
130
131    # Version Type              Priority
132    ${VERSION_PURPOSE_BMC}     ${-1}
133    ${VERSION_PURPOSE_BMC}     ${256}
134
135
136Delete BMC Image
137    [Documentation]  Delete a BMC image from the BMC flash chip.
138    [Tags]  Delete_BMC_Image
139
140    ${software_object}=  Get Non Running BMC Software Object
141    Delete Image And Verify  ${software_object}  ${VERSION_PURPOSE_BMC}
142
143
144BMC Image Priority Attribute Test
145    [Documentation]  Set "Priority" attribute.
146    [Tags]  BMC_Image_Priority_Attribute_Test
147    [Template]  Temporarily Set BMC Attribute
148
149    # Property        Value
150    Priority          ${0}
151    Priority          ${1}
152    Priority          ${127}
153    Priority          ${255}
154
155
156Delete All Non Running BMC Images
157    [Documentation]  Delete all non running BMC images.
158    [Tags]  Delete_All_Non_Running_BMC_Images
159
160    ${version_id}=  Upload And Activate Image  ${ALTERNATE_IMAGE_FILE_PATH}
161    Delete All Non Running BMC Images
162
163    ${software_ids}=  Get Software Objects Id
164    ...  version_type=${VERSION_PURPOSE_BMC}
165    Should Not Contain  ${software_ids}  ${version_id}
166
167
168*** Keywords ***
169
170Temporarily Set BMC Attribute
171    [Documentation]  Update the BMC attribute value.
172    [Arguments]  ${attribute_name}  ${attribute_value}
173
174    # Description of argument(s):
175    # attribute_name    BMC software attribute name (e.g. "Priority").
176    # attribute_value   Value to be written.
177
178    ${image_ids}=  Get Software Objects  ${VERSION_PURPOSE_BMC}
179    ${init_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
180    ${initial_priority}=  Set Variable  ${init_bmc_properties["Priority"]}
181
182    Set Host Software Property  ${image_ids[0]}  ${attribute_name}
183    ...  ${attribute_value}
184
185    ${cur_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
186    Should Be Equal As Integers  ${cur_bmc_properties["Priority"]}
187    ...  ${attribute_value}
188
189    # Revert to to initial value.
190    Set Host Software Property
191    ...  ${image_ids[0]}  ${attribute_name}  ${initial_priority}
192
193
194Upload And Activate Multiple BMC Images Setup
195    [Documentation]  Check that the ALTERNATE_FILE_PATH variable is set.
196
197    Should Not Be Empty  ${ALTERNATE_IMAGE_FILE_PATH}
198
199
200REST BMC Code Update Teardown
201    [Documentation]  Do code update test teardown.
202
203    FFDC On Test Case Fail
204    Run Keyword If Test Failed  Fatal Error  msg=Code update failed.
205
206
207Suite Setup Execution
208    [Documentation]  Do code update test case setup.
209    # - Clean up all existing BMC dumps.
210
211    Delete All Dumps
212    Run Keyword And Ignore Error  Smart Power Off
213
214Test Teardown Execution
215    [Documentation]  Do code update test case teardown.
216    # 1. Collect FFDC if test case failed.
217    # 2. Collect FFDC if test PASS but error log exists.
218
219    # Don't delete our logs if we want to persist them for tests.
220    Return From Keyword If  ${running_persistence_test}
221
222    FFDC On Test Case Fail
223    Run Keyword If  '${TEST_STATUS}' == 'PASS'  Check Error And Collect FFDC
224