Repository: ansible/ansible

Issue:
nxos_vxlan_vtep does not configure properly
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
nxos_vxlan_vtep

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel b49be56c5b) last updated 2017/07/13 12:38:51 (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/p2/Projects/nxos_ansible/fix_ansible/lib/ansible
  executable location = /root/p2/Projects/nxos_ansible/fix_ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
Ansible Server : Ubuntu 14.04
Device: Nexus9000 C9396PX running 7.0(3)I2(2e)

##### SUMMARY
When we run a playbook for configuring vxlan_vtep on the node, it only creates an interface nve but no other parameters are being configured.

##### STEPS TO REPRODUCE
playbook:

```
- hosts: nxos
  connection: local
  gather_facts: no

  tasks:
  - name: configure vxlan_vtep
    nxos_vxlan_vtep: &configure
      interface: nve1
      description: default
      host_reachability: true
      source_interface: Loopback0
      source_interface_hold_down_time: 30
      shutdown: true
```

##### EXPECTED RESULTS
On the node we should see
```
interface nve1
  no description
  source-interface loopback0
  host-reachability protocol bgp
  source-interface hold-down-time 30
  shutdown
```
##### ACTUAL RESULTS
```
interface nve1
```



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @privateip @rahushen @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_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
@@ -150,7 +150,7 @@ def get_value(arg, config, module):
         value = ''
         if arg == 'description':
             if NO_DESC_REGEX.search(config):
-                value = ''
+                value = False
             elif PARAM_TO_COMMAND_KEYMAP[arg] in config:
                 value = REGEX.search(config).group('value').strip()
         elif arg == 'source_interface':
@@ -169,7 +169,7 @@ def get_value(arg, config, module):
 
 def get_existing(module, args):
     existing = {}
-    netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
+    netcfg = CustomNetworkConfig(indent=2, contents=get_config(module, flags=['all']))
 
     interface_string = 'interface {0}'.format(module.params['interface'].lower())
     parents = [interface_string]
@@ -294,18 +294,14 @@ def main():
     proposed = {}
     for key, value in proposed_args.items():
         if key != 'interface':
-            if str(value).lower() == 'true':
-                value = True
-            elif str(value).lower() == 'false':
-                value = False
-            elif str(value).lower() == 'default':
+            if str(value).lower() == 'default':
                 value = PARAM_TO_DEFAULT_KEYMAP.get(key)
                 if value is None:
                     if key in BOOL_PARAMS:
                         value = False
                     else:
                         value = 'default'
-            if existing.get(key) != value:
+            if str(existing.get(key)).lower() != str(value).lower():
                 proposed[key] = value
 
     candidate = CustomNetworkConfig(indent=3)


Test patch:
diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml
--- a/test/integration/nxos.yaml
+++ b/test/integration/nxos.yaml
@@ -213,6 +213,15 @@
             failed_modules: "{{ failed_modules }} + [ 'nxos_portchannel' ]"
             test_failed: true
 
+    - block:
+      - include_role:
+          name: nxos_vxlan_vtep
+        when: "limit_to in ['*', 'nxos_vxlan_vtep']"
+      rescue:
+        - set_fact:
+            failed_modules: "{{ failed_modules }} + [ 'nxos_vxlan_vtep' ]"
+            test_failed: true
+
     - block:
       - include_role:
           name: nxos_logging
diff --git a/test/integration/targets/nxos_vxlan_vtep/defaults/main.yaml b/test/integration/targets/nxos_vxlan_vtep/defaults/main.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/defaults/main.yaml
@@ -0,0 +1,2 @@
+---
+testcase: "*"
diff --git a/test/integration/targets/nxos_vxlan_vtep/meta/main.yml b/test/integration/targets/nxos_vxlan_vtep/meta/main.yml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/meta/main.yml
@@ -0,0 +1,2 @@
+dependencies:
+  - prepare_nxos_tests
diff --git a/test/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml b/test/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/tasks/cli.yaml
@@ -0,0 +1,15 @@
+---
+- name: collect all cli test cases
+  find:
+    paths: "{{ role_path }}/tests/cli"
+    patterns: "{{ testcase }}.yaml"
+  register: test_cases
+
+- name: set test_items
+  set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
+
+- name: run test case
+  include: "{{ test_case_to_run }}"
+  with_items: "{{ test_items }}"
+  loop_control:
+    loop_var: test_case_to_run
diff --git a/test/integration/targets/nxos_vxlan_vtep/tasks/main.yaml b/test/integration/targets/nxos_vxlan_vtep/tasks/main.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/tasks/main.yaml
@@ -0,0 +1,3 @@
+---
+- { include: cli.yaml, tags: ['cli'] }
+- { include: nxapi.yaml, tags: ['nxapi'] }
diff --git a/test/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml b/test/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/tasks/nxapi.yaml
@@ -0,0 +1,28 @@
+---
+- name: collect all nxapi test cases
+  find:
+    paths: "{{ role_path }}/tests/nxapi"
+    patterns: "{{ testcase }}.yaml"
+  register: test_cases
+
+- name: set test_items
+  set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
+
+- name: enable nxapi
+  nxos_config:
+    lines:
+      - feature nxapi
+      - nxapi http port 80
+    provider: "{{ cli }}"
+
+- name: run test case
+  include: "{{ test_case_to_run }}"
+  with_items: "{{ test_items }}"
+  loop_control:
+    loop_var: test_case_to_run
+
+- name: disable nxapi
+  nxos_config:
+    lines:
+      - no feature nxapi
+    provider: "{{ cli }}"
diff --git a/test/integration/targets/nxos_vxlan_vtep/tests/cli/sanity.yaml b/test/integration/targets/nxos_vxlan_vtep/tests/cli/sanity.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/tests/cli/sanity.yaml
@@ -0,0 +1,4 @@
+---
+- set_fact: connection="{{ cli }}"
+
+- import_tasks: targets/nxos_vxlan_vtep/tests/common/sanity.yaml
diff --git a/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml b/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/tests/common/sanity.yaml
@@ -0,0 +1,65 @@
+---
+- - debug: msg="START TRANSPORT:{{ connection.transport }} nxos_vxlan_vtep sanity test"
+
+- block:
+  - name: "Enable feature nv overlay"
+    nxos_config: 
+      commands:
+        - feature nv overlay
+      provider: "{{ connection }}"
+      match: none
+
+  - name: configure vxlan_vtep
+    nxos_vxlan_vtep: &configure
+      interface: nve1
+      description: default
+      host_reachability: true
+      source_interface: Loopback0
+      source_interface_hold_down_time: 30
+      shutdown: true
+      provider: "{{ connection }}"
+    register: result
+
+  - assert: &true
+      that:
+        - "result.changed == true"
+
+  - name: "Conf Idempotence"
+    nxos_vxlan_vtep: *configure
+    register: result
+
+  - assert: &false
+      that:
+        - "result.changed == false"
+
+  - name: remove vxlan_vtep
+    nxos_vxlan_vtep: &remove
+      interface: nve1
+      description: default
+      host_reachability: true
+      source_interface: Loopback0
+      source_interface_hold_down_time: 30
+      shutdown: true
+      state: absent
+      provider: "{{ connection }}"
+    register: result
+
+  - assert: *true
+
+  - name: "Remove Idempotence"
+    nxos_vxlan_vtep: *remove
+    register: result
+
+  - assert: *false
+
+  when: (platform | search('N9K'))
+
+  always:
+  - name: "Disable feature nv overlay"
+    nxos_feature: 
+      feature: nve
+      state: disabled
+      provider: "{{ connection }}"
+    ignore_errors: yes
+
+- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_vxlan_vtep sanity test"
diff --git a/test/integration/targets/nxos_vxlan_vtep/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_vxlan_vtep/tests/nxapi/sanity.yaml
new file mode 100644
--- /dev/null
+++ b/test/integration/targets/nxos_vxlan_vtep/tests/nxapi/sanity.yaml
@@ -0,0 +1,4 @@
+---
+- set_fact: connection="{{ nxapi }}"
+
+- import_tasks: targets/nxos_vxlan_vtep/tests/common/sanity.yaml