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