From d459c2c58267c9788969e8e7061f9b4626bd9291 Mon Sep 17 00:00:00 2001 From: Jose Delarosa Date: Thu, 6 Dec 2018 12:52:31 -0600 Subject: [PATCH] Fix idempotency issues 2 (#49333) * Fix idempotency issues in set_manager_attributes * Add changed status in set_bios_default_settings --- lib/ansible/module_utils/redfish_utils.py | 30 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index d6b81069da..d030ce6612 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -629,7 +629,7 @@ class RedfishUtils(object): response = self.post_request(self.root_uri + reset_bios_settings_uri, {}, HEADERS) if response['ret'] is False: return response - return {'ret': True} + return {'ret': True, 'changed': True, 'msg': "Set BIOS to default settings"} def set_one_time_boot_device(self, bootdevice): result = {} @@ -664,7 +664,25 @@ class RedfishUtils(object): return {'ret': True} def set_manager_attributes(self, attr): - attributes = "Attributes" + result = {} + # Here I'm making the assumption that the key 'Attributes' is part of the URI. + # It may not, but in the hardware I tested with, getting to the final URI where + # the Manager Attributes are, appear to be part of a specific OEM extension. + key = "Attributes" + + # Search for key entry and extract URI from it + response = self.get_request(self.root_uri + self.manager_uri + "/" + key) + if response['ret'] is False: + return response + result['ret'] = True + data = response['data'] + + if key not in data: + return {'ret': False, 'msg': "Key %s not found" % key} + + # Check if attribute exists + if attr['mgr_attr_name'] not in data[key]: + return {'ret': False, 'msg': "Manager attribute %s not found" % attr['mgr_attr_name']} # Example: manager_attr = {\"name\":\"value\"} # Check if value is a number. If so, convert to int. @@ -673,11 +691,15 @@ class RedfishUtils(object): else: manager_attr = "{\"%s\": \"%s\"}" % (attr['mgr_attr_name'], attr['mgr_attr_value']) + # Find out if value is already set to what we want. If yes, return + if data[key][attr['mgr_attr_name']] == attr['mgr_attr_value']: + return {'ret': True, 'changed': False, 'msg': "Manager attribute already set"} + payload = {"Attributes": json.loads(manager_attr)} - response = self.patch_request(self.root_uri + self.manager_uri + "/" + attributes, payload, HEADERS) + response = self.patch_request(self.root_uri + self.manager_uri + "/" + key, payload, HEADERS) if response['ret'] is False: return response - return {'ret': True} + return {'ret': True, 'changed': True, 'msg': "Modified Manager attribute %s" % attr['mgr_attr_name']} def set_bios_attributes(self, attr): result = {}