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