blob: b0eeb00c9232299b148db77463c584b9cbb5b551 [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
Saqib Khanbb8b63f2017-05-24 10:58:01 -050027${upload_dir_path} /tmp/images/
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050028${QUIET} ${1}
Saqib Khanbb8b63f2017-05-24 10:58:01 -050029${image_version} ${EMPTY}
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050030
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}
Saqib Khanbb8b63f2017-05-24 10:58:01 -050040 Upload Image To BMC /upload/image data=${image_data}
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050041 ${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
George Keishingff1e3ec2017-07-20 01:58:21 -050051 ... ${SOFTWARE_VERSION_URI}/action/DownloadViaTFTP data=${data}
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050052 Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
53 Sleep 1 minute
Saqib Khanbb8b63f2017-05-24 10:58:01 -050054 ${upload_file}= Get Latest File ${upload_dir_path}
55 ${image_version}= Get Image Version
56 ... ${upload_dir_path}${upload_file}/MANIFEST
Saqib Khanfb1f6ae2017-04-26 13:24:41 -050057 ${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
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500119 [Documentation] Log FFDC if test fails for debugging purposes.
120
121 Open Connection And Log In
122 Execute Command On BMC rm -rf /tmp/images/*
Saqib Khanfb1f6ae2017-04-26 13:24:41 -0500123
124 Close All Connections
125 FFDC On Test Case Fail
126
Saqib Khanbb8b63f2017-05-24 10:58:01 -0500127
Saqib Khanfb1f6ae2017-04-26 13:24:41 -0500128Upload Post Request
129 [Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
130
Charles P. Hofer1d20acd2017-07-05 15:24:40 -0500131 # Description of argument(s):
Saqib Khanfb1f6ae2017-04-26 13:24:41 -0500132 # uri URI for uploading image via REST.
133 # timeout Time allocated for the REST command to return status.
134 # quiet If enabled turns off logging to console.
135 # kwargs A dictionary that maps each keyword to a value.
136
137 Initialize OpenBMC ${timeout} quiet=${quiet}
138 ${base_uri}= Catenate SEPARATOR= ${DBUS_PREFIX} ${uri}
139 ${headers}= Create Dictionary Content-Type=application/octet-stream
140 ... Accept=application/octet-stream
141 Set To Dictionary ${kwargs} headers ${headers}
142 Run Keyword If '${quiet}' == '${0}' Log Request method=Post
143 ... base_uri=${base_uri} args=&{kwargs}
144 ${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
145 Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
146 Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
Charles P. Hofer1d20acd2017-07-05 15:24:40 -0500147
148
149Get Image Version From TFTP Server
150 [Documentation] Get the version dfound in the MANIFEST file of
151 ... an image on the given TFTP server.
152 [Arguments] ${image_file_path}
153
154 # Description of argument(s):
155 # image_file_path The path to the image on the TFTP server,
156 # ommitting a leading /.
157
158 ${rc}= OperatingSystem.Run And Return RC
159 ... curl -s tftp://${TFTP_SERVER}/${image_file_path} > bad_image.tar
160 Should Be Equal As Integers 0 ${rc}
161 ... msg=Could not download image to check version.
162 ${version}= Get Version Tar bad_image.tar
163 OperatingSystem.Remove File bad_image.tar
164 [Return] ${version}