diff --git a/changelogs/fragments/fix_820.yaml b/changelogs/fragments/fix_820.yaml new file mode 100644 index 000000000..b2f1b674c --- /dev/null +++ b/changelogs/fragments/fix_820.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "nxos_snmp_server - correctly render entity traps (https://github.com/ansible-collections/cisco.nxos/issues/820)." diff --git a/plugins/module_utils/network/nxos/rm_templates/snmp_server.py b/plugins/module_utils/network/nxos/rm_templates/snmp_server.py index 35451a47b..4661a0dc1 100644 --- a/plugins/module_utils/network/nxos/rm_templates/snmp_server.py +++ b/plugins/module_utils/network/nxos/rm_templates/snmp_server.py @@ -78,7 +78,11 @@ def _tmplt_users_auth(data): class Snmp_serverTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): - super(Snmp_serverTemplate, self).__init__(lines=lines, tmplt=self, module=module) + super(Snmp_serverTemplate, self).__init__( + lines=lines, + tmplt=self, + module=module, + ) # fmt: off PARSERS = [ @@ -415,10 +419,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-fan-status-change) + \sentity\s(?Pentity_fan_status_change) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-fan-status-change", + "setval": "snmp-server enable traps entity entity_fan_status_change", "result": { "traps": { "entity": { @@ -433,10 +437,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-mib-change) + \sentity\s(?Pentity_mib_change) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-mib-change", + "setval": "snmp-server enable traps entity entity_mib_change", "result": { "traps": { "entity": { @@ -451,10 +455,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-module-inserted) + \sentity\s(?Pentity_module_inserted) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-module-inserted", + "setval": "snmp-server enable traps entity entity_module_inserted", "result": { "traps": { "entity": { @@ -469,10 +473,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-module-status-change) + \sentity\s(?Pentity_module_status_change) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-module-status-change", + "setval": "snmp-server enable traps entity entity_module_status_change", "result": { "traps": { "entity": { @@ -487,10 +491,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-power-out-change) + \sentity\s(?Pentity_power_out_change) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-power-out-change", + "setval": "snmp-server enable traps entity entity_power_out_change", "result": { "traps": { "entity": { @@ -508,7 +512,7 @@ def __init__(self, lines=None, module=None): \sentity\s(?Pentity_power_status_change) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-power-status-change", + "setval": "snmp-server enable traps entity entity_power_status_change", "result": { "traps": { "entity": { @@ -523,10 +527,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-sensor) + \sentity\s(?Pentity_sensor) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-sensor", + "setval": "snmp-server enable traps entity entity_sensor", "result": { "traps": { "entity": { @@ -541,10 +545,10 @@ def __init__(self, lines=None, module=None): r""" ^snmp-server\senable \straps - \sentity\s(?Pentity-unrecognised-module) + \sentity\s(?Pentity_unrecognised_module) $""", re.VERBOSE, ), - "setval": "snmp-server enable traps entity entity-unrecognised-module", + "setval": "snmp-server enable traps entity entity_unrecognised_module", "result": { "traps": { "entity": { diff --git a/tests/unit/modules/network/nxos/test_nxos_snmp_server.py b/tests/unit/modules/network/nxos/test_nxos_snmp_server.py index a15562b10..93aad2c9e 100644 --- a/tests/unit/modules/network/nxos/test_nxos_snmp_server.py +++ b/tests/unit/modules/network/nxos/test_nxos_snmp_server.py @@ -1033,3 +1033,43 @@ def test_nxos_snmp_server_gathered_empty(self): gathered = {} result = self.execute_module(changed=False) self.assertEqual(result["gathered"], gathered) + + def test_nxos_snmp_server_traps_merged_820(self): + # test merged for traps, related to #820 + self.get_config.return_value = dedent( + """\ + """, + ) + set_module_args( + dict( + config=dict( + traps=dict( + entity=dict( + entity_fan_status_change=True, + entity_mib_change=True, + entity_module_inserted=True, + entity_module_removed=True, + entity_module_status_change=True, + entity_power_out_change=True, + entity_power_status_change=True, + entity_unrecognised_module=True, + entity_sensor=True, + ), + ), + ), + state="merged", + ), + ignore_provider_arg, + ) + commands = [ + "snmp-server enable traps entity entity_fan_status_change", + "snmp-server enable traps entity entity_mib_change", + "snmp-server enable traps entity entity_module_inserted", + "snmp-server enable traps entity entity_module_status_change", + "snmp-server enable traps entity entity_power_out_change", + "snmp-server enable traps entity entity_power_status_change", + "snmp-server enable traps entity entity_sensor", + "snmp-server enable traps entity entity_unrecognised_module", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands))