summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Wiebe <mwiebe@cisco.com>2017-09-14 19:25:35 +0200
committerNathaniel Case <this.is@nathanielca.se>2017-09-14 19:25:35 +0200
commit3faba93a2bf4bd3187ce62f39ca01e4fc0272da6 (patch)
tree85944d33eb0569fe67c12179b2547ac9058dc2a8
parentFix import error. Was pointing to the wrong module (#30293) (diff)
downloadansible-3faba93a2bf4bd3187ce62f39ca01e4fc0272da6.tar.xz
ansible-3faba93a2bf4bd3187ce62f39ca01e4fc0272da6.zip
Fix nxos_interface error for nxapi and idempotence problem (#29136)
* Fix nxos_interface nxapi error and idempotence * Make shippable happy
-rw-r--r--lib/ansible/modules/network/nxos/nxos_interface.py17
-rw-r--r--test/integration/targets/nxos_interface/tests/common/sanity.yaml131
2 files changed, 139 insertions, 9 deletions
diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py
index a27f61bcac..ef9d518938 100644
--- a/lib/ansible/modules/network/nxos/nxos_interface.py
+++ b/lib/ansible/modules/network/nxos/nxos_interface.py
@@ -214,22 +214,21 @@ def get_manual_interface_attributes(interface, module):
"""
if get_interface_type(interface) == 'svi':
- command = 'show interface {0}'.format(interface)
+ command = 'show run interface {0} all'.format(interface)
try:
- body = run_commands(module, [command])[0]
+ # body = run_commands(module, [command])[0]
+ body = execute_show_command(command, module)[0]
except IndexError:
return None
-
if body:
command_list = body.split('\n')
desc = None
- admin_state = 'up'
+ admin_state = 'down'
for each in command_list:
- if 'Description:' in each:
- line = each.split('Description:')
- desc = line[1].strip().split('MTU')[0].strip()
- elif 'Administratively down' in each:
- admin_state = 'down'
+ if 'description' in each:
+ desc = each.lstrip().split("description")[1].lstrip()
+ elif 'no shutdown' in each:
+ admin_state = 'up'
return dict(description=desc, admin_state=admin_state)
else:
diff --git a/test/integration/targets/nxos_interface/tests/common/sanity.yaml b/test/integration/targets/nxos_interface/tests/common/sanity.yaml
new file mode 100644
index 0000000000..e5bcfbcb38
--- /dev/null
+++ b/test/integration/targets/nxos_interface/tests/common/sanity.yaml
@@ -0,0 +1,131 @@
+---
+- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_interface sanity test"
+
+- set_fact: testint="{{ nxos_int1 }}"
+
+- name: "Setup: Enable feature interface-vlan"
+ nxos_feature:
+ feature: interface-vlan
+ state: enabled
+ provider: "{{ connection }}"
+ ignore_errors: yes
+
+- name: "Setup: Put interface {{ testint }} into a default state"
+ nxos_config: &intcleanup
+ lines:
+ - "default interface {{ testint }}"
+ provider: "{{ connection }}"
+ ignore_errors: yes
+
+- name: "Setup: Remove possibly existing vlan interfaces"
+ nxos_config: &vlanintcleanup
+ lines:
+ - "no interface vlan 2"
+ - "no interface vlan 710"
+ - "no interface vlan 711"
+ - "no interface vlan 712"
+ provider: "{{ connection }}"
+ ignore_errors: yes
+
+- block:
+ - name: "Configure layer3 params"
+ nxos_interface: &l3config
+ interface: "{{ testint }}"
+ mode: layer3
+ description: 'Configured by Ansible - Layer3'
+ admin_state: 'up'
+ state: present
+ provider: "{{ connection }}"
+ register: result
+
+ - assert: &true
+ that:
+ - "result.changed == true"
+
+ - name: "Check Idempotence"
+ nxos_interface: *l3config
+ register: result
+
+ - assert: &false
+ that:
+ - "result.changed == false"
+
+ - name: "Configure layer2 params"
+ nxos_interface: &l2config
+ interface: "{{ testint }}"
+ mode: layer2
+ description: 'Configured by Ansible - Layer2'
+ admin_state: 'down'
+ state: present
+ provider: "{{ connection }}"
+ register: result
+
+ - assert: *true
+
+ - name: "Check Idempotence"
+ nxos_interface: *l2config
+ register: result
+
+ - assert: *false
+
+ - name: Create VLAN Interfaces
+ nxos_interface: &createvlans
+ interface: "{{ item.os_svi_int }}"
+ description: "{{ item.os_svi_desc }}"
+ provider: "{{ connection }}"
+ with_items: &vlanitems
+ - {os_svi_int: vlan2, os_svi_desc: SVI_VLAN2}
+ - {os_svi_int: vlan710, os_svi_desc: SVI_VLAN710}
+ - {os_svi_int: vlan711, os_svi_desc: SVI_VLAN711}
+ - {os_svi_int: vlan712, os_svi_desc: SVI_VLAN712}
+ register: result
+
+ - assert: *true
+
+ - name: Configure Required SVI
+ nxos_ip_interface: &addips
+ interface: "{{ item.os_svi_int }}"
+ addr: "{{ item.ipv4_addr }}"
+ mask: "{{ item.ipv4_mask }}"
+ version: "{{ item.ipv4_ver }}"
+ provider: "{{ connection }}"
+ with_items: &vlanips
+ - {os_svi_int: vlan2, ipv4_addr: 192.168.2.1, ipv4_mask: 24, ipv4_ver: v4}
+ - {os_svi_int: vlan710, ipv4_addr: 192.168.3.1, ipv4_mask: 24, ipv4_ver: v4}
+ - {os_svi_int: vlan711, ipv4_addr: 192.168.4.1, ipv4_mask: 24, ipv4_ver: v4}
+ - {os_svi_int: vlan712, ipv4_addr: 192.168.5.1, ipv4_mask: 24, ipv4_ver: v4}
+ register: result
+
+ - assert: *true
+
+ - name: Create VLAN Interfaces Idempotence Check
+ nxos_interface: *createvlans
+ with_items: *vlanitems
+ register: result
+
+ - assert: *false
+
+ - name: Configure Required SVI Idempotence Check
+ nxos_ip_interface: *addips
+ with_items: *vlanips
+ register: result
+
+ - assert: *false
+
+ rescue:
+ - name: "Set interface back to default"
+ nxos_config: *intcleanup
+ ignore_errors: yes
+
+ - name: "Remove vlan interfaces"
+ nxos_config: *vlanintcleanup
+
+ - name: "Setup: Disable feature interface-vlan"
+ nxos_feature:
+ feature: interface-vlan
+ state: disabled
+ provider: "{{ connection }}"
+ ignore_errors: yes
+
+ always:
+ - debug: msg="END TRANSPORT:{{ connection.transport }} nxos_interface sanity test"