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