TFTP Bad firmware update for BMC/Host

Resolves openbmc/openbmc-test-automation#1898

Change-Id: Ie3bf4a5d9c2e9381632189c3fad8ee11febb7b43
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/lib/code_update_utils.robot b/lib/code_update_utils.robot
index b92a215..cef51e7 100644
--- a/lib/code_update_utils.robot
+++ b/lib/code_update_utils.robot
@@ -1,15 +1,18 @@
 *** Settings ***
-Documentation  BMC and PNOR update utilities keywords.
+Documentation   BMC and PNOR update utilities keywords.
 
-Library     code_update_utils.py
-Library     OperatingSystem
-Library     String
-Library     utilities.py
-Library     gen_robot_valid.py
-Variables   ../data/variables.py
-Resource    boot_utils.robot
-Resource    rest_client.robot
-Resource    openbmc_ffdc.robot
+Library         code_update_utils.py
+Library         OperatingSystem
+Library         String
+Library         utilities.py
+Library         gen_robot_valid.py
+Variables       ../data/variables.py
+Resource        boot_utils.robot
+Resource        rest_client.robot
+Resource        openbmc_ffdc.robot
+
+*** Variables ***
+${ignore_err}    ${0}
 
 *** Keywords ***
 
@@ -593,3 +596,21 @@
     ${apply_time}=  Read Attribute   ${SOFTWARE_VERSION_URI}apply_time  RequestedApplyTime
     Valid Value  apply_time  valid_values=["xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.${policy}"]
     Rprint Vars  apply_time
+
+
+Get Image Version From TFTP Server
+    [Documentation]  Get and return the image version
+    ...  from the TFTP server.
+    [Arguments]  ${server_host}  ${image_file_name}
+
+    # Description of argument(s):
+    # server_host   The host name or IP address of the TFTP server.
+    # image_file_name  The file name of the image.
+
+    Shell Cmd
+    ...  curl -s tftp://${server_host}/${image_file_name} > tftp_image.tar
+    ${version}=  Get Version Tar  tftp_image.tar
+    OperatingSystem.Remove File  tftp_image.tar
+
+    [Return]  ${version}
+
diff --git a/redfish/update_service/test_redfish_image_upload.robot b/redfish/update_service/test_redfish_image_upload.robot
index 98e9376..b83e39e 100644
--- a/redfish/update_service/test_redfish_image_upload.robot
+++ b/redfish/update_service/test_redfish_image_upload.robot
@@ -1,7 +1,7 @@
 *** Settings ***
 Documentation         Test upload image with invalid images.
 ...                   This test expects the following bad tarball image files
-...                   to exist in the BAD_IMAGES_DIR_PATH:
+...                   to exist in the BAD_IMAGES_DIR_PATH/TFTP_SERVER:
 ...                       bmc_bad_manifest.ubi.mtd.tar
 ...                       bmc_nokernel_image.ubi.mtd.tar
 ...                       bmc_invalid_key.ubi.mtd.tar
@@ -14,6 +14,7 @@
 # OPENBMC_USERNAME     The OS login userid.
 # OPENBMC_PASSWORD     The password for the OS login.
 # BAD_IMAGES_DIR_PATH  The path to the directory which contains the bad image files.
+# TFTP_SERVER          The host name or IP of the TFTP server.
 
 Resource               ../../lib/connection_client.robot
 Resource               ../../lib/rest_client.robot
@@ -73,13 +74,48 @@
     pnor_nokernel_image.pnor.squashfs.tar
 
 
+Redfish TFTP Failure to Upload BMC Image With Bad Manifest
+    [Documentation]  Upload a BMC firmware with a bad MANFIEST file via TFTP.
+    [Tags]  Redfish_TFTP_Failure_To_Upload_BMC_Image_With_Bad_Manifest
+    [Template]  Redfish TFTP Bad Firmware Update
+
+    # Image File Name
+    bmc_bad_manifest.ubi.mtd.tar
+
+
+Redfish TFTP Failure to Upload Empty BMC Image
+    [Documentation]  Upload a BMC firmware with no kernel image via TFTP.
+    [Tags]  Redfish_TFTP_Failure_To_Upload_Empty_BMC_Image
+    [Template]  Redfish TFTP Bad Firmware Update
+
+    # Image File Name
+    bmc_nokernel_image.ubi.mtd.tar
+
+
+Redfish TFTP Failure to Upload Host Image With Bad Manifest
+    [Documentation]  Upload a PNOR firmware with a bad MANIFEST file via TFTP.
+    [Tags]  Redfish_TFTP_Failure_To_Upload_Host_Image_With_Bad_Manifest
+    [Template]  Redfish TFTP Bad Firmware Update
+
+    # Image File Name
+    pnor_bad_manifest.pnor.squashfs.tar
+
+
+Redfish TFTP Failure to Upload Empty Host Image
+    [Documentation]  Upload a PNOR firmware with no kernel Image via TFTP.
+    [Tags]  Redfish_TFTP_Failure_To_Upload_Empty_Host_Image
+    [Template]  Redfish TFTP Bad Firmware Update
+
+    # Image File Name
+    pnor_nokernel_image.pnor.squashfs.tar
+
+
 *** Keywords ***
 
 Suite Setup Execution
     [Documentation]  Do the suite setup.
 
     Redfish.Login
-    Valid Dir Path  BAD_IMAGES_DIR_PATH
     Delete All BMC Dump
     Redfish Purge Event Log
 
@@ -92,6 +128,7 @@
     # Description of argument(s):
     # image_file_name  The file name of the image.
 
+    Valid Dir Path  BAD_IMAGES_DIR_PATH
     ${image_file_path}=  OperatingSystem.Join Path  ${BAD_IMAGES_DIR_PATH}
     ...  ${image_file_name}
     Valid File Path  image_file_path
@@ -110,9 +147,34 @@
     Check Image Update Progress State
     ...  match_state='Updating', 'Disabled'  image_id=${image_id}
 
+
+Redfish TFTP Bad Firmware Update
+    [Documentation]  Redfish bad firmware update via TFTP.
+    [Arguments]  ${image_file_name}
+    [Teardown]  Test Teardown Execution
+
+    # Description of argument(s):
+    # image_file_name  The file name of the image.
+
+    Set ApplyTime  policy=OnReset
+    # Download image from TFTP server to BMC.
+    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
+    ...  body={"TransferProtocol" : "TFTP", "ImageURI" : "${TFTP_SERVER}/${image_file_name}"}
+    Sleep  60s
+    ${image_version}=  Get Image Version From TFTP Server  ${TFTP_SERVER}  ${image_file_name}
+    Return From Keyword If  '${image_version}' == '${EMPTY}'
+    # Wait for image tar file to download complete.
+    ${image_id}=  Wait Until Keyword Succeeds  60 sec  10 sec  Get Latest Image ID
+    Rprint Vars  image_id
+
+    Check Image Update Progress State
+    ...  match_state='Updating', 'Disabled'  image_id=${image_id}
+
+
 Test Teardown Execution
     [Documentation]  Do the post test teardown.
 
     FFDC On Test Case Fail
     Run Keyword If  '${image_id}'  Delete Software Object
     ...  /xyz/openbmc_project/software/${image_id}
+