Added test cases for PNOR code upload
Resolves openbmc/openbmc-test-automation#766
Change-Id: I1f530b4f0ca57dd83962de2e7dfad20dbab3b526
Signed-off-by: Charles P. Hofer <charles.hofer@ibm.com>
diff --git a/extended/test_uploadimage.robot b/extended/test_uploadimage.robot
index 46a4829..008596c 100644
--- a/extended/test_uploadimage.robot
+++ b/extended/test_uploadimage.robot
@@ -1,10 +1,14 @@
*** Settings ***
-Documentation Test Upload Image
+Documentation Test upload image with both valid and invalid images.
+... This test expects there to be bad image tarballs named
+... pnor_bad_manifest.tar and pnor_no_image.tar on the TFTP
+... server and in the directory BAD_IMAGES_DIR_PATH.
... Execution Method :
... python -m robot -v OPENBMC_HOST:<hostname>
... -v TFTP_SERVER:<TFTP server IP>
... -v TFTP_FILE_NAME:<filename.tar>
... -v IMAGE_FILE_PATH:<path/*.tar> test_uploadimage.robot
+... -v BAD_IMAGES_DIR_PATH:<path>
Resource ../lib/connection_client.robot
Resource ../lib/rest_client.robot
@@ -53,6 +57,62 @@
${ret}= Verify Image Upload
Should Be True True == ${ret}
+Upload Image With Bad Manifest Via REST
+ [Documentation] Upload an image with a MANIFEST with an invalid
+ ... purpose via REST and make sure the BMC does not unpack it.
+ [Tags] Upload_Image_With_Bad_Manifest_Via_REST
+
+ ${bad_image_file_path}= OperatingSystem.Join Path ${BAD_IMAGES_DIR_PATH}
+ ... pnor_bad_manifest.tar
+ OperatingSystem.File Should Exist ${bad_image_file_path}
+ ... msg=Invalid PNOR image pnor_bad_manifest.tar not found
+ ${bad_image_version}= Get Version Tar ${bad_image_file_path}
+ ${bad_image_data}= OperatingSystem.Get Binary File ${bad_image_file_path}
+ Upload Post Request /upload/image data=${bad_image_data}
+ Verify Image Not In BMC Uploads Dir ${bad_image_version}
+
+Upload Image With Bad Manifest Via TFTP
+ [Documentation] Upload an image with a MANIFEST with an invalid
+ ... purpose via TFTP and make sure the BMC does not unpack it.
+ [Tags] Upload_Image_With_Bad_Manifest_Via_TFTP
+
+ @{image}= Create List pnor_bad_manifest.tar ${TFTP_SERVER}
+ ${data}= Create Dictionary data=@{image}
+ ${resp}= OpenBMC Post Request
+ ... ${SOFTWARE_VERSION_URI}/action/DownloadViaTFTP data=${data}
+ Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
+ ${bad_image_version}= Get Image Version From TFTP Server
+ ... pnor_bad_manifest.tar
+ Verify Image Not In BMC Uploads Dir ${bad_image_version}
+
+Upload Image With No Squashfs Via REST
+ [Documentation] Upload an image with no pnor.xz.suashfs file via REST and
+ ... make sure the BMC does not unpack it.
+ [Tags] Upload_Image_With_No_Squashfs_Via_REST
+
+ ${bad_image_file_path}= OperatingSystem.Join Path ${BAD_IMAGES_DIR_PATH}
+ ... pnor_no_image.tar
+ OperatingSystem.File Should Exist ${bad_image_file_path}
+ ... msg=Invalid PNOR image pnor_no_image.tar not found
+ ${bad_image_version}= Get Version Tar ${bad_image_file_path}
+ ${bad_image_data}= OperatingSystem.Get Binary File ${bad_image_file_path}
+ Upload Post Request /upload/image data=${bad_image_data}
+ Verify Image Not In BMC Uploads Dir ${bad_image_version}
+
+Upload Image With No Squashfs Via TFTP
+ [Documentation] Upload an image with no pnor.xz.suashfs file via TFTP and
+ ... make sure the BMC does not unpack it.
+ [Tags] Upload_Image_With_No_Squashfs_Via_TFTP
+
+ @{image}= Create List pnor_no_image.tar ${TFTP_SERVER}
+ ${data}= Create Dictionary data=@{image}
+ ${resp}= OpenBMC Post Request
+ ... ${SOFTWARE_VERSION_URI}/action/DownloadViaTFTP data=${data}
+ Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
+ ${bad_image_version}= Get Image Version From TFTP Server
+ ... pnor_no_image.tar
+ Verify Image Not In BMC Uploads Dir ${bad_image_version}
+
*** Keywords ***
Upload Image Teardown
@@ -65,7 +125,7 @@
Upload Post Request
[Arguments] ${uri} ${timeout}=10 ${quiet}=${QUIET} &{kwargs}
- # Description of arguments:
+ # Description of argument(s):
# uri URI for uploading image via REST.
# timeout Time allocated for the REST command to return status.
# quiet If enabled turns off logging to console.
@@ -81,3 +141,22 @@
${ret}= Post Request openbmc ${base_uri} &{kwargs} timeout=${timeout}
Run Keyword If '${quiet}' == '${0}' Log Response ${ret}
Should Be Equal As Strings ${ret.status_code} ${HTTP_OK}
+
+
+Get Image Version From TFTP Server
+ [Documentation] Get the version dfound in the MANIFEST file of
+ ... an image on the given TFTP server.
+ [Arguments] ${image_file_path}
+
+ # Description of argument(s):
+ # image_file_path The path to the image on the TFTP server,
+ # ommitting a leading /.
+
+ ${rc}= OperatingSystem.Run And Return RC
+ ... curl -s tftp://${TFTP_SERVER}/${image_file_path} > bad_image.tar
+ Should Be Equal As Integers 0 ${rc}
+ ... msg=Could not download image to check version.
+ ${version}= Get Version Tar bad_image.tar
+ OperatingSystem.Remove File bad_image.tar
+ [Return] ${version}
+