xref: /openbmc/openbmc-test-automation/extended/code_update/host_code_update.robot (revision 7c6e7520f344f75665c1f5a71e531e408bc50de8)
1*** Settings ***
2Documentation     Update the PNOR code on a target BMC.
3...               Execution Method:
4...               python -m robot -v OPENBMC_HOST:<hostname>
5...               -v DELETE_OLD_PNOR_IMAGES:<"true" or "false">
6...               -v IMAGE_FILE_PATH:<path/*.tar>
7...               -v ALTERNATE_IMAGE_FILE_PATH:<path/*.tar>
8...               host_code_update.robot
9...
10...               Code update method BMC
11...               Update work flow sequence:
12...                 - Upload image via REST
13...                 - Verify that the file exists on the BMC
14...                 - Check that software "Activation" is set to "Ready"
15...                 - Set "Requested Activation" to "Active"
16...                 - Wait for code update to complete
17...                 - Verify the new version
18
19Library           ../../lib/bmc_ssh_utils.py
20Library           ../../lib/code_update_utils.py
21Variables         ../../data/variables.py
22Resource          ../../lib/boot_utils.robot
23Resource          code_update_utils.robot
24Resource          ../../lib/code_update_utils.robot
25Resource          ../../lib/openbmc_ffdc.robot
26Resource          ../../lib/state_manager.robot
27Resource          ../../lib/dump_utils.robot
28
29Test Teardown     Code Update Test Teardown
30
31Force Tags        Host_Code_Update
32
33*** Variables ***
34
35${QUIET}                          ${1}
36${IMAGE_FILE_PATH}                ${EMPTY}
37${DELETE_OLD_PNOR_IMAGES}         false
38${DELETE_OLD_GUARD_FILE}          false
39${ALTERNATE_IMAGE_FILE_PATH}      ${EMPTY}
40
41*** Test Cases ***
42
43REST Host Code Update
44    [Documentation]  Do a PNOR code update by uploading image on BMC via REST.
45    # 1. Delete error logs if there is any.
46    # 1. Do code update.
47    # 2. Do post update the following:
48    #    - Collect FFDC if error log exist and delete error logs.
49    [Tags]  REST_Host_Code_Update
50    [Setup]  Code Update Setup
51
52    Upload And Activate Image  ${IMAGE_FILE_PATH}
53    OBMC Reboot (off)
54
55
56Post Update Boot To OS
57    [Documentation]  Boot the host OS
58    [Tags]  Post_Update_Boot_To_OS
59    [Setup]  Start SOL Console Logging
60    [Teardown]  Run Keywords  Stop SOL Console Logging
61    ...         AND  Code Update Test Teardown
62
63    Run Keyword If  '${PREV_TEST_STATUS}' == 'FAIL'
64    ...  Fail  Code update failed. No need to boot to OS.
65    Delete Error Logs
66    REST Power On
67    Verify Running Host Image  ${IMAGE_FILE_PATH}
68
69
70REST Host Code Update While OS Is Running
71    [Documentation]  Do a PNOR code update while the host is running.
72    [Tags]  REST_Host_Code_Update_While_OS_Is_Running
73
74    Run Keyword If  '${PREV_TEST_STATUS}' == 'FAIL'
75    ...  Fail  Cannot boot the OS.
76
77    REST Power On  stack_mode=skip
78    Upload And Activate Image  ${ALTERNATE_IMAGE_FILE_PATH}
79    REST Power On  stack_mode=normal
80    Verify Running Host Image  ${ALTERNATE_IMAGE_FILE_PATH}
81
82
83Host Image Priority Attribute Test
84    [Documentation]  Set "Priority" attribute.
85    [Tags]  Host_Image_Priority_Attribute_Test
86    [Template]  Temporarily Set PNOR Attribute
87
88    # Property        Value
89    Priority          ${0}
90    Priority          ${1}
91    Priority          ${127}
92    Priority          ${255}
93
94
95Host Set Priority To Invalid Values
96    [Documentation]  Attempt to set the priority of an image to an invalid
97    ...              value and expect an error.
98    [Tags]  Host_Set_Priority_To_Invalid_Values
99    [Template]  Set Priority To Invalid Value And Expect Error
100
101    # Version Type              Priority
102    ${VERSION_PURPOSE_HOST}    ${-1}
103    ${VERSION_PURPOSE_HOST}    ${256}
104
105
106Set RequestedActivation To None
107    [Documentation]  Set the RequestedActivation of the image to None and
108    ...              verify that it is in fact set to None.
109    [Tags]  Set_RequestedActivation_To_None
110
111    ${software_objects}=  Get Software Objects
112    Set Host Software Property  @{software_objects}[0]  RequestedActivation
113    ...  ${REQUESTED_NONE}
114    ${software_properties}=  Get Host Software Property  @{software_objects}[0]
115    Should Be Equal As Strings  &{software_properties}[RequestedActivation]
116    ...  ${REQUESTED_NONE}
117
118
119Set RequestedActivation And Activation To Invalid Value
120    [Documentation]  Set the RequestedActivation and Activation propreties of
121    ...              the image to an invalid value and verify that it was not
122    ...              changed.
123    [Template]  Set Property To Invalid Value And Verify No Change
124    [Tags]  Set_RequestedActivation_And_Activation_To_Invalid_Value
125
126    # Property              Version Type
127    RequestedActivation     ${VERSION_PURPOSE_HOST}
128    Activation              ${VERSION_PURPOSE_HOST}
129
130
131Upload And Activate Multiple Host Images
132    [Documentation]  Upload another PNOR image and verify that its state is
133    ...              different from all others.
134    [Tags]  Upload_And_Activate_Multiple_Host_Images
135    [Template]  Activate Image And Verify No Duplicate Priorities
136    [Setup]  Upload And Activate Multiple BMC Images Setup
137
138    # Image File Path              Image Purpose
139    ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_HOST}
140
141
142Set Same Priority For Multiple Host Images
143    [Documentation]  Attempt to set the priority to be the same for two PNOR
144    ...              images and verify that the priorities are not the same.
145    [Tags]  Set_Same_Priority_For_Multiple_Host_Images
146
147    Run Keyword If  '${PREV_TEST_STATUS}' == 'FAIL'
148    ...  Fail  Activation of alternate image failed. Cannot set priority.
149    Set Same Priority For Multiple Images  ${VERSION_PURPOSE_HOST}
150
151
152Delete Host Image
153    [Documentation]  Delete a PNOR image from the BMC and PNOR flash chip.
154    [Tags]  Delete_Host_Image
155    [Setup]  Initiate Host PowerOff
156
157    ${software_objects}=  Get Software Objects
158    ...  version_type=${VERSION_PURPOSE_HOST}
159    ${num_images}=  Get Length  ${software_objects}
160    Should Be True  0 < ${num_images}
161    ...  msg=There are no PNOR images on the BMC to delete.
162    Delete Image And Verify  @{software_objects}[0]  ${VERSION_PURPOSE_HOST}
163
164
165*** Keywords ***
166
167Temporarily Set PNOR Attribute
168    [Documentation]  Update the PNOR attribute value.
169    [Arguments]  ${attribute_name}  ${attribute_value}
170
171    # Description of argument(s):
172    # attribute_name    Host software attribute name (e.g. "Priority").
173    # attribute_value   Value to be written.
174
175    ${image_ids}=  Get Software Objects
176    ${init_host_properties}=  Get Host Software Property  ${image_ids[0]}
177    ${initial_priority}=  Set Variable  ${init_host_properties["Priority"]}
178
179    Set Host Software Property  ${image_ids[0]}  ${attribute_name}
180    ...  ${attribute_value}
181
182    ${cur_host_properties}=  Get Host Software Property  ${image_ids[0]}
183    Should Be Equal As Integers  ${cur_host_properties["Priority"]}
184    ...  ${attribute_value}
185
186    # Revert to to initial value.
187    Set Host Software Property
188    ...  ${image_ids[0]}  ${attribute_name}  ${initial_priority}
189
190
191Code Update Setup
192    [Documentation]  Do code update test case setup.
193    # - Clean up all existing BMC dumps.
194    # - Clean up all currently install PNOR images.
195
196    Run Keyword And Ignore Error  Smart Power Off
197    Delete All Dumps
198    Delete Error Logs
199    Run Keyword If  'true' == '${DELETE_OLD_PNOR_IMAGES}'
200    ...  Delete All PNOR Images
201    Run Keyword If  'true' == '${DELETE_OLD_GUARD_FILE}'  BMC Execute Command
202    ...  rm -f /var/lib/phosphor-software-manager/pnor/prsv/GUARD
203
204
205Upload And Activate Multiple BMC Images Setup
206    [Documentation]  Check that the ALTERNATE_FILE_PATH variable is set.
207
208    Should Not Be Empty  ${ALTERNATE_IMAGE_FILE_PATH}
209
210
211Get PNOR Extended Version
212    [Documentation]  Return the PNOR extended version.
213    [Arguments]  ${manifest_path}
214
215    # Description of argument(s):
216    # manifest_path  Path of the MANIFEST file
217    #                (e.g. "/tmp/images/abc123/MANIFEST").
218
219    ${version}= BMC Execute Command
220    ...  grep extended_version= ${manifest_path}
221    [return] ${version.split(",")}
222
223
224Code Update Test Teardown
225    [Documentation]  Do code update test case teardown.
226    # 1. Collect FFDC if test case failed.
227    # 2. Collect FFDC if test PASS but error log exists.
228
229    FFDC On Test Case Fail
230    Run Keyword If  '${TEST_STATUS}' == 'PASS'  Check Error And Collect FFDC
231