fix nxos_vpc_interface peer_link idempotence (#35737)

* fix peer_link idempotence

* review comment
This commit is contained in:
saichint 2018-02-06 19:05:43 -08:00 committed by Trishna Guha
parent 8a2bda0e06
commit c9e0ce1d7d
2 changed files with 49 additions and 7 deletions

View file

@ -193,12 +193,15 @@ def get_portchannel_vpc_config(module, portchannel):
def get_commands_to_config_vpc_interface(portchannel, delta, config_value, existing):
commands = []
if delta.get('peer-link') is False and existing.get('peer-link') is True:
command = 'no vpc peer-link'
if not delta.get('peer-link') and existing.get('peer-link'):
commands.append('no vpc peer-link')
commands.insert(0, 'interface port-channel{0}'.format(portchannel))
elif delta.get('peer-link') or not existing.get('vpc'):
elif delta.get('peer-link') and not existing.get('peer-link'):
commands.append('vpc peer-link')
commands.insert(0, 'interface port-channel{0}'.format(portchannel))
elif delta.get('vpc') and not existing.get('vpc'):
command = 'vpc {0}'.format(config_value)
commands.append(command)
commands.insert(0, 'interface port-channel{0}'.format(portchannel))

View file

@ -10,7 +10,7 @@
state: enabled
provider: "{{ connection }}"
- name: create port-channel
- name: create port-channel10
nxos_config:
commands:
- interface port-channel10
@ -18,6 +18,14 @@
match: none
provider: "{{ connection }}"
- name: create port-channel11
nxos_config:
commands:
- interface port-channel11
- switchport
match: none
provider: "{{ connection }}"
- name: configure vpc
nxos_vpc:
state: present
@ -33,7 +41,7 @@
- name: Configure vpc port channel
nxos_vpc_interface: &conf
portchannel: 10
vpc: 100
vpc: 10
provider: "{{ connection }}"
register: result
@ -49,10 +57,40 @@
that:
- "result.changed == false"
- name: Configure vpc port channel
nxos_vpc_interface: &conf1
portchannel: 11
peer_link: True
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Conf Idempotence"
nxos_vpc_interface: *conf1
register: result
- assert: *false
- name: Configure vpc port channel
nxos_vpc_interface: &conf2
portchannel: 11
peer_link: False
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Conf Idempotence"
nxos_vpc_interface: *conf2
register: result
- assert: *false
- name: remove vpc port channel
nxos_vpc_interface: &remove
portchannel: 10
vpc: 100
vpc: 10
state: absent
provider: "{{ connection }}"
register: result
@ -82,7 +120,7 @@
- name: remove vpc port channel
nxos_vpc_interface:
portchannel: 10
vpc: 100
vpc: 10
state: absent
provider: "{{ connection }}"
ignore_errors: yes
@ -91,6 +129,7 @@
nxos_config:
commands:
- no interface port-channel10
- no interface port-channel11
match: none
provider: "{{ connection }}"
ignore_errors: yes