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

nxos_hsrp: fix 'sh_preempt': <unknown enum:> (#52858)

* nxos_hsrp: fix 'sh_preempt': <unknown enum:>

Some older nxos images fail to set this attr value. This fix checks for
unknown enum and issues a second (unstructured) call to the device to get
the data.

* add whitespace for pep8
This commit is contained in:
Chris Van Heuveln 2019-02-27 03:50:50 -05:00 committed by Trishna Guha
parent b1f117ec99
commit 5dc65d0dfc
2 changed files with 17 additions and 2 deletions

View file

@ -211,6 +211,8 @@ def get_hsrp_group(group, interface, module):
try: try:
body = run_commands(module, [command])[0] body = run_commands(module, [command])[0]
hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail'] hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail']
if 'unknown enum:' in str(hsrp_table):
hsrp_table = get_hsrp_group_unknown_enum(module, command, hsrp_table)
except (AttributeError, IndexError, TypeError, KeyError): except (AttributeError, IndexError, TypeError, KeyError):
return {} return {}
@ -239,6 +241,19 @@ def get_hsrp_group(group, interface, module):
return hsrp return hsrp
def get_hsrp_group_unknown_enum(module, command, hsrp_table):
'''Some older NXOS images fail to set the attr values when using structured output and
instead set the values to <unknown enum>. This fallback method is a workaround that
uses an unstructured (text) request to query the device a second time.
'sh_preempt' is currently the only attr affected. Add checks for other attrs as needed.
'''
if 'unknown enum:' in hsrp_table['sh_preempt']:
cmd = {'output': 'text', 'command': command.split('|')[0]}
out = run_commands(module, cmd)[0]
hsrp_table['sh_preempt'] = 'enabled' if ('may preempt' in out) else 'disabled'
return hsrp_table
def get_commands_remove_hsrp(group, interface): def get_commands_remove_hsrp(group, interface):
commands = ['interface {0}'.format(interface), 'no hsrp {0}'.format(group)] commands = ['interface {0}'.format(interface), 'no hsrp {0}'.format(group)]
return commands return commands