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       tftp_update
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
105    # Wait for image tar file to download complete.
106    ${image_id}=  Wait Until Keyword Succeeds  180 sec  10 sec  Get Latest Image ID
107    Rprint Vars  image_id
108
109    # Let the image get extracted and it should not fail.
110    Sleep  5s
111    Check Image Update Progress State  match_state='Disabled', 'Updating'  image_id=${image_id}
112
113    # Get image version currently installation in progress.
114    ${install_version}=  Get Firmware Image Version  image_id=${image_id}
115    Rprint Vars  install_version
116
117    Check Image Update Progress State  match_state='Updating'  image_id=${image_id}
118
119    # Wait for the image to install complete.
120    Wait Until Keyword Succeeds  8 min  15 sec
121    ...  Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
122
123    Run Key  ${post_code_update_actions['BMC image']['${policy}']}
124
125    # Verify the image is installed and functional.
126    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' | sed 's/"//g'
127    ${functional_version}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
128    Valid Value  functional_version  valid_values=['${install_version}']
129    Rprint Vars  functional_version
130
131
132ImageURI Download Install
133    [Documentation]  Download image to BMC using ImageURI with ApplyTime policy and verify installation.
134    [Arguments]  ${policy}
135
136    # Description of argument(s):
137    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
138
139    ${post_code_update_actions}=  Get Post Boot Action
140    ${state}=  Get Pre Reboot State
141    Rprint Vars  state
142
143    Set ApplyTime  policy=${policy}
144
145    # Download image from TFTP server via ImageURI to BMC.
146    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
147    ...  body={"ImageURI": "tftp://${TFTP_SERVER}/${IMAGE_FILE_NAME}"}
148
149    # Wait for image tar file download to complete.
150    ${image_id}=  Wait Until Keyword Succeeds  180 sec  10 sec  Get Latest Image ID
151    Rprint Vars  image_id
152
153    # Let the image get extracted and it should not fail.
154    Sleep  5s
155    Check Image Update Progress State  match_state='Disabled', 'Updating'  image_id=${image_id}
156
157    ${install_version}=  Get Firmware Image Version  image_id=${image_id}
158    Rprint Vars  install_version
159
160    Check Image Update Progress State  match_state='Updating'  image_id=${image_id}
161
162    # Wait for the image to install complete.
163    Wait Until Keyword Succeeds  8 min  15 sec
164    ...  Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
165
166    Run Key  ${post_code_update_actions['BMC image']['${policy}']}
167
168    # Verify the image is installed and functional.
169    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '=' | sed 's/"//g'
170    ${functional_version}  ${stderr}  ${rc}=  BMC Execute Command  ${cmd}
171    Valid Value  functional_version  valid_values=['${install_version}']
172    Rprint Vars  functional_version
173
174
175Same Firmware Install Two Times
176    [Documentation]  Download same image twice to BMC via ImageURI. Second attempt would fail.
177    [Arguments]  ${apply_time}  ${tftp_server}=${TFTP_SERVER}  ${image_file_name}=${IMAGE_FILE_NAME}
178
179    # Description of argument(s):
180    # apply_time       ApplyTime allowed values (e.g. "OnReset", "Immediate").
181    # tftp_server      Server IP.
182    # image_file_name  Image file name.
183
184    ImageURI Download Install  ${apply_time}
185
186    # Download image from TFTP server via ImageURI to BMC.
187    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
188    ...  body={"ImageURI": "tftp://${tftp_server}/${image_file_name}"}
189
190    ${image_version}=  Get Image Version From TFTP Server  ${tftp_server}  ${image_file_name}
191    ${software_inventory_record}=  Get Software Inventory State By Version
192    ...  ${image_version}
193    Rprint Vars  software_inventory_record
194
195    ${image_id}=  Wait Until Keyword Succeeds  180 sec  10 sec  Get Latest Image ID
196    Rprint Vars  image_id
197
198    Check Image Update Progress State  match_state='Enabled'  image_id=${image_id}
199    # Check if the existing firmware is functional.
200    Pass Execution If  ${software_inventory_record['functional']}
201    ...  The existing ${image_version} firmware is already functional.
202
203