Repository: ansible/ansible

Issue:
nxos_vxlan_vtep is not idempotent for source_interface_hold_down_time
<!---
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 or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
nxos_vxlan_vtep
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.0 (devel 788010d0f0) last updated 2018/01/08 11:49:21 (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)I5(3)
##### SUMMARY
<!--- Explain the problem briefly -->
1. source_interface_hold_down_time has a default value of 180. In the ansible code, this is not defined in the defaults and it is causing idempotent issues. However on older platforms, this is not shown in "show running-config interface <int> all" and so this problem was not seen but in all the newer platforms, this issue is visible.
2. In the documentation, shutdown default is shown as false, which is not correct.
3. m_facts is defined as a param in the code but there is no such thing.

I will open a PR shortly to address this issue.

##### EXPECTED RESULTS
```
PLAY RECAP **************************************************************************************************************************************************
n9k.example.com   : ok=61   changed=10   unreachable=0    failed=0
```
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
TASK [nxos_vxlan_vtep : assert] *****************************************************************************************************************************
fatal: [n9k.example.com]: FAILED! => {
    "assertion": "result.changed == false",
    "attempts": 1,
    "changed": false,
    "evaluated_to": false
}
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py
--- a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py
+++ b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py
@@ -58,7 +58,7 @@
       - Administratively shutdown the NVE interface.
     required: false
     choices: ['true','false']
-    default: false
+    default: true
   source_interface:
     description:
       - Specify the loopback interface whose IP address should be
@@ -100,6 +100,7 @@
 '''
 
 import re
+
 from ansible.module_utils.network.nxos.nxos import get_config, load_config
 from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
 from ansible.module_utils.basic import AnsibleModule
@@ -120,6 +121,7 @@
 PARAM_TO_DEFAULT_KEYMAP = {
     'description': False,
     'shutdown': True,
+    'source_interface_hold_down_time': '180',
 }
 
 
@@ -270,7 +272,6 @@ def main():
         shutdown=dict(required=False, type='bool'),
         source_interface=dict(required=False, type='str'),
         source_interface_hold_down_time=dict(required=False, type='str'),
-        m_facts=dict(required=False, default=False, type='bool'),
         state=dict(choices=['present', 'absent'], default='present', required=False),
     )
 


Test patch:
diff --git a/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml b/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml
--- a/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml
+++ b/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml
@@ -1,5 +1,5 @@
 ---
-- - debug: msg="START connection={{ ansible_connection }} nxos_vxlan_vtep sanity test"
+- debug: msg="START connection={{ ansible_connection }} nxos_vxlan_vtep sanity test"
 - debug: msg="Using provider={{ connection.transport }}"
   when: ansible_connection == "local"
 
@@ -19,11 +19,11 @@
     - name: configure vxlan_vtep
       nxos_vxlan_vtep: &configure9
         interface: nve1
-        description: default
+        description: "abcd"
         host_reachability: true
         source_interface: Loopback0
         source_interface_hold_down_time: 30
-        shutdown: true
+        shutdown: false
         provider: "{{ connection }}"
       register: result
   
@@ -39,6 +39,25 @@
         that:
           - "result.changed == false"
 
+    - name: reset vxlan_vtep
+      nxos_vxlan_vtep: &def9
+        interface: nve1
+        description: default
+        host_reachability: false
+        source_interface_hold_down_time: default
+        source_interface: default
+        shutdown: true
+        provider: "{{ connection }}"
+      register: result
+  
+    - assert: *true
+  
+    - name: "reset Idempotence"
+      nxos_vxlan_vtep: *def9
+      register: result
+
+    - assert: *false
+
     when: (platform is search('N9K'))
 
   - block:
@@ -48,7 +67,7 @@
         description: default
         host_reachability: true
         source_interface: Loopback0
-        shutdown: true
+        shutdown: false
         provider: "{{ connection }}"
       register: result
   
@@ -64,6 +83,24 @@
         that:
           - "result.changed == false"
 
+    - name: reset vxlan_vtep
+      nxos_vxlan_vtep: &def7
+        interface: nve1
+        description: default
+        host_reachability: false
+        source_interface: default
+        shutdown: true
+        provider: "{{ connection }}"
+      register: result
+  
+    - assert: *true
+  
+    - name: "reset Idempotence"
+      nxos_vxlan_vtep: *def7
+      register: result
+
+    - assert: *false
+
     when: (platform is search('N7K'))
 
   - name: remove vxlan_vtep