Same firmware upload two times

Added code address same image gets updated multiple times.
1. Upload and update fimrware image and verify installation.
2. Upload same image again.
3. This time same image gets failed to upload.

Change-Id: I4d307056103ab01ad2d819c2f137c8aa2a5805a6
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/redfish/update_service/test_firmware_tftp_upload_image.robot b/redfish/update_service/test_firmware_tftp_upload_image.robot
index a62acf3..1292d6a 100644
--- a/redfish/update_service/test_firmware_tftp_upload_image.robot
+++ b/redfish/update_service/test_firmware_tftp_upload_image.robot
@@ -15,6 +15,7 @@
 Resource         ../../lib/bmc_redfish_resource.robot
 Resource         ../../lib/openbmc_ffdc.robot
 Resource         ../../lib/code_update_utils.robot
+Resource         ../../lib/redfish_code_update_utils.robot
 Library          ../../lib/code_update_utils.py
 Library          ../../lib/gen_robot_valid.py
 Library          ../../lib/tftp_update_utils.py
@@ -63,6 +64,16 @@
     # policy
     Immediate
 
+
+Install Same Image Two Times
+    [Documentation]  Install firmware image and re-try using the same image which should fail.
+    [Tags]  Install_Same_Image_Two_Times
+    [Template]  Same Firmware Install Two Times
+
+    # policy
+    Immediate
+
+
 *** Keywords ***
 
 Suite Setup Execution
@@ -158,6 +169,35 @@
     Rprint Vars  functional_version
 
 
+Same Firmware Install Two Times
+    [Documentation]  Download same image twice to BMC via ImageURI. Second attempt would fail.
+    [Arguments]  ${apply_time}  ${tftp_server}=${TFTP_SERVER}  ${image_file_name}=${IMAGE_FILE_NAME}
+
+    # Description of argument(s):
+    # apply_time       ApplyTime allowed values (e.g. "OnReset", "Immediate").
+    # tftp_server      Server IP.
+    # image_file_name  Image file name.
+
+    ImageURI Download Install  ${apply_time}
+
+    # Download image from TFTP server via ImageURI to BMC.
+    Redfish.Post  /redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate
+    ...  body={"ImageURI": "tftp://${tftp_server}/${image_file_name}"}
+
+    ${image_version}=  Get Image Version From TFTP Server  ${tftp_server}  ${image_file_name}
+    ${software_inventory_record}=  Get Software Inventory State By Version
+    ...  ${image_version}
+    Rprint Vars  software_inventory_record
+
+    ${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='Enabled'  image_id=${image_id}
+    # Check if the existing firmware is functional.
+    Pass Execution If  ${software_inventory_record['functional']}
+    ...  The existing ${image_version} firmware is already functional.
+
+
 Reboot And Wait For BMC Standby
     [Documentation]  Reboot or wait for BMC standby post reboot.
     [Arguments]  ${policy}  ${start_boot_seconds}