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
31*** Variables ***
32
33${QUIET}                          ${1}
34${IMAGE_FILE_PATH}                ${EMPTY}
35${DELETE_OLD_PNOR_IMAGES}         false
36${DELETE_OLD_GUARD_FILE}          false
37${ALTERNATE_IMAGE_FILE_PATH}      ${EMPTY}
38
39*** Test Cases ***
40
41REST Host Code Update
42    [Documentation]  Do a PNOR code update by uploading image on BMC via REST.
43    # 1. Delete error logs if there is any.
44    # 1. Do code update.
45    # 2. Do post update the following:
46    #    - Collect FFDC if error log exist and delete error logs.
47    [Tags]  REST_Host_Code_Update
48    [Setup]  Code Update Setup
49
50    Upload And Activate Image  ${IMAGE_FILE_PATH}
51    OBMC Reboot (off)
52
53
54Post Update Boot To OS
55    [Documentation]  Boot the host OS
56    [Tags]  Post_Update_Boot_To_OS
57    [Teardown]  Run Keywords  Stop SOL Console Logging
58    ...         AND  Code Update Test Teardown
59
60    Run Keyword If  '${PREV_TEST_STATUS}' == 'FAIL'
61    ...  Fail  Code update failed. No need to boot to OS.
62    Start SOL Console Logging
63    Delete Error Logs
64    REST Power On
65
66
67Host Image Priority Attribute Test
68    [Documentation]  Set "Priority" attribute.
69    [Tags]  Host_Image_Priority_Attribute_Test
70    [Template]  Temporarily Set PNOR Attribute
71
72    # Property        Value
73    Priority          ${0}
74    Priority          ${1}
75    Priority          ${127}
76
77
78Set RequestedActivation To None
79    [Documentation]  Set the RequestedActivation of the image to None and
80    ...              verify that it is in fact set to None.
81    [Tags]  Set_RequestedActivation_To_None
82
83    ${software_objects}=  Get Software Objects
84    Set Host Software Property  @{software_objects}[0]  RequestedActivation
85    ...  ${REQUESTED_NONE}
86    ${software_properties}=  Get Host Software Property  @{software_objects}[0]
87    Should Be Equal As Strings  &{software_properties}[RequestedActivation]
88    ...  ${REQUESTED_NONE}
89
90
91Set RequestedActivation And Activation To Invalid Value
92    [Documentation]  Set the RequestedActivation and Activation propreties of
93    ...              the image to an invalid value and verify that it was not
94    ...              changed.
95    [Template]  Set Property To Invalid Value And Verify No Change
96    [Tags]  Set_RequestedActivation_And_Activation_To_Invalid_Value
97
98    # Property              Version Type
99    RequestedActivation     ${VERSION_PURPOSE_HOST}
100    Activation              ${VERSION_PURPOSE_HOST}
101
102
103Upload And Activate Multiple Host Images
104    [Documentation]  Upload another PNOR image and verify that its state is
105    ...              different from all others.
106    [Tags]  Upload_And_Activate_Multiple_Host_Images
107    [Template]  Activate Image And Verify No Duplicate Priorities
108    [Setup]  Upload And Activate Multiple BMC Images Setup
109
110    # Image File Path              Image Purpose
111    ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_HOST}
112
113
114Set Same Priority For Multiple Host Images
115    [Documentation]  Attempt to set the priority to be the same for two PNOR
116    ...              images and verify that the priorities are not the same.
117    [Tags]  Set_Same_Priority_For_Multiple_Host_Images
118
119    Run Keyword If  '${PREV_TEST_STATUS}' == 'FAIL'
120    ...  Fail  Activation of alternate image failed. Cannot set priority.
121    Set Same Priority For Multiple Images  ${VERSION_PURPOSE_HOST}
122
123
124Delete Host Image
125    [Documentation]  Delete a PNOR image from the BMC and PNOR flash chip.
126    [Tags]  Delete_Host_Image
127    [Setup]  Initiate Host PowerOff
128
129    ${software_objects}=  Get Software Objects
130    ...  version_type=${VERSION_PURPOSE_HOST}
131    ${num_images}=  Get Length  ${software_objects}
132    Should Be True  0 < ${num_images}
133    ...  msg=There are no PNOR images on the BMC to delete.
134    Delete Image And Verify  @{software_objects}[0]  ${VERSION_PURPOSE_HOST}
135
136
137*** Keywords ***
138
139Temporarily Set PNOR Attribute
140    [Documentation]  Update the PNOR attribute value.
141    [Arguments]  ${attribute_name}  ${attribute_value}
142
143    # Description of argument(s):
144    # attribute_name    Host software attribute name (e.g. "Priority").
145    # attribute_value   Value to be written.
146
147    ${image_ids}=  Get Software Objects
148    ${init_host_properties}=  Get Host Software Property  ${image_ids[0]}
149    ${initial_priority}=  Set Variable  ${init_host_properties["Priority"]}
150
151    Set Host Software Property  ${image_ids[0]}  ${attribute_name}
152    ...  ${attribute_value}
153
154    ${cur_host_properties}=  Get Host Software Property  ${image_ids[0]}
155    Should Be Equal As Integers  ${cur_host_properties["Priority"]}
156    ...  ${attribute_value}
157
158    # Revert to to initial value.
159    Set Host Software Property
160    ...  ${image_ids[0]}  ${attribute_name}  ${initial_priority}
161
162
163Code Update Setup
164    [Documentation]  Do code update test case setup.
165    # - Clean up all existing BMC dumps.
166    # - Clean up all currently install PNOR images.
167
168    Initiate Host PowerOff
169    Delete All Dumps
170    Delete Error Logs
171    Run Keyword If  'true' == '${DELETE_OLD_PNOR_IMAGES}'
172    ...  Delete All PNOR Images
173    Run Keyword If  'true' == '${DELETE_OLD_GUARD_FILE}'  BMC Execute Command
174    ...  rm -f /var/lib/phosphor-software-manager/pnor/prsv/GUARD
175
176
177Upload And Activate Multiple BMC Images Setup
178    [Documentation]  Check that the ALTERNATE_FILE_PATH variable is set.
179
180    Should Not Be Empty  ${ALTERNATE_IMAGE_FILE_PATH}
181
182
183Get PNOR Extended Version
184    [Documentation]  Return the PNOR extended version.
185    [Arguments]  ${manifest_path}
186
187    # Description of argument(s):
188    # manifest_path  Path of the MANIFEST file
189    #                (e.g. "/tmp/images/abc123/MANIFEST").
190
191    ${version}= BMC Execute Command
192    ...  grep extended_version= ${manifest_path}
193    [return] ${version.split(",")}
194
195
196Code Update Test Teardown
197    [Documentation]  Do code update test case teardown.
198    # 1. Collect FFDC if test case failed.
199    # 2. Collect FFDC if test PASS but error log exists.
200
201    FFDC On Test Case Fail
202    Run Keyword If  '${TEST_STATUS}' == 'PASS'  Check Error And Collect FFDC
203