1*** Settings ***
2Documentation         Test upload image with invalid images.
3...                   This test expects the following bad tarball image files
4...                   to exist in the BAD_IMAGES_DIR_PATH/TFTP_SERVER:
5...                       bmc_bad_manifest.ubi.mtd.tar
6...                       bmc_nokernel_image.ubi.mtd.tar
7...                       bmc_invalid_key.ubi.mtd.tar
8...                       pnor_bad_manifest.pnor.squashfs.tar
9...                       pnor_nokernel_image.pnor.squashfs.tar
10...                       pnor_invalid_key.pnor.squashfs.tar
11
12# Test Parameters:
13# OPENBMC_HOST         The BMC host name or IP address.
14# OPENBMC_USERNAME     The OS login userid.
15# OPENBMC_PASSWORD     The password for the OS login.
16# BAD_IMAGES_DIR_PATH  The path to the directory which contains the bad image files.
17# TFTP_SERVER          The host name or IP of the TFTP server.
18
19Resource               ../../lib/connection_client.robot
20Resource               ../../lib/rest_client.robot
21Resource               ../../lib/openbmc_ffdc.robot
22Resource               ../../lib/bmc_redfish_resource.robot
23Resource               ../../lib/code_update_utils.robot
24Library                OperatingSystem
25Library                ../../lib/code_update_utils.py
26Library                ../../lib/gen_robot_valid.py
27
28Suite Setup            Suite Setup Execution
29Suite Teardown         Redfish.Logout
30Test Setup             Printn
31
32Force Tags  Upload_Test
33
34*** Variables ***
35${timeout}             20
36${QUIET}               ${1}
37${image_id}            ${EMPTY}
38
39*** Test Cases ***
40
41Redfish Failure to Upload BMC Image With Bad Manifest
42    [Documentation]  Upload a BMC firmware with a bad MANFIEST file.
43    [Tags]  Redfish_Failure_To_Upload_BMC_Image_With_Bad_Manifest
44    [Template]  Redfish Bad Firmware Update
45
46    # Image File Name
47    bmc_bad_manifest.ubi.mtd.tar
48
49
50Redfish Failure to Upload Empty BMC Image
51    [Documentation]  Upload a BMC firmware with no kernel image.
52    [Tags]  Redfish_Failure_To_Upload_Empty_BMC_Image
53    [Template]  Redfish Bad Firmware Update
54
55    # Image File Name
56    bmc_nokernel_image.ubi.mtd.tar
57
58
59Redfish Failure to Upload Host Image With Bad Manifest
60    [Documentation]  Upload a PNOR firmware with a bad MANIFEST file.
61    [Tags]  Redfish_Failure_To_Upload_Host_Image_With_Bad_Manifest
62    [Template]  Redfish Bad Firmware Update
63
64    # Image File Name
65    pnor_bad_manifest.pnor.squashfs.tar
66
67
68Redfish Failure to Upload Empty Host Image
69    [Documentation]  Upload a PNOR firmware with no kernel Image.
70    [Tags]  Redfish_Failure_To_Upload_Empty_Host_Image
71    [Template]  Redfish Bad Firmware Update
72
73    # Image File Name
74    pnor_nokernel_image.pnor.squashfs.tar
75
76
77Redfish TFTP Failure to Upload BMC Image With Bad Manifest
78    [Documentation]  Upload a BMC firmware with a bad MANFIEST file via TFTP.
79    [Tags]  Redfish_TFTP_Failure_To_Upload_BMC_Image_With_Bad_Manifest
80    [Template]  Redfish TFTP Bad Firmware Update
81
82    # Image File Name
83    bmc_bad_manifest.ubi.mtd.tar
84
85
86Redfish TFTP Failure to Upload Empty BMC Image
87    [Documentation]  Upload a BMC firmware with no kernel image via TFTP.
88    [Tags]  Redfish_TFTP_Failure_To_Upload_Empty_BMC_Image
89    [Template]  Redfish TFTP Bad Firmware Update
90
91    # Image File Name
92    bmc_nokernel_image.ubi.mtd.tar
93
94
95Redfish TFTP Failure to Upload Host Image With Bad Manifest
96    [Documentation]  Upload a PNOR firmware with a bad MANIFEST file via TFTP.
97    [Tags]  Redfish_TFTP_Failure_To_Upload_Host_Image_With_Bad_Manifest
98    [Template]  Redfish TFTP Bad Firmware Update
99
100    # Image File Name
101    pnor_bad_manifest.pnor.squashfs.tar
102
103
104Redfish TFTP Failure to Upload Empty Host Image
105    [Documentation]  Upload a PNOR firmware with no kernel Image via TFTP.
106    [Tags]  Redfish_TFTP_Failure_To_Upload_Empty_Host_Image
107    [Template]  Redfish TFTP Bad Firmware Update
108
109    # Image File Name
110    pnor_nokernel_image.pnor.squashfs.tar
111
112
113*** Keywords ***
114
115Suite Setup Execution
116    [Documentation]  Do the suite setup.
117
118    Redfish.Login
119    Redfish Delete All BMC Dumps
120    Redfish Purge Event Log
121
122
123Redfish Bad Firmware Update
124    [Documentation]  Redfish firmware update.
125    [Arguments]  ${image_file_name}
126    [Teardown]  Test Teardown Execution
127
128    # Description of argument(s):
129    # image_file_name  The file name of the image.
130
131    Valid Dir Path  BAD_IMAGES_DIR_PATH
132    ${image_file_path}=  OperatingSystem.Join Path  ${BAD_IMAGES_DIR_PATH}
133    ...  ${image_file_name}
134    Valid File Path  image_file_path
135    Set ApplyTime  policy=OnReset
136    ${image_data}=  OperatingSystem.Get Binary File  ${image_file_path}
137    ${status_code}=  Upload Image To BMC
138    ...  ${REDFISH_BASE_URI}UpdateService
139    ...  ${timeout}
140    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_INTERNAL_SERVER_ERROR}]
141    ...  data=${image_data}
142
143    Return From Keyword If  ${status_code} == ${HTTP_INTERNAL_SERVER_ERROR}
144
145    ${image_id}=  Get Latest Image ID
146    Rprint Vars  image_id
147    Check Image Update Progress State
148    ...  match_state='Updating', 'Disabled'  image_id=${image_id}
149
150
151Redfish TFTP Bad Firmware Update
152    [Documentation]  Redfish bad firmware update via TFTP.
153    [Arguments]  ${image_file_name}
154    [Teardown]  Test Teardown Execution
155
156    # Description of argument(s):
157    # image_file_name  The file name of the image.
158
159    Set ApplyTime  policy=OnReset
160    # Download image from TFTP server to BMC.
161    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
162    ...  body={"TransferProtocol" : "TFTP", "ImageURI" : "${TFTP_SERVER}/${image_file_name}"}
163    Sleep  60s
164    ${image_version}=  Get Image Version From TFTP Server  ${TFTP_SERVER}  ${image_file_name}
165    Return From Keyword If  '${image_version}' == '${EMPTY}'
166    # Wait for image tar file to download complete.
167    ${image_id}=  Wait Until Keyword Succeeds  60 sec  10 sec  Get Latest Image ID
168    Rprint Vars  image_id
169
170    Check Image Update Progress State
171    ...  match_state='Updating', 'Disabled'  image_id=${image_id}
172
173
174Test Teardown Execution
175    [Documentation]  Do the post test teardown.
176
177    FFDC On Test Case Fail
178    Run Keyword If  '${image_id}'  Delete Software Object
179    ...  /xyz/openbmc_project/software/${image_id}
180
181