Fix nxos_vrf issues (#37092)

* fix nxos_vrf issues

* fix doc
This commit is contained in:
saichint 2018-03-13 04:38:37 -07:00 committed by Trishna Guha
parent ba5e562c76
commit dc61f4c6b1
2 changed files with 72 additions and 24 deletions

View file

@ -74,7 +74,7 @@ options:
interfaces: interfaces:
description: description:
- List of interfaces to check the VRF has been - List of interfaces to check the VRF has been
configured correctly. configured correctly or keyword 'default'.
version_added: 2.5 version_added: 2.5
associated_interfaces: associated_interfaces:
description: description:
@ -98,7 +98,7 @@ options:
choices: ['present','absent'] choices: ['present','absent']
description: description:
description: description:
- Description of the VRF. - Description of the VRF or keyword 'default'.
required: false required: false
default: null default: null
delay: delay:
@ -257,7 +257,7 @@ def map_obj_to_commands(updates, module):
commands.append('vrf context {0}'.format(name)) commands.append('vrf context {0}'.format(name))
for item in args: for item in args:
candidate = w.get(item) candidate = w.get(item)
if candidate: if candidate and candidate != 'default':
cmd = item + ' ' + str(candidate) cmd = item + ' ' + str(candidate)
commands.append(cmd) commands.append(cmd)
if admin_state == 'up': if admin_state == 'up':
@ -266,7 +266,7 @@ def map_obj_to_commands(updates, module):
commands.append('shutdown') commands.append('shutdown')
commands.append('exit') commands.append('exit')
if interfaces: if interfaces and interfaces[0] != 'default':
for i in interfaces: for i in interfaces:
commands.append('interface {0}'.format(i)) commands.append('interface {0}'.format(i))
commands.append('no switchport') commands.append('no switchport')
@ -280,7 +280,11 @@ def map_obj_to_commands(updates, module):
for item in args: for item in args:
candidate = w.get(item) candidate = w.get(item)
if candidate and candidate != obj_in_have.get(item): if candidate == 'default':
if obj_in_have.get(item):
cmd = 'no ' + item + ' ' + obj_in_have.get(item)
commands.append(cmd)
elif candidate and candidate != obj_in_have.get(item):
cmd = item + ' ' + str(candidate) cmd = item + ' ' + str(candidate)
commands.append(cmd) commands.append(cmd)
if admin_state and admin_state != obj_in_have.get('admin_state'): if admin_state and admin_state != obj_in_have.get('admin_state'):
@ -293,7 +297,7 @@ def map_obj_to_commands(updates, module):
commands.insert(0, 'vrf context {0}'.format(name)) commands.insert(0, 'vrf context {0}'.format(name))
commands.append('exit') commands.append('exit')
if interfaces: if interfaces and interfaces[0] != 'default':
if not obj_in_have['interfaces']: if not obj_in_have['interfaces']:
for i in interfaces: for i in interfaces:
commands.append('vrf context {0}'.format(name)) commands.append('vrf context {0}'.format(name))
@ -318,6 +322,14 @@ def map_obj_to_commands(updates, module):
commands.append('interface {0}'.format(i)) commands.append('interface {0}'.format(i))
commands.append('no switchport') commands.append('no switchport')
commands.append('no vrf member {0}'.format(name)) commands.append('no vrf member {0}'.format(name))
elif interfaces and interfaces[0] == 'default':
if obj_in_have['interfaces']:
for i in obj_in_have['interfaces']:
commands.append('vrf context {0}'.format(name))
commands.append('exit')
commands.append('interface {0}'.format(i))
commands.append('no switchport')
commands.append('no vrf member {0}'.format(name))
if purge: if purge:
existing = get_existing_vrfs(module) existing = get_existing_vrfs(module)

View file

@ -3,21 +3,39 @@
- debug: msg="Using provider={{ connection.transport }}" - debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local" when: ansible_connection == "local"
- block: - set_fact: intname1="{{ nxos_int1 }}"
- name: 'Setup: Delete VRF before test' - set_fact: intname2="{{ nxos_int2 }}"
nxos_config:
lines:
- no vrf context ntc
provider: "{{ connection }}"
ignore_errors: yes
- set_fact: rdnd="1:2"
when: (platform is not match("N35|N7K")) and ((imagetag != 'I2'))
- set_fact: rdd="default"
when: (platform is not match("N35|N7K")) and ((imagetag != 'I2'))
- set_fact: vnind="5000"
when: platform is not match("N35|N7K")
- set_fact: vnid="default"
when: platform is not match("N35|N7K")
- name: "Enable feature BGP"
nxos_feature:
feature: bgp
state: enabled
provider: "{{ connection }}"
ignore_errors: yes
- block:
- name: Ensure ntc VRF exists on switch - name: Ensure ntc VRF exists on switch
nxos_vrf: &configure nxos_vrf: &configure
vrf: ntc vrf: ntc
admin_state: down admin_state: down
description: testing description: testing
#vni: 5000 vni: "{{vnind|default(omit)}}"
#rd: auto rd: "{{rdnd|default(omit)}}"
interfaces:
- "{{ intname1 }}"
- "{{ intname2 }}"
provider: "{{ connection }}" provider: "{{ connection }}"
register: result register: result
@ -33,13 +51,30 @@
that: that:
- "result.changed == false" - "result.changed == false"
- pause:
seconds: 30
- name: Remove config
nxos_vrf: &remconf
vrf: ntc
admin_state: up
vni: "{{vnid|default(omit)}}"
rd: "{{rdd|default(omit)}}"
interfaces: default
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Conf Idempotence"
nxos_vrf: *remconf
register: result
- assert: *false
- name: Ensure ntc VRF does not exist on switch - name: Ensure ntc VRF does not exist on switch
nxos_vrf: &remove nxos_vrf: &remove
vrf: ntc vrf: ntc
admin_state: down
description: testing
#vni: 5000
#rd: auto
state: absent state: absent
provider: "{{ connection }}" provider: "{{ connection }}"
register: result register: result
@ -55,11 +90,12 @@
- assert: *false - assert: *false
- name: 'Teardown: Delete VRF after test' always:
nxos_config: - name: "Disable feature BGP"
lines: nxos_feature:
- no vrf context ntc feature: bgp
state: disabled
provider: "{{ connection }}" provider: "{{ connection }}"
ignore_errors: yes ignore_errors: yes
- debug: msg="END connection={{ ansible_connection }} nxos_vrf sanity test" - debug: msg="END connection={{ ansible_connection }} nxos_vrf sanity test"