Repository: ansible/ansible

Issue:
nxos_igmp_snooping 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_igmp_snooping

##### ANSIBLE VERSION
<!--- Paste 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]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### 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 some issues with nxos_igmp_snooping module.
* group_timeout parameter accepts 'default' value to put it into default state according to the documentation but if pass 'default' the code errors out.
* platform dependency checks are needed in the test files as all parameters are not supported on all platforms.

Note: I will open a PR shortly to address the above issues


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py b/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py
--- a/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py
+++ b/lib/ansible/modules/network/nxos/nxos_igmp_snooping.py
@@ -53,6 +53,7 @@
     report_supp:
         description:
             - Global IGMPv1/IGMPv2 Report Suppression.
+        type: bool
     v3_report_supp:
         description:
             - Global IGMPv3 Report Suppression and Proxy Reporting.
@@ -127,17 +128,6 @@ def get_group_timeout(config):
     return value
 
 
-def get_snooping(config):
-    REGEX = re.compile(r'{0}$'.format('no ip igmp snooping'), re.M)
-    value = False
-    try:
-        if REGEX.search(config):
-            value = False
-    except TypeError:
-        value = True
-    return value
-
-
 def get_igmp_snooping(module):
     command = 'show ip igmp snooping'
     existing = {}
@@ -196,6 +186,9 @@ def config_igmp_snooping(delta, existing, default=False):
             if default and key == 'group_timeout':
                 if existing.get(key):
                     command = 'no ' + CMDS.get(key).format(existing.get(key))
+            elif value == 'default' and key == 'group_timeout':
+                if existing.get(key):
+                    command = 'no ' + CMDS.get(key).format(existing.get(key))
             else:
                 command = CMDS.get(key).format(value)
         else:


Test patch:
diff --git a/test/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml b/test/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml
--- a/test/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml
+++ b/test/integration/targets/nxos_igmp_snooping/tests/common/sanity.yaml
@@ -3,14 +3,24 @@
 - debug: msg="Using provider={{ connection.transport }}"
   when: ansible_connection == "local"
 
+- set_fact: gt_run="false"
+- set_fact: gt_run="true"
+  when: not (platform is match("N5K")) and not (platform is match("N35"))
+
+- set_fact: group_timeout="never"
+  when: not (platform is match("N5K")) and not (platform is match("N35"))
+
+- set_fact: def_group_timeout="default"
+  when: not (platform is match("N5K")) and not (platform is match("N35"))
+
 - block:
 
   - name: Configure igmp snooping with non-default values
     nxos_igmp_snooping: &non-default
-      snooping: true
-      group_timeout: never
-      link_local_grp_supp: true
-      report_supp: true
+      snooping: false
+      group_timeout: "{{group_timeout|default(omit)}}"
+      link_local_grp_supp: false
+      report_supp: false
       v3_report_supp: true
       state: present
       provider: "{{ connection }}"
@@ -19,14 +29,33 @@
   - assert: &true
       that:
         - "result.changed == true"
+  - block:
+    - name: "Check Idempotence - Configure igmp snooping with non-default values"
+      nxos_igmp_snooping: *non-default
+      register: result
 
-  - name: "Check Idempotence - Configure igmp snooping with non-default values"
-    nxos_igmp_snooping: *non-default
+    - assert: &false
+        that:
+          - "result.changed == false"
+    when: (imagetag and (imagetag is version_compare('D1', 'ne')))
+
+  - name: Configure igmp snooping with default group timeout
+    nxos_igmp_snooping: &defgt
+      group_timeout: "{{def_group_timeout|default(omit)}}"
+      state: present
+      provider: "{{ connection }}"
     register: result
 
-  - assert: &false
-      that:
-        - "result.changed == false"
+  - assert: *true
+    when: gt_run
+
+  - block:
+    - name: "Check Idempotence"
+      nxos_igmp_snooping: *defgt
+      register: result
+
+    - assert: *false
+    when: gt_run or (imagetag and (imagetag is version_compare('D1', 'ne')))
 
   - name: Configure igmp snooping with default values
     nxos_igmp_snooping: &default
@@ -36,11 +65,13 @@
 
   - assert: *true
 
-  - name: "Check Idempotence - Configure igmp snooping with default values"
-    nxos_igmp_snooping: *default
-    register: result
+  - block:
+    - name: "Check Idempotence - Configure igmp snooping with default values"
+      nxos_igmp_snooping: *default
+      register: result
 
-  - assert: *false
+    - assert: *false
+    when: (imagetag and (imagetag is version_compare('D1', 'ne')))
 
   always:
   - name: Configure igmp snooping with default values
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
@@ -1344,7 +1344,6 @@ lib/ansible/modules/network/nxos/nxos_evpn_global.py E326
 lib/ansible/modules/network/nxos/nxos_file_copy.py E324
 lib/ansible/modules/network/nxos/nxos_gir.py E326
 lib/ansible/modules/network/nxos/nxos_igmp_interface.py E326
-lib/ansible/modules/network/nxos/nxos_igmp_snooping.py E325
 lib/ansible/modules/network/nxos/nxos_interface.py E324
 lib/ansible/modules/network/nxos/nxos_lldp.py E326
 lib/ansible/modules/network/nxos/nxos_logging.py E325