blob: 008596c65b276290093b158ded68a1c3a732e3b1 [file] [log] [blame]
Saqib Khanfb1f6ae2017-04-26 13:24:41 -05001*** Settings ***
Charles P. Hofer1d20acd2017-07-05 15:24:40 -05002Documentation Test upload image with both valid and invalid images.
3... This test expects there to be bad image tarballs named
4... pnor_bad_manifest.tar and pnor_no_image.tar on the TFTP
5... server and in the directory BAD_IMAGES_DIR_PATH.
Saqib Khanfb1f6ae2017-04-26 13:24:41 -05006... Execution Method :
7... python -m robot -v OPENBMC_HOST:<hostname>
8... -v TFTP_SERVER:<TFTP server IP>
9... -v TFTP_FILE_NAME:<filename.tar>
10... -v IMAGE_FILE_PATH:<path/*.tar> test_uploadimage.robot
Charles P. Hofer1d20acd2017-07-05 15:24:40 -050011... -v BAD_IMAGES_DIR_PATH:<path>
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050012
13Resource ../lib/connection_client.robot
14Resource ../lib/rest_client.robot
15Resource ../lib/openbmc_ffdc.robot
16Library Collections
17Library String
18Library OperatingSystem
19Library test_uploadimage.py
20
21Test Teardown Upload Image Teardown
22
Sweta Potthuri5db43e42017-06-15 05:36:44 -050023Force Tags Upload_Test
24
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050025*** Variables ***
26${timeout} 10
27${UPLOAD_DIR_PATH} /tmp/images/
28${QUIET} ${1}
29${IMAGE_VERSION} ${EMPTY}
30
31*** Test Cases ***
32
33Upload Image Via REST
34 [Documentation] Upload an image via REST.
35 [Tags] Upload_Image_Via_REST
36
37 OperatingSystem.File Should Exist ${IMAGE_FILE_PATH}
38 ${IMAGE_VERSION}= Get Version Tar ${IMAGE_FILE_PATH}
39 ${image_data}= OperatingSystem.Get Binary File ${IMAGE_FILE_PATH}
40 Upload Post Request /upload/image data=${image_data}
41 ${ret}= Verify Image Upload
42 Should Be True True == ${ret}
43
44Upload Image Via TFTP
45 [Documentation] Upload an image via TFTP.
46 [Tags] Upload_Image_Via_TFTP
47
48 @{image}= Create List ${TFTP_FILE_NAME} ${TFTP_SERVER}
49 ${data}= Create Dictionary data=@{image}
50 ${resp}= OpenBMC Post Request
51 ... ${SOFTWARE_VERSION_URI}/action/DownloadViaTFTP data=${data}
52 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
53 Sleep 1 minute
54 ${upload_file}= Get Latest File ${UPLOAD_DIR_PATH}
55 ${IMAGE_VERSION}= Get Image Version
56 ... ${UPLOAD_DIR_PATH}${upload_file}/MANIFEST
57 ${ret}= Verify Image Upload
58 Should Be True True == ${ret}
59
Charles P. Hofer1d20acd2017-07-05 15:24:40 -050060Upload Image With Bad Manifest Via REST
61 [Documentation] Upload an image with a MANIFEST with an invalid
62 ... purpose via REST and make sure the BMC does not unpack it.
63 [Tags] Upload_Image_With_Bad_Manifest_Via_REST
64
65 ${bad_image_file_path}= OperatingSystem.Join Path ${BAD_IMAGES_DIR_PATH}
66 ... pnor_bad_manifest.tar
67 OperatingSystem.File Should Exist ${bad_image_file_path}
68 ... msg=Invalid PNOR image pnor_bad_manifest.tar not found
69 ${bad_image_version}= Get Version Tar ${bad_image_file_path}
70 ${bad_image_data}= OperatingSystem.Get Binary File ${bad_image_file_path}
71 Upload Post Request /upload/image data=${bad_image_data}
72 Verify Image Not In BMC Uploads Dir ${bad_image_version}
73
74Upload Image With Bad Manifest Via TFTP
75 [Documentation] Upload an image with a MANIFEST with an invalid
76 ... purpose via TFTP and make sure the BMC does not unpack it.
77 [Tags] Upload_Image_With_Bad_Manifest_Via_TFTP
78
79 @{image}= Create List pnor_bad_manifest.tar ${TFTP_SERVER}
80 ${data}= Create Dictionary data=@{image}
81 ${resp}= OpenBMC Post Request
82 ... ${SOFTWARE_VERSION_URI}/action/DownloadViaTFTP data=${data}
83 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
84 ${bad_image_version}= Get Image Version From TFTP Server
85 ... pnor_bad_manifest.tar
86 Verify Image Not In BMC Uploads Dir ${bad_image_version}
87
88Upload Image With No Squashfs Via REST
89 [Documentation] Upload an image with no pnor.xz.suashfs file via REST and
90 ... make sure the BMC does not unpack it.
91 [Tags] Upload_Image_With_No_Squashfs_Via_REST
92
93 ${bad_image_file_path}= OperatingSystem.Join Path ${BAD_IMAGES_DIR_PATH}
94 ... pnor_no_image.tar
95 OperatingSystem.File Should Exist ${bad_image_file_path}
96 ... msg=Invalid PNOR image pnor_no_image.tar not found
97 ${bad_image_version}= Get Version Tar ${bad_image_file_path}
98 ${bad_image_data}= OperatingSystem.Get Binary File ${bad_image_file_path}
99 Upload Post Request /upload/image data=${bad_image_data}
100 Verify Image Not In BMC Uploads Dir ${bad_image_version}
101
102Upload Image With No Squashfs Via TFTP
103 [Documentation] Upload an image with no pnor.xz.suashfs file via TFTP and
104 ... make sure the BMC does not unpack it.
105 [Tags] Upload_Image_With_No_Squashfs_Via_TFTP
106
107 @{image}= Create List pnor_no_image.tar ${TFTP_SERVER}
108 ${data}= Create Dictionary data=@{image}
109 ${resp}= OpenBMC Post Request
110 ... ${SOFTWARE_VERSION_URI}/action/DownloadViaTFTP data=${data}
111 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
112 ${bad_image_version}= Get Image Version From TFTP Server
113 ... pnor_no_image.tar
114 Verify Image Not In BMC Uploads Dir ${bad_image_version}
115
Saqib Khanfb1f6ae2017-04-26 13:24:41 -0500116*** Keywords ***
117
118Upload Image Teardown
119 [Documentation] Log FFDC if test suite fails and collect SOL log for
120 ... debugging purposes.
121
122 Close All Connections
123 FFDC On Test Case Fail
124
125Upload Post Request
126 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
127
Charles P. Hofer1d20acd2017-07-05 15:24:40 -0500128 # Description of argument(s):
Saqib Khanfb1f6ae2017-04-26 13:24:41 -0500129 # uri URI for uploading image via REST.
130 # timeout Time allocated for the REST command to return status.
131 # quiet If enabled turns off logging to console.
132 # kwargs A dictionary that maps each keyword to a value.
133
134 Initialize OpenBMC ${timeout} quiet=${quiet}
135 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
136 ${headers}= Create Dictionary Content-Type=application/octet-stream
137 ... Accept=application/octet-stream
138 Set To Dictionary ${kwargs} headers ${headers}
139 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
140 ... base_uri=${base_uri} args=&{kwargs}
141 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
142 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
143 Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
Charles P. Hofer1d20acd2017-07-05 15:24:40 -0500144
145
146Get Image Version From TFTP Server
147 [Documentation] Get the version dfound in the MANIFEST file of
148 ... an image on the given TFTP server.
149 [Arguments] ${image_file_path}
150
151 # Description of argument(s):
152 # image_file_path The path to the image on the TFTP server,
153 # ommitting a leading /.
154
155 ${rc}= OperatingSystem.Run And Return RC
156 ... curl -s tftp://${TFTP_SERVER}/${image_file_path} > bad_image.tar
157 Should Be Equal As Integers 0 ${rc}
158 ... msg=Could not download image to check version.
159 ${version}= Get Version Tar bad_image.tar
160 OperatingSystem.Remove File bad_image.tar
161 [Return] ${version}
162