Add logic to update firmware functional status of the firmware

Changes:
    - Added new keyword to check for ActiveSoftwareImage
      to filter if the image id and the Links image are same.

Tested:
      robot -v OPENBMC_HOST:xx.xx.xx.xx
      --include Test_Firmware_Image_Switch_Without_Powering_Host
      redfish/update_service/test_bmc_image_switch.robot

      Tested code update with the patch to ensure its not broken.

Change-Id: I580c81f7039575385f10cba75774443550646c3d
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/redfish_code_update_utils.robot b/lib/redfish_code_update_utils.robot
index dd094d0..17ffbe0 100644
--- a/lib/redfish_code_update_utils.robot
+++ b/lib/redfish_code_update_utils.robot
@@ -29,9 +29,41 @@
     ${functional}=  Run Keyword And Return Status
     ...   Should Be Equal  ${sw_functional}  ${image_info["Version"]}
 
+    # If they are not same, return from here.
+    Return From Keyword If  '${functional}' == 'False'  ${functional}
+
+    # WHen the functional and backup firmware versions are same, this ensure, we rightly set the
+    # test inventory dictionary for the firmware functional status.
+    Run Keyword If
+    ...   '${image_info["Description"]}' == 'BMC image' or '${image_info["Description"]}' == 'BMC update'
+    ...   Run Keyword And Return  Find Active Software Image  ${image_id}
+
     [Return]  ${functional}
 
 
+Find Active Software Image
+    [Documentation]  Match the firmware id of ActiveSoftwareImage attribute with the input id.
+    ...              The ActiveSoftwareImage id is the current functional BMC firmware.
+    [Arguments]  ${image_id}
+
+    # Description of argument(s):
+    # image_id   The image ID (e.g. "acc9e073").
+
+    # This attribute tells which is the firmware version currently functional.
+    # "ActiveSoftwareImage": {
+    #         "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/5ca9fec0"
+    #     },
+    ${active_sw_img}=  Redfish.Get Attribute  /redfish/v1/Managers/bmc  Links
+
+    ${active_id}=  Set Variable  ${active_sw_img["ActiveSoftwareImage"]["@odata.id"].split("/")[-1]}
+
+    ${matched_functional}=  Run Keyword And Return Status
+    ...  Should Be Equal As Strings  ${image_id}  ${active_id}
+
+    # Returns True if matched else False.
+    [Return]  ${matched_functional}
+
+
 Get Software Inventory State
     [Documentation]  Return dictionary of the image type, version and functional state
     ...  of the software objects active on the system.