Repository: ansible/ansible

Issue:
nxos_igmp 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
##### 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]
```

##### OS / ENVIRONMENT
<!---
Mention 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 some issues with nxos_igmp module.
1. If the 'restart' parameter is set to True, the module is throwing bad command errors.
2. Currently all the parameters can be set to false but there is no way to set individual parameters to false if they are already in true state.

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.py b/lib/ansible/modules/network/nxos/nxos_igmp.py
--- a/lib/ansible/modules/network/nxos/nxos_igmp.py
+++ b/lib/ansible/modules/network/nxos/nxos_igmp.py
@@ -132,10 +132,12 @@ def main():
             commands.append('no ip igmp enforce-router-alert')
 
     elif state == 'present':
-        if desired['flush_routes'] and not current['flush_routes']:
-            commands.append('ip igmp flush-routes')
-        if desired['enforce_rtr_alert'] and not current['enforce_rtr_alert']:
-            commands.append('ip igmp enforce-router-alert')
+        ldict = {'flush_routes': 'flush-routes', 'enforce_rtr_alert': 'enforce-router-alert'}
+        for arg in ['flush_routes', 'enforce_rtr_alert']:
+            if desired[arg] and not current[arg]:
+                commands.append('ip igmp {0}'.format(ldict.get(arg)))
+            elif current[arg] and not desired[arg]:
+                commands.append('no ip igmp {0}'.format(ldict.get(arg)))
 
     result = {'changed': False, 'updates': commands, 'warnings': warnings}
 
@@ -145,7 +147,8 @@ def main():
         result['changed'] = True
 
     if module.params['restart']:
-        run_commands(module, 'restart igmp')
+        cmd = {'command': 'restart igmp', 'output': 'text'}
+        run_commands(module, cmd)
 
     module.exit_json(**result)
 


Test patch:
diff --git a/test/integration/targets/nxos_igmp/tests/common/sanity.yaml b/test/integration/targets/nxos_igmp/tests/common/sanity.yaml
--- a/test/integration/targets/nxos_igmp/tests/common/sanity.yaml
+++ b/test/integration/targets/nxos_igmp/tests/common/sanity.yaml
@@ -3,6 +3,9 @@
 - debug: msg="Using provider={{ connection.transport }}"
   when: ansible_connection == "local"
 
+- set_fact: restart="true"
+  when: platform is not match("N35")
+
 - block:
 
   - name: Configure igmp with non-default values
@@ -26,23 +29,45 @@
       that:
         - "result.changed == false"
 
-  - name: Configure igmp with default values
+  - name: Configure igmp defaults
     nxos_igmp: &default
-      state: default
+      flush_routes: false
+      enforce_rtr_alert: false
+      restart: "{{restart|default(omit)}}"
+      state: present
       provider: "{{ connection }}"
     register: result
 
   - assert: *true
 
-  - name: "Check Idempotence - Configure igmp with default values"
+  - name: "Check Idempotence - Configure igmp with defaults"
     nxos_igmp: *default
     register: result
 
   - assert: *false
 
+  - name: Configure igmp non-defaults again
+    nxos_igmp: *non-default
+    register: result
+
+  - name: Configure igmp state as values
+    nxos_igmp: &sdefault
+      state: default
+      provider: "{{ connection }}"
+    register: result
+
+  - assert: *true
+
+  - name: "Check Idempotence - Configure igmp with state default"
+    nxos_igmp: *sdefault
+    register: result
+
+  - assert: *false
+
   always:
   - name: Configure igmp with default values
-    nxos_igmp: *default
+    nxos_igmp: *sdefault
     register: result
+    ignore_errors: yes
 
   - debug: msg="END connection={{ ansible_connection }} nxos_igmp sanity test"