Skip to content

Commit

Permalink
[snmp_server] correctly render entity traps
Browse files Browse the repository at this point in the history
Signed-off-by: NilashishC <[email protected]>
  • Loading branch information
NilashishC committed Jun 24, 2024
1 parent 19b2473 commit b11bce0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/fix_820.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "nxos_snmp_server - correctly render entity traps (https://github.com/ansible-collections/cisco.nxos/issues/820)."
36 changes: 20 additions & 16 deletions plugins/module_utils/network/nxos/rm_templates/snmp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -415,10 +419,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_fan_status_change>entity-fan-status-change)
\sentity\s(?P<entity_fan_status_change>entity_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": {
Expand All @@ -433,10 +437,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_mib_change>entity-mib-change)
\sentity\s(?P<entity_mib_change>entity_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": {
Expand All @@ -451,10 +455,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_module_inserted>entity-module-inserted)
\sentity\s(?P<entity_module_inserted>entity_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": {
Expand All @@ -469,10 +473,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_module_status_change>entity-module-status-change)
\sentity\s(?P<entity_module_status_change>entity_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": {
Expand All @@ -487,10 +491,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_power_out_change>entity-power-out-change)
\sentity\s(?P<entity_power_out_change>entity_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": {
Expand All @@ -508,7 +512,7 @@ def __init__(self, lines=None, module=None):
\sentity\s(?P<entity_power_status_change>entity_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": {
Expand All @@ -523,10 +527,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_sensor>entity-sensor)
\sentity\s(?P<entity_sensor>entity_sensor)
$""", re.VERBOSE,
),
"setval": "snmp-server enable traps entity entity-sensor",
"setval": "snmp-server enable traps entity entity_sensor",
"result": {
"traps": {
"entity": {
Expand All @@ -541,10 +545,10 @@ def __init__(self, lines=None, module=None):
r"""
^snmp-server\senable
\straps
\sentity\s(?P<entity_unrecognised_module>entity-unrecognised-module)
\sentity\s(?P<entity_unrecognised_module>entity_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": {
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/modules/network/nxos/test_nxos_snmp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit b11bce0

Please sign in to comment.