Repository: ansible/ansible

Issue:
(P1) nxos_igmp_interface: 'querier_timeout' is not working as expected
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
- nxos_igmp_interface

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel ddbdf0fd5d) last updated 2017/08/29 14:13:40 (GMT -400)
  config file = None
  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.
-->
Ubuntu 14.04

##### SUMMARY
<!--- Explain the problem briefly -->
`querier_timeout` is behaving abnormally. The task to set it gets the value correctly and applies the correct command , but while running it again the value obtained is different and hence fails the idempotency check.

##### 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.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  - name: Configure igmp interface with non-default values
    nxos_igmp_interface: &non-default
      interface: "{{ intname }}"
      version: 3
      startup_query_interval: 60
      startup_query_count: 5
      robustness: 6
      querier_timeout: 2000
      query_mrt: 12
      query_interval: 200
      last_member_qrt: 2
      last_member_query_count: 4
      report_llg: true
      immediate_leave: true
      restart: false
      state: present
      provider: "{{ connection }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
    "evaluated_to": false,
TASK [nxos_igmp_interface : Configure igmp interface with non-default values] *****************************************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml:26
<n9k-xxx.example.com> connection transport is cli
<n9k-xxx.example.com> using connection plugin network_cli
<n9k-xxx.example.com> socket_path: /root/.ansible/pc/eb89154fe6
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_igmp_interface.py
<n9k-xxx.example.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<n9k-xxx.example.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701 `" && echo ansible-tmp-1504030769.71-240678736088701="` echo /root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701 `" ) && sleep 0'
<n9k-xxx.example.com> PUT /tmp/tmpJBa7HV TO /root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701/nxos_igmp_interface.py
<n9k-xxx.example.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701/ /root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701/nxos_igmp_interface.py && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701/nxos_igmp_interface.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1504030769.71-240678736088701/" > /dev/null 2>&1 && sleep 0'
changed: [n9k-xxx.example.com] => {
    "changed": true,
    "end_state": {
        "group_timeout": "260",
        "immediate_leave": true,
        "last_member_qrt": "2",
        "last_member_query_count": "4",
        "oif_prefix_source": [],
        "oif_routemap": null,
        "querier_timeout": "1206",
        "query_interval": "200",
        "query_mrt": "12",
        "report_llg": true,
        "robustness": "6",
        "startup_query_count": "5",
        "startup_query_interval": "60",
        "version": "3"
    },
    "existing": {
        "group_timeout": "260",
        "immediate_leave": false,
        "last_member_qrt": "1",
        "last_member_query_count": "2",
        "oif_prefix_source": [],
        "oif_routemap": null,
        "querier_timeout": "255",
        "query_interval": "125",
        "query_mrt": "10",
        "report_llg": false,
        "robustness": "2",
        "startup_query_count": "2",
        "startup_query_interval": "31",
        "version": "2"
    },
    "failed": false,
    "invocation": {
        "module_args": {
            "config": null,
            "group_timeout": null,
            "host": null,
            "immediate_leave": true,
            "include_defaults": "True",
            "interface": "Ethernet1/1",
            "last_member_qrt": "2",
            "last_member_query_count": "4",
            "oif_prefix": null,
            "oif_routemap": null,
            "oif_source": null,
            "password": null,
            "port": null,
            "provider": null,
            "querier_timeout": "2000",
            "query_interval": "200",
            "query_mrt": "12",
            "report_llg": true,
            "restart": false,
            "robustness": "6",
            "save": false,
            "ssh_keyfile": null,
            "startup_query_count": "5",
            "startup_query_interval": "60",
            "state": "present",
            "timeout": null,
            "transport": "cli",
            "use_ssl": null,
            "username": null,
            "validate_certs": null,
            "version": "3"
        }
    },
    "proposed": {
        "immediate_leave": true,
        "last_member_qrt": "2",
        "last_member_query_count": "4",
        "querier_timeout": "2000",
        "query_interval": "200",
        "query_mrt": "12",
        "report_llg": true,
        "robustness": "6",
        "startup_query_count": "5",
        "startup_query_interval": "60",
        "version": "3"
    },
    "updates": [
        "interface Ethernet1/1",
        "ip igmp startup-query-interval 60",
        "ip igmp report-link-local-groups",
        "ip igmp last-member-query-response-time 2",
        "ip igmp robustness-variable 6",
        "ip igmp startup-query-count 5",
        "ip igmp immediate-leave",
        "ip igmp version 3",
        "ip igmp query-interval 200",
        "ip igmp last-member-query-count 4",
        "ip igmp querier-timeout 2000",
        "ip igmp query-max-response-time 12"
    ]
}

TASK [nxos_igmp_interface : assert] ***********************************************************************************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml:45
ok: [n9k-xxx.example.com] => {
    "changed": false,
    "failed": false,
    "msg": "All assertions passed"
}

TASK [nxos_igmp_interface : Check Idempotence - Configure igmp interface with non-default values] *********************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml:49
<n9k-xxx.example.com> connection transport is cli
<n9k-xxx.example.com> using connection plugin network_cli
<n9k-xxx.example.com> socket_path: /root/.ansible/pc/eb89154fe6
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_igmp_interface.py
<n9k-xxx.example.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<n9k-xxx.example.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117 `" && echo ansible-tmp-1504030773.14-2497370163117="` echo /root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117 `" ) && sleep 0'
<n9k-xxx.example.com> PUT /tmp/tmpVWC0Ce TO /root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117/nxos_igmp_interface.py
<n9k-xxx.example.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117/ /root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117/nxos_igmp_interface.py && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117/nxos_igmp_interface.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1504030773.14-2497370163117/" > /dev/null 2>&1 && sleep 0'
changed: [n9k-xxx.example.com] => {
    "changed": true,
    "end_state": {
        "group_timeout": "260",
        "immediate_leave": true,
        "last_member_qrt": "2",
        "last_member_query_count": "4",
        "oif_prefix_source": [],
        "oif_routemap": null,
        "querier_timeout": "1206",
        "query_interval": "200",
        "query_mrt": "12",
        "report_llg": true,
        "robustness": "6",
        "startup_query_count": "5",
        "startup_query_interval": "60",
        "version": "3"
    },
    "existing": {
        "group_timeout": "260",
        "immediate_leave": true,
        "last_member_qrt": "2",
        "last_member_query_count": "4",
        "oif_prefix_source": [],
        "oif_routemap": null,
        "querier_timeout": "1206",
        "query_interval": "200",
        "query_mrt": "12",
        "report_llg": true,
        "robustness": "6",
        "startup_query_count": "5",
        "startup_query_interval": "60",
        "version": "3"
    },
    "failed": false,
    "invocation": {
        "module_args": {
            "config": null,
            "group_timeout": null,
            "host": null,
            "immediate_leave": true,
            "include_defaults": "True",
            "interface": "Ethernet1/1",
            "last_member_qrt": "2",
            "last_member_query_count": "4",
            "oif_prefix": null,
            "oif_routemap": null,
            "oif_source": null,
            "password": null,
            "port": null,
            "provider": null,
            "querier_timeout": "2000",
            "query_interval": "200",
            "query_mrt": "12",
            "report_llg": true,
            "restart": false,
            "robustness": "6",
            "save": false,
            "ssh_keyfile": null,
            "startup_query_count": "5",
            "startup_query_interval": "60",
            "state": "present",
            "timeout": null,
            "transport": "cli",
            "use_ssl": null,
            "username": null,
            "validate_certs": null,
            "version": "3"
        }
    },
    "proposed": {
        "immediate_leave": true,
        "last_member_qrt": "2",
        "last_member_query_count": "4",
        "querier_timeout": "2000",
        "query_interval": "200",
        "query_mrt": "12",
        "report_llg": true,
        "robustness": "6",
        "startup_query_count": "5",
        "startup_query_interval": "60",
        "version": "3"
    },
    "updates": [
        "interface Ethernet1/1",
        "ip igmp querier-timeout 2000"
    ]
}

