1*** Settings ***
2Documentation    Firmware image (BMC and Host) upload test using TFTP protocol.
3
4# Test Parameters:
5# TFTP_SERVER        The TFTP server host name or IP address.
6# IMAGE_FILE_NAME    The BMC or Host image file name.
7#
8# Firmware update states:
9#     Enabled  -> Image is installed and either functional or active.
10#     Disabled -> Image installation failed or ready for activation.
11#     Updating -> Image installation currently in progress.
12
13Resource         ../../lib/resource.robot
14Resource         ../../lib/boot_utils.robot
15Resource         ../../lib/bmc_redfish_resource.robot
16Resource         ../../lib/openbmc_ffdc.robot
17Resource         ../../lib/code_update_utils.robot
18Resource         ../../lib/redfish_code_update_utils.robot
19Resource         ../../lib/utils.robot
20Library          ../../lib/code_update_utils.py
21Library          ../../lib/gen_robot_valid.py
22Library          ../../lib/tftp_update_utils.py
23
24Suite Setup      Suite Setup Execution
25Suite Teardown   Redfish.Logout
26Test Setup       Run Keywords  Redfish Power Off  stack_mode=skip  quiet=1  AND  Redfish.Login
27Test Teardown    FFDC On Test Case Fail
28
29Force Tags       Firmware_Tftp_Upload_Image
30
31*** Test Cases ***
32
33TFTP Download Install With ApplyTime OnReset Policy
34    [Documentation]  Download image to BMC using TFTP with OnReset policy and verify installation.
35    [Tags]  TFTP_Download_Install_With_ApplyTime_OnReset_Policy
36    [Template]  TFTP Download Install
37
38    # policy
39    OnReset
40
41
42TFTP Download Install With ApplyTime Immediate Policy
43    [Documentation]  Download image to BMC using TFTP with Immediate policy and verify installation.
44    [Tags]  TFTP_Download_Install_With_ApplyTime_Immediate_Policy
45    [Template]  TFTP Download Install
46
47    # policy
48    Immediate
49
50
51ImageURI Download Install With ApplyTime OnReset Policy
52    [Documentation]  Download image to BMC using ImageURI with OnReset policy and verify installation.
53    [Tags]  ImageURI_Download_Install_With_ApplyTime_OnReset_Policy
54    [Template]  ImageURI Download Install
55
56    # policy
57    OnReset
58
59
60ImageURI Download Install With ApplyTime Immediate Policy
61    [Documentation]  Download image to BMC using ImageURI with Immediate policy and verify installation.
62    [Tags]  ImageURI_Download_Install_With_ApplyTime_Immediate_Policy
63    [Template]  ImageURI Download Install
64
65    # policy
66    Immediate
67
68
69Install Same Image Two Times
70    [Documentation]  Install firmware image and re-try using the same image which should fail.
71    [Tags]  Install_Same_Image_Two_Times
72    [Template]  Same Firmware Install Two Times
73
74    # policy
75    Immediate
76
77
78*** Keywords ***
79
80Suite Setup Execution
81    [Documentation]  Do the suite setup.
82
83    Redfish.Login
84    Valid Value  TFTP_SERVER
85    Valid Value  IMAGE_FILE_NAME
86
87
88TFTP Download Install
89    [Documentation]  Download image to BMC using TFTP with ApplyTime policy and verify installation.
90    [Arguments]  ${policy}
91
92    # Description of argument(s):
93    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
94
95    ${post_code_update_actions}=  Get Post Boot Action
96    ${state}=  Get Pre Reboot State
97    Rprint Vars  state
98
99    Set ApplyTime  policy=${policy}
100
101    # Download image from TFTP server to BMC.
102    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
103    ...  body={"TransferProtocol" : "TFTP", "ImageURI" : "${TFTP_SERVER}/${IMAGE_FILE_NAME}"}
104    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_ACCEPTED}]
105
106    # Wait for image tar file to download complete.
107    ${image_id}=  Wait Until Keyword Succeeds  180 sec  10 sec  Get Latest Image ID
108    Rprint Vars  image_id
109
110    # Let the image get extracted and it should not fail.
111    Sleep  5s
112    Check Image Update Progress State  match_state='Disabled', 'Updating'  image_id=${image_id}
113
114    # Get image version currently installation in progress.
115    ${install_version}=  Get Firmware Image Version  image_id=${image_id}
116    Rprint Vars  install_version
117
118    Check Image Update Progress State  match_state='Updating'  image_id=${image_id}
119
120    # Wait for the image to install complete.
121    Wait Until Keyword Succeeds  8 min  15 sec
122    ...  Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
123
124    Run Key  ${post_code_update_actions['BMC image']['${policy}']}
125
126    # Verify the image is installed and functional.
127    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' | sed 's/"//g'
128    ${functional_version}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
129    Valid Value  functional_version  valid_values=['${install_version}']
130    Rprint Vars  functional_version
131
132
133ImageURI Download Install
134    [Documentation]  Download image to BMC using ImageURI with ApplyTime policy and verify installation.
135    [Arguments]  ${policy}
136
137    # Description of argument(s):
138    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
139
140    ${post_code_update_actions}=  Get Post Boot Action
141    ${state}=  Get Pre Reboot State
142    Rprint Vars  state
143
144    Set ApplyTime  policy=${policy}
145
146    # Download image from TFTP server via ImageURI to BMC.
147    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
148    ...  body={"ImageURI": "tftp://${TFTP_SERVER}/${IMAGE_FILE_NAME}"}
149    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_ACCEPTED}]
150
151    # Wait for image tar file download to complete.
152    ${image_id}=  Wait Until Keyword Succeeds  180 sec  10 sec  Get Latest Image ID
153    Rprint Vars  image_id
154
155    # Let the image get extracted and it should not fail.
156    Sleep  5s
157    Check Image Update Progress State  match_state='Disabled', 'Updating'  image_id=${image_id}
158
159    ${install_version}=  Get Firmware Image Version  image_id=${image_id}
160    Rprint Vars  install_version
161
162    Check Image Update Progress State  match_state='Updating'  image_id=${image_id}
163
164    # Wait for the image to install complete.
165    Wait Until Keyword Succeeds  8 min  15 sec
166    ...  Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
167
168    Run Key  ${post_code_update_actions['BMC image']['${policy}']}
169
170    # Verify the image is installed and functional.
171    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' | sed 's/"//g'
172    ${functional_version}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
173    Valid Value  functional_version  valid_values=['${install_version}']
174    Rprint Vars  functional_version
175
176
177Same Firmware Install Two Times
178    [Documentation]  Download same image twice to BMC via ImageURI. Second attempt would fail.
179    [Arguments]  ${apply_time}  ${tftp_server}=${TFTP_SERVER}  ${image_file_name}=${IMAGE_FILE_NAME}
180
181    # Description of argument(s):
182    # apply_time       ApplyTime allowed values (e.g. "OnReset", "Immediate").
183    # tftp_server      Server IP.
184    # image_file_name  Image file name.
185
186    ImageURI Download Install  ${apply_time}
187
188    # Download image from TFTP server via ImageURI to BMC.
189    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
190    ...  body={"ImageURI": "tftp://${tftp_server}/${image_file_name}"}
191
192    ${image_version}=  Get Image Version From TFTP Server  ${tftp_server}  ${image_file_name}
193    ${software_inventory_record}=  Get Software Inventory State By Version
194    ...  ${image_version}
195    Rprint Vars  software_inventory_record
196
197    ${image_id}=  Wait Until Keyword Succeeds  180 sec  10 sec  Get Latest Image ID
198    Rprint Vars  image_id
199
200    Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
201    # Check if the existing firmware is functional.
202    Pass Execution If  ${software_inventory_record['functional']}
203    ...  The existing ${image_version} firmware is already functional.
204
205