Automation enhancement for firmware update

changes:
   - Removed code to replace the image with least priority.
   - New implementation will delete the alternate side image
     and then delete the the image, once image gets deleted
     a fresh image installation will be occur.
   - todo: use redfish URI to boot the image from alternate side.

Change-Id: I3dfe2909eda773cc0cd8bd4f95f10305bbe749c0
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/redfish/extended/redfish_bmc_code_update.robot b/redfish/extended/redfish_bmc_code_update.robot
index ed6659b..25db16a 100644
--- a/redfish/extended/redfish_bmc_code_update.robot
+++ b/redfish/extended/redfish_bmc_code_update.robot
@@ -50,8 +50,24 @@
     Pass Execution If  '${functional_version}' == '${image_version}'
     ...  The existing ${image_version} firmware is already functional.
 
-    Run Keyword If  not ${FORCE_UPDATE}
-    ...  Activate Existing Firmware  ${image_version}
+    # TODO: Replace with redfish ActiveSoftwareImage API.
+    #Run Keyword If  not ${FORCE_UPDATE}
+    #...  Activate Existing Firmware  ${image_version}
+
+    # Firmware inventory record of the given image version.
+    ${image_info}=  Get Software Inventory State By Version  ${image_version}
+
+    ${image_info_len}=  Get Length  ${image_info}
+
+    # REST delete the image to fresh code update for a given same image object
+    # which is already ACTIVE but on the alternate side. Irrespective of when
+    # REST is disabled in near future or the below operation fails, is purely
+    # done to give a chance.
+
+    Run Keyword If  '${image_info_len}' != 0
+    ...  Run Keyword And Ignore Error
+    ...    Delete Software Object  /xyz/openbmc_project/software/${image_info['image_id']}
+
     Redfish Update Firmware