Get Software Inventory State By Version
Change-Id: Ida3e67ce1fe14b6f789ea66a3e1c1b1ce4106095
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 b9fb2aa..ad091f8 100644
--- a/lib/redfish_code_update_utils.robot
+++ b/lib/redfish_code_update_utils.robot
@@ -36,14 +36,17 @@
# sw_inv_dict:
# [ace821ef]:
# [image_type]: Host update
+ # [image_id]: ace821ef
# [functional]: True
# [version]: witherspoon-xx.xx.xx.xx
# [b9101858]:
# [image_type]: BMC update
+ # [image_id]: b9101858
# [functional]: True
# [version]: 2.8.0-dev-150-g04508dc9f
# [c45eafa5]:
# [image_type]: BMC update
+ # [image_id]: c45eafa5
# [functional]: False
# [version]: 2.8.0-dev-149-g1a8df5077
@@ -59,10 +62,40 @@
&{tmp_dict}= Create Dictionary
${image_info}= Redfish.Get Properties ${uri_path}
Set To Dictionary ${tmp_dict} image_type ${image_info["Description"]}
+ Set To Dictionary ${tmp_dict} image_id ${uri_path.split("/")[-1]}
${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"]}
+ Set To Dictionary ${sw_inv_dict} ${uri_path.split("/")[-1]} ${tmp_dict}
END
[Return] &{sw_inv_dict}
+
+
+Get Software Inventory State By Version
+ [Documentation] Return the software inventory record that matches the given software version.
+ [Arguments] ${software_version}
+
+ # If no matchine record can be found, return ${EMPTY}.
+
+ # Example of returned data:
+ # software_inventory_record:
+ # [image_type]: BMC update
+ # [image_id]: 1e662ba8
+ # [functional]: True
+ # [version]: 2.8.0-dev-150-g04508dc9f
+
+ # Description of argument(s):
+ # software_version A BMC or Host version (e.g "2.8.0-dev-150-g04508dc9f").
+
+ ${software_inventory}= Get Software Inventory State
+ # Filter out entries that don't match the criterion..
+ ${software_inventory}= Filter Struct ${software_inventory} [('version', '${software_version}')]
+ # Convert from dictionary to list.
+ ${software_inventory}= Get Dictionary Values ${software_inventory}
+ ${num_records}= Get Length ${software_inventory}
+
+ Return From Keyword If ${num_records} == ${0} ${EMPTY}
+
+ # Return the first list entry.
+ [Return] ${software_inventory}[0]