TASK [nxos_igmp_interface : assert] ***********************************************************************************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml:53
FAILED! => {
    "assertion": "result.changed == false",
    "changed": false,
    "evaluated_to": false,
    "failed": true
}
```



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py
--- a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py
+++ b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py
@@ -322,7 +322,7 @@ def get_igmp_interface(module, interface):
         'ConfiguredStartupQueryInterval': 'startup_query_interval',
         'StartupQueryCount': 'startup_query_count',
         'RobustnessVariable': 'robustness',
-        'QuerierTimeout': 'querier_timeout',
+        'ConfiguredQuerierTimeout': 'querier_timeout',
         'ConfiguredMaxResponseTime': 'query_mrt',
         'ConfiguredQueryInterval': 'query_interval',
         'LastMemberMTR': 'last_member_qrt',
@@ -342,9 +342,9 @@ def get_igmp_interface(module, interface):
             igmp['report_llg'] = False
 
         immediate_leave = str(resource['ImmediateLeave'])  # returns en or dis
-        if immediate_leave == 'en':
+        if immediate_leave == 'en' or immediate_leave == 'true':
             igmp['immediate_leave'] = True
-        elif immediate_leave == 'dis':
+        elif immediate_leave == 'dis' or immediate_leave == 'false':
             igmp['immediate_leave'] = False
 
     # the  next block of code is used to retrieve anything with:


Test patch: