Repository: ansible/ansible

Issue:
nxos_snmp_community issues
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
Always add information AFTER of these html comments. -->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
nxos_snmp_community

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.0 (devel fed20b825f) last updated 2018/02/15 12:51:12 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
Ansible Server : Ubuntu 14.04
Device: N9K running 7.0(3)I2(5)
##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

There are couple of issues with nxos_snmp_community module.
1. acl  parameter cannot be removed by itself unless we remove the entire configuration.
2. default for acl is given as 1 in docs which is wrong.

Note: I will open a PR shortly to address the above issues
nxos_snmp_community issues
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
Always add information AFTER of these html comments. -->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
nxos_snmp_community

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.0 (devel fed20b825f) last updated 2018/02/15 12:51:12 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
Ansible Server : Ubuntu 14.04
Device: N9K running 7.0(3)I2(5)
##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

There are couple of issues with nxos_snmp_community module.
1. acl  parameter cannot be removed by itself unless we remove the entire configuration.
2. default for acl is given as 1 in docs which is wrong.

Note: I will open a PR shortly to address the above issues


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_snmp_community.py b/lib/ansible/modules/network/nxos/nxos_snmp_community.py
--- a/lib/ansible/modules/network/nxos/nxos_snmp_community.py
+++ b/lib/ansible/modules/network/nxos/nxos_snmp_community.py
@@ -48,8 +48,7 @@
             - Group to which the community belongs.
     acl:
         description:
-            - ACL name to filter snmp requests.
-        default: 1
+            - ACL name to filter snmp requests or keyword 'default'.
     state:
         description:
             - Manage the state of the resource.
@@ -150,7 +149,8 @@ def get_snmp_community(module, name):
 def config_snmp_community(delta, community):
     CMDS = {
         'group': 'snmp-server community {0} group {group}',
-        'acl': 'snmp-server community {0} use-acl {acl}'
+        'acl': 'snmp-server community {0} use-acl {acl}',
+        'no_acl': 'no snmp-server community {0} use-acl {no_acl}'
     }
     commands = []
     for k, v in delta.items():
@@ -203,6 +203,10 @@ def main():
     args = dict(group=group, acl=acl)
     proposed = dict((k, v) for k, v in args.items() if v is not None)
     delta = dict(set(proposed.items()).difference(existing.items()))
+    if delta.get('acl') == 'default':
+        delta.pop('acl')
+        if existing.get('acl'):
+            delta['no_acl'] = existing.get('acl')
 
     commands = []
 


Test patch:
diff --git a/test/integration/targets/nxos_snmp_community/tests/common/sanity.yaml b/test/integration/targets/nxos_snmp_community/tests/common/sanity.yaml
--- a/test/integration/targets/nxos_snmp_community/tests/common/sanity.yaml
+++ b/test/integration/targets/nxos_snmp_community/tests/common/sanity.yaml
@@ -17,7 +17,6 @@
     nxos_snmp_community: &config
       community: TESTING7
       group: network-operator
-      #access: ro
       state: present
       provider: "{{ connection }}"
     register: result
@@ -34,6 +33,22 @@
       that:
         - "result.changed == false"
 
+  - name: Change snmp_community group
+    nxos_snmp_community: &chg
+      community: TESTING7
+      group: network-admin
+      state: present
+      provider: "{{ connection }}"
+    register: result
+
+  - assert: *true
+
+  - name: Idempotence Check
+    nxos_snmp_community: *chg
+    register: result
+
+  - assert: *false
+
   - name: Remove snmp_community
     nxos_snmp_community: *remove
     register: result
@@ -91,6 +106,40 @@
 
   - assert: *false
 
+  - name: Change acl
+    nxos_snmp_community: &chgacl
+      community: TESTING7
+      access: rw
+      acl: new_acl
+      state: present
+      provider: "{{ connection }}"
+    register: result
+
+  - assert: *true
+
+  - name: Idempotence Check
+    nxos_snmp_community: *chgacl
+    register: result
+
+  - assert: *false
+
+  - name: Remove acl
+    nxos_snmp_community: &removeacl
+      community: TESTING7
+      access: rw
+      acl: default
+      state: present
+      provider: "{{ connection }}"
+    register: result
+
+  - assert: *true
+
+  - name: Idempotence Check
+    nxos_snmp_community: *removeacl
+    register: result
+
+  - assert: *false
+
   always:
   - name: Cleanup
     nxos_snmp_community: *remove
diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt
--- a/test/sanity/validate-modules/ignore.txt
+++ b/test/sanity/validate-modules/ignore.txt
@@ -1202,7 +1202,6 @@ lib/ansible/modules/network/nxos/nxos_pim_interface.py E326
 lib/ansible/modules/network/nxos/nxos_pim_rp_address.py E326
 lib/ansible/modules/network/nxos/nxos_reboot.py E325
 lib/ansible/modules/network/nxos/nxos_smu.py E324
-lib/ansible/modules/network/nxos/nxos_snmp_community.py E324
 lib/ansible/modules/network/nxos/nxos_system.py E325
 lib/ansible/modules/network/nxos/nxos_vpc.py E324
 lib/ansible/modules/network/nxos/nxos_vpc_interface.py E325