From 5e5cba985fc80d76b03c0b575ae81c60945f7199 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:26:50 +0000 Subject: [PATCH] [PR #7952/dd7c3ad1 backport][stable-7] Fix errors in hpe specific get methods (#8021) Fix errors in hpe specific get methods (#7952) * Fix errors in hpe specific get methods * corrects reference to non existent `self.chassis_uri_list` to `self.chassis_uris` * corrects syntactically incorrect dereferences * removes an uneccessary variable assignment to `chassis_uri_list` in `get_psu_inventory` method * adds changelog fragment for above indicating fix of issue #7951 * Update changelog. --------- Co-authored-by: Felix Fontein (cherry picked from commit dd7c3ad10d706267ffcd1bea1337a148dfce60af) Co-authored-by: Dave Rawks --- .../7951-fix-redfish_info-exception.yml | 2 ++ plugins/module_utils/redfish_utils.py | 26 ++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) create mode 100644 changelogs/fragments/7951-fix-redfish_info-exception.yml diff --git a/changelogs/fragments/7951-fix-redfish_info-exception.yml b/changelogs/fragments/7951-fix-redfish_info-exception.yml new file mode 100644 index 0000000000..cd5707da4b --- /dev/null +++ b/changelogs/fragments/7951-fix-redfish_info-exception.yml @@ -0,0 +1,2 @@ +bugfixes: + - "redfish_info - correct uncaught exception when attempting to retrieve ``Chassis`` information (https://github.com/ansible-collections/community.general/pull/7952)." diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index a4b1673ac6..c7580dbc88 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -2915,8 +2915,7 @@ class RedfishUtils(object): # Get a list of all Chassis and build URIs, then get all PowerSupplies # from each Power entry in the Chassis - chassis_uri_list = self.chassis_uris - for chassis_uri in chassis_uri_list: + for chassis_uri in self.chassis_uris: response = self.get_request(self.root_uri + chassis_uri) if response['ret'] is False: return response @@ -3478,33 +3477,30 @@ class RedfishUtils(object): result = {} key = "Thermal" # Go through list - for chassis_uri in self.chassis_uri_list: + for chassis_uri in self.chassis_uris: response = self.get_request(self.root_uri + chassis_uri) if response['ret'] is False: return response result['ret'] = True data = response['data'] - oem = data.get['Oem'] - hpe = oem.get['Hpe'] - thermal_config = hpe.get('ThermalConfiguration') - result["current_thermal_config"] = thermal_config - return result + val = data.get('Oem', {}).get('Hpe', {}).get('ThermalConfiguration') + if val is not None: + return {"ret": True, "current_thermal_config": val} + return {"ret": False} def get_hpe_fan_percent_min(self): result = {} key = "Thermal" # Go through list - for chassis_uri in self.chassis_uri_list: + for chassis_uri in self.chassis_uris: response = self.get_request(self.root_uri + chassis_uri) if response['ret'] is False: return response - result['ret'] = True data = response['data'] - oem = data.get['Oem'] - hpe = oem.get['Hpe'] - fan_percent_min_config = hpe.get('FanPercentMinimum') - result["fan_percent_min"] = fan_percent_min_config - return result + val = data.get('Oem', {}).get('Hpe', {}).get('FanPercentMinimum') + if val is not None: + return {"ret": True, "fan_percent_min": val} + return {"ret": False} def delete_volumes(self, storage_subsystem_id, volume_ids): # Find the Storage resource from the requested ComputerSystem resource