From 46f185c2175184b8970d079a4b9bfcf10e0549da Mon Sep 17 00:00:00 2001 From: Chris Van Heuveln Date: Tue, 7 May 2019 04:27:55 -0400 Subject: [PATCH] nxos_snmp_traps: fix 'group: all' for N35 platforms (#55995) * nxos_snmp_traps: fix 'group: all' for N35 platforms - `group: all` attempts to enable traps for all features defined in the module's `feature_list` - `N35` platforms do not support `snmp-server enable traps bfd`; so removing `bfd` from the `feature_list` for that platform - Minor cleanup in `sanity.yaml` test file * whitespace lint fix (cherry picked from commit 0e0c2a7db7670133bf2f4e762bc46ae8c4efc6be) --- changelogs/fragments/nxos_snmp_traps_28.yaml | 2 ++ lib/ansible/modules/network/nxos/nxos_snmp_traps.py | 11 +++++++++++ .../targets/nxos_snmp_traps/tests/common/sanity.yaml | 9 ++++----- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/nxos_snmp_traps_28.yaml diff --git a/changelogs/fragments/nxos_snmp_traps_28.yaml b/changelogs/fragments/nxos_snmp_traps_28.yaml new file mode 100644 index 00000000000..983a31acf3d --- /dev/null +++ b/changelogs/fragments/nxos_snmp_traps_28.yaml @@ -0,0 +1,2 @@ +bugfixes: +- nxos_snmp_traps fix group all for N35 platforms (https://github.com/ansible/ansible/pull/55995). diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_traps.py b/lib/ansible/modules/network/nxos/nxos_snmp_traps.py index d42eca87bed..b0a32bc251c 100644 --- a/lib/ansible/modules/network/nxos/nxos_snmp_traps.py +++ b/lib/ansible/modules/network/nxos/nxos_snmp_traps.py @@ -78,9 +78,15 @@ commands: from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args +from ansible.module_utils.network.nxos.nxos import get_capabilities from ansible.module_utils.basic import AnsibleModule +def get_platform_id(module): + info = get_capabilities(module).get('device_info', {}) + return (info.get('network_os_platform', '')) + + def execute_show_command(command, module): command = { 'command': command, @@ -110,6 +116,11 @@ def get_snmp_traps(group, module): 'rf', 'rmon', 'snmp', 'storm-control', 'stpx', 'switchfabric', 'syslog', 'sysmgr', 'system', 'upgrade', 'vtp'] + + if 'all' in group and 'N3K-C35' in get_platform_id(module): + module.warn("Platform does not support bfd traps; bfd ignored for 'group: all' request") + feature_list.remove('bfd') + for each in feature_list: for line in body: if each == 'ospf': diff --git a/test/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml b/test/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml index 29212ec1e40..7d7df1e8241 100644 --- a/test/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_snmp_traps/tests/common/sanity.yaml @@ -5,14 +5,14 @@ - name: Setup - Remove snmp_traps if configured nxos_snmp_traps: &remove - group: all + group: all provider: "{{ connection }}" state: disabled - block: - - name: Configure one snmp trap group + - name: Configure one snmp trap group nxos_snmp_traps: &config - group: bridge + group: bridge provider: "{{ connection }}" state: enabled register: result @@ -60,10 +60,9 @@ - name: Idempotence Check nxos_snmp_traps: *config1 register: result - when: imagetag is not search("I2|D1") - assert: *false - when: imagetag is not search("I2|D1") + when: imagetag is not search("I2|I7|D1") - name: Cleanup nxos_snmp_traps: *remove