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