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    ${bmc_release_info}=  Get BMC Release Info
79    ${functional_version}=  Set Variable  ${bmc_release_info['version_id']}
80    Rprint Vars  image_version  functional_version
81
82    # Check if the existing firmware is functional.
83    Pass Execution If  '${functional_version}' == '${image_version}'
84    ...  The existing ${image_version} firmware is already functional.
85
86    Upload And Activate Image  ${IMAGE_FILE_PATH}
87    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
88    OBMC Reboot (off)
89    Verify Running BMC Image  ${IMAGE_FILE_PATH}
90    BMC Execute Command  cd /etc ; cat host.conf hosts hostname  print_out=1
91
92
93Verify Error Log Persistency
94    [Documentation]  Check that the error log is still present after a
95    ...              code update.
96    [Tags]  Verify_Error_Log_Persistency
97
98    ${error_log_paths}=  Read Properties  ${BMC_LOGGING_ENTRY}list
99    Log To Console  ${error_log_paths}
100    ${test_error_message}=  Read Attribute  @{error_log_paths}[-1]  Message
101    Should Be Equal  ${test_error_message}
102    ...  example.xyz.openbmc_project.Example.Elog.${test_errlog_text}
103    Delete Error Log Entry  @{error_log_paths}[-1]
104
105
106Verify BMC Dump Persistency
107    [Documentation]  Check that the BMC dump present after a code update.
108    [Tags]  Verify_BMC_Dump_Persistency
109    [Teardown]  Set Suite Variable  ${running_persistence_test}  ${FALSE}
110
111    Check Dump Existence  ${dump_id}
112    Delete BMC Dump  ${dump_id}
113
114
115Verify Settings Persistency
116    [Documentation]  Verify that the settings from 'Prepare Persistent Data'
117    ...              are still set correctly after the code update.
118    [Tags]  Verify_Settings_Persistency
119
120    ${autoreboot_enabled}=  Read Attribute  ${CONTROL_HOST_URI}auto_reboot
121    ...  AutoReboot
122    Should Be Equal  ${autoreboot_enabled}  ${0}
123    ${onetime_enabled}=  Read Attribute  ${CONTROL_HOST_URI}boot/one_time
124    ...  Enabled
125    Should Be Equal  ${onetime_enabled}  ${0}
126
127    # Set values back to their defaults
128    ${autoreboot_dict}=  Create Dictionary  data=${1}
129    Write Attribute  ${CONTROL_HOST_URI}auto_reboot  AutoReboot
130    ...  data=${autoreboot_dict}
131    ${onetime_dict}=  Create Dictionary  data=${1}
132    Write Attribute  ${CONTROL_HOST_URI}boot/one_time  Enabled
133    ...  data=${onetime_dict}
134
135
136Upload And Activate Multiple BMC Images
137    [Documentation]  Upload another BMC image and verify that its state is
138    ...              different from all others.
139    [Tags]  Upload_And_Activate_Multiple_BMC_Images
140    [Template]  Activate Image And Verify No Duplicate Priorities
141    [Setup]  Upload And Activate Multiple BMC Images Setup
142
143    # Image File Path              Image Purpose
144    ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_BMC}
145
146
147BMC Set Priority To Invalid Values
148    [Documentation]  Attempt to set the priority of an image to an invalid
149    ...              value and expect an error.
150    [Tags]  BMC_Set_Priority_To_Invalid_Values
151    [Template]  Set Priority To Invalid Value And Expect Error
152
153    # Version Type              Priority
154    ${VERSION_PURPOSE_BMC}     ${-1}
155    ${VERSION_PURPOSE_BMC}     ${256}
156
157
158Delete BMC Image
159    [Documentation]  Delete a BMC image from the BMC flash chip.
160    [Tags]  Delete_BMC_Image
161
162    ${software_object}=  Get Non Running BMC Software Object
163    Delete Image And Verify  ${software_object}  ${VERSION_PURPOSE_BMC}
164
165
166BMC Image Priority Attribute Test
167    [Documentation]  Set "Priority" attribute.
168    [Tags]  BMC_Image_Priority_Attribute_Test
169    [Template]  Temporarily Set BMC Attribute
170
171    # Property        Value
172    Priority          ${False}
173    Priority          ${True}
174    Priority          ${0}
175    Priority          ${1}
176    Priority          ${127}
177    Priority          ${255}
178
179
180Delete All Non Running BMC Images
181    [Documentation]  Delete all non running BMC images.
182    [Tags]  Delete_All_Non_Running_BMC_Images
183
184    ${version_id}=  Upload And Activate Image  ${ALTERNATE_IMAGE_FILE_PATH}
185    ...  skip_if_active=true
186    Delete All Non Running BMC Images
187
188    ${software_ids}=  Get Software Objects Id
189    ...  version_type=${VERSION_PURPOSE_BMC}
190    Should Not Contain  ${software_ids}  ${version_id}
191
192
193Test Certificate Persistency After BMC Code Update
194    [Documentation]  Test certificate persistency after BMC update.
195    [Tags]  Test_Certificate_Persistency_After_BMC_Code_Update
196
197    # Create certificate sub-directory in current working directory.
198    Create Directory  certificate_dir
199    OperatingSystem.Directory Should Exist  ${EXECDIR}${/}certificate_dir
200
201    ${cert_file_path}=  Generate Certificate File Via Openssl
202    ...  Valid Certificate Valid Privatekey
203    ${file_data}=  OperatingSystem.Get Binary File  ${cert_file_path}
204    ${cert_file_content}=  OperatingSystem.Get File  ${cert_file_path}
205
206    Redfish.Login
207    ${cert_id}=  Install Certificate File On BMC  ${REDFISH_CA_CERTIFICATE_URI}  ok  data=${file_data}
208    Logging  Installed certificate id: ${cert_id}
209
210    # Adding delay after certificate installation.
211    Sleep  30s
212
213    ${bmc_cert_content}=  redfish_utils.Get Attribute
214    ...  /redfish/v1/Managers/bmc/Truststore/Certificates/${cert_id}  CertificateString
215    Should Contain  ${cert_file_content}  ${bmc_cert_content}
216
217    Upload And Activate Image  ${IMAGE_FILE_PATH}
218    ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
219    OBMC Reboot (off)
220    Verify Running BMC Image  ${IMAGE_FILE_PATH}
221
222    Redfish.Login
223    ${bmc_cert_content}=  redfish_utils.Get Attribute
224    ...  ${REDFISH_CA_CERTIFICATE_URI}/${cert_id}  CertificateString
225    Should Contain  ${cert_file_content}  ${bmc_cert_content}
226
227    Redfish.Logout
228
229
230Test Basic BMC Performance After Code Update
231    [Documentation]  Check performance of memory, CPU & file system of BMC.
232    [Tags]  Test_Basic_BMC_Performance_After_Code_Update
233
234    Open Connection And Log In
235    Check BMC Performance
236
237
238*** Keywords ***
239
240Temporarily Set BMC Attribute
241    [Documentation]  Update the BMC attribute value.
242    [Arguments]  ${attribute_name}  ${attribute_value}
243
244    # Description of argument(s):
245    # attribute_name    BMC software attribute name (e.g. "Priority").
246    # attribute_value   Value to be written.
247
248    ${image_ids}=  Get Software Objects  ${VERSION_PURPOSE_BMC}
249    ${init_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
250    ${initial_priority}=  Set Variable  ${init_bmc_properties["Priority"]}
251
252    Set Host Software Property  ${image_ids[0]}  ${attribute_name}
253    ...  ${attribute_value}
254
255    ${cur_bmc_properties}=  Get Host Software Property  ${image_ids[0]}
256    Should Be Equal As Integers  ${cur_bmc_properties["Priority"]}
257    ...  ${attribute_value}
258
259    # Revert to to initial value.
260    Set Host Software Property
261    ...  ${image_ids[0]}  ${attribute_name}  ${initial_priority}
262
263
264Upload And Activate Multiple BMC Images Setup
265    [Documentation]  Check that the ALTERNATE_FILE_PATH variable is set.
266
267    Should Not Be Empty  ${ALTERNATE_IMAGE_FILE_PATH}
268
269
270REST BMC Code Update Teardown
271    [Documentation]  Do code update test teardown.
272
273    FFDC On Test Case Fail
274    Run Keyword If Test Failed  Fatal Error  msg=Code update failed.
275
276
277Suite Setup Execution
278    [Documentation]  Do code update test case setup.
279    # - Clean up all existing BMC dumps.
280
281    Run Key  Delete All Dumps  ignore=1
282    Run Keyword And Ignore Error  Smart Power Off
283
284Test Teardown Execution
285    [Documentation]  Do code update test case teardown.
286    # 1. Collect FFDC if test case failed.
287    # 2. Collect FFDC if test PASS but error log exists.
288
289    # Don't delete our logs if we want to persist them for tests.
290    Return From Keyword If  ${running_persistence_test}
291
292    FFDC On Test Case Fail
293    Run Keyword If  '${TEST_STATUS}' == 'PASS'  Check Error And Collect FFDC
294    Close All Connections
295