1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

modified redfish_config and idrac_redfish_config to skip incorrect attributes (#2334)

* modified redfish_config and idrac_redfish_config to skip incorrect attributes

Signed-off-by: Trevor Squillario Trevor_Squillario@Dell.com

* modified redfish_utils.py and idrac_redfish_config.py to return empty warning message

* modified redfish_config.py and idrac_redfish_config.py to use module.warn()

* updated changelog fragment for pr 2334
This commit is contained in:
TrevorSquillario 2021-05-11 11:30:09 -06:00 committed by GitHub
parent eea4f45965
commit 9d46ccf1b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 12 deletions

View file

@ -0,0 +1,4 @@
minor_changes:
- redfish_utils module utils - modified set_bios_attributes function to skip invalid attribute instead of returning. Added skipped attributes to output (https://github.com/ansible-collections/community.general/issues/1995).
- idrac_redfish_config - modified set_manager_attributes function to skip invalid attribute instead of returning. Added skipped attributes to output. Modified module exit to add warning variable (https://github.com/ansible-collections/community.general/issues/1995).
- redfish_config - modified module exit to add warning variable (https://github.com/ansible-collections/community.general/issues/1995).

View file

@ -1671,19 +1671,31 @@ class RedfishUtils(object):
# Make a copy of the attributes dict
attrs_to_patch = dict(attributes)
# List to hold attributes not found
attrs_bad = {}
# Check the attributes
for attr in attributes:
if attr not in data[u'Attributes']:
return {'ret': False, 'msg': "BIOS attribute %s not found" % attr}
for attr_name, attr_value in attributes.items():
# Check if attribute exists
if attr_name not in data[u'Attributes']:
# Remove and proceed to next attribute if this isn't valid
attrs_bad.update({attr_name: attr_value})
del attrs_to_patch[attr_name]
continue
# If already set to requested value, remove it from PATCH payload
if data[u'Attributes'][attr] == attributes[attr]:
del attrs_to_patch[attr]
if data[u'Attributes'][attr_name] == attributes[attr_name]:
del attrs_to_patch[attr_name]
warning = ""
if attrs_bad:
warning = "Incorrect attributes %s" % (attrs_bad)
# Return success w/ changed=False if no attrs need to be changed
if not attrs_to_patch:
return {'ret': True, 'changed': False,
'msg': "BIOS attributes already set"}
'msg': "BIOS attributes already set",
'warning': warning}
# Get the SettingsObject URI
set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"]["@odata.id"]
@ -1693,7 +1705,9 @@ class RedfishUtils(object):
response = self.patch_request(self.root_uri + set_bios_attr_uri, payload)
if response['ret'] is False:
return response
return {'ret': True, 'changed': True, 'msg': "Modified BIOS attribute"}
return {'ret': True, 'changed': True,
'msg': "Modified BIOS attributes %s" % (attrs_to_patch),
'warning': warning}
def set_boot_order(self, boot_list):
if not boot_list:

View file

@ -179,6 +179,7 @@ class IdracRedfishUtils(RedfishUtils):
attrs_to_patch = {}
attrs_skipped = {}
attrs_bad = {} # Store attrs which were not found in the system
# Search for key entry and extract URI from it
response = self.get_request(self.root_uri + manager_uri + "/" + key)
@ -189,13 +190,15 @@ class IdracRedfishUtils(RedfishUtils):
if key not in data:
return {'ret': False,
'msg': "%s: Key %s not found" % (command, key)}
'msg': "%s: Key %s not found" % (command, key),
'warning': ""}
for attr_name, attr_value in attributes.items():
# Check if attribute exists
if attr_name not in data[u'Attributes']:
return {'ret': False,
'msg': "%s: Manager attribute %s not found" % (command, attr_name)}
# Skip and proceed to next attribute if this isn't valid
attrs_bad.update({attr_name: attr_value})
continue
# Find out if value is already set to what we want. If yes, exclude
# those attributes
@ -204,16 +207,23 @@ class IdracRedfishUtils(RedfishUtils):
else:
attrs_to_patch.update({attr_name: attr_value})
warning = ""
if attrs_bad:
warning = "Incorrect attributes %s" % (attrs_bad)
if not attrs_to_patch:
return {'ret': True, 'changed': False,
'msg': "Manager attributes already set"}
'msg': "No changes made. Manager attributes already set.",
'warning': warning}
payload = {"Attributes": attrs_to_patch}
response = self.patch_request(self.root_uri + manager_uri + "/" + key, payload)
if response['ret'] is False:
return response
return {'ret': True, 'changed': True,
'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch)}
'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch),
'warning': warning}
CATEGORY_COMMANDS_ALL = {
@ -221,6 +231,7 @@ CATEGORY_COMMANDS_ALL = {
"SetSystemAttributes"]
}
# list of mutually exclusive commands for a category
CATEGORY_COMMANDS_MUTUALLY_EXCLUSIVE = {
"Manager": [["SetManagerAttributes", "SetLifecycleControllerAttributes",
@ -308,6 +319,9 @@ def main():
# Return data back or fail with proper message
if result['ret'] is True:
if result.get('warning'):
module.warn(to_native(result['warning']))
module.exit_json(changed=result['changed'], msg=to_native(result['msg']))
else:
module.fail_json(msg=to_native(result['msg']))

View file

@ -321,6 +321,9 @@ def main():
# Return data back or fail with proper message
if result['ret'] is True:
if result.get('warning'):
module.warn(to_native(result['warning']))
module.exit_json(changed=result['changed'], msg=to_native(result['msg']))
else:
module.fail_json(msg=to_native(result['msg']))