Software objects function keywords

Changes:
    - Added new keyword to get the functional state.
    - Added new keyword to build software state dictionary.

Change-Id: I7d9ac02f6c7641ecb86fbbc91a92bceb1e4165bd
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
new file mode 100644
index 0000000..b9fb2aa
--- /dev/null
+++ b/lib/redfish_code_update_utils.robot
@@ -0,0 +1,68 @@
+*** Settings ***
+Documentation   Redfish BMC and PNOR software utilities keywords.
+
+Library         code_update_utils.py
+Library         gen_robot_valid.py
+Resource        bmc_redfish_utils.robot
+
+*** Keywords ***
+
+Get Software Functional State
+    [Documentation]  Return functional or active state of the software (i.e. True/False).
+    [Arguments]  ${image_id}
+
+    # Description of argument(s):
+    # image_id   The image ID (e.g. "acc9e073").
+
+    ${image_info}=  Redfish.Get Properties  /redfish/v1/UpdateService/FirmwareInventory/${image_id}
+
+    ${sw_functional}=  Run Keyword If  '${image_info["Description"]}' == 'BMC update'
+    ...    Redfish.Get Attribute  /redfish/v1/Managers/bmc  FirmwareVersion
+    ...  ELSE
+    ...    Redfish.Get Attribute  /redfish/v1/Systems/system  BiosVersion
+
+    ${functional}=  Run Keyword And Return Status
+    ...   Should Be Equal  ${sw_functional}  ${image_info["Version"]}
+
+    [Return]  ${functional}
+
+
+Get Software Inventory State
+    [Documentation]  Return dictionary of the image type, version and functional state
+    ...  of the software objects active on the system.
+
+    # User defined state for software objects.
+    # Note: "Functional" term refers to firmware which system is currently booted with.
+    # sw_inv_dict:
+    #   [ace821ef]:
+    #     [image_type]:                 Host update
+    #     [functional]:                 True
+    #     [version]:                    witherspoon-xx.xx.xx.xx
+    #   [b9101858]:
+    #     [image_type]:                 BMC update
+    #     [functional]:                 True
+    #     [version]:                    2.8.0-dev-150-g04508dc9f
+    #   [c45eafa5]:
+    #     [image_type]:                 BMC update
+    #     [functional]:                 False
+    #     [version]:                    2.8.0-dev-149-g1a8df5077
+
+    ${sw_member_list}=  Redfish_Utils.Get Member List  /redfish/v1/UpdateService/FirmwareInventory
+    &{sw_inv_dict}=  Create Dictionary
+
+    # sw_member_list:
+    #   [0]:                            /redfish/v1/UpdateService/FirmwareInventory/98744d76
+    #   [1]:                            /redfish/v1/UpdateService/FirmwareInventory/9a8028ec
+    #   [2]:                            /redfish/v1/UpdateService/FirmwareInventory/acc9e073
+
+    FOR  ${uri_path}  IN  @{sw_member_list}
+        &{tmp_dict}=  Create Dictionary
+        ${image_info}=  Redfish.Get Properties  ${uri_path}
+        Set To Dictionary  ${tmp_dict}  image_type  ${image_info["Description"]}
+        ${functional}=  Get Software Functional State  ${uri_path.split("/")[-1]}
+        Set To Dictionary  ${tmp_dict}  functional  ${functional}
+        Set To Dictionary  ${sw_inv_dict}  ${uri_path.split("/")[-1]}  ${tmp_dict}
+        Set To Dictionary  ${tmp_dict}  version  ${image_info["Version"]}
+    END
+
+    [Return]  &{sw_inv_dict}