From c9e0ce1d7dc5f9764a862f4e414fa6b78d7e10fa Mon Sep 17 00:00:00 2001 From: saichint Date: Tue, 6 Feb 2018 19:05:43 -0800 Subject: [PATCH] fix nxos_vpc_interface peer_link idempotence (#35737) * fix peer_link idempotence * review comment --- .../network/nxos/nxos_vpc_interface.py | 9 ++-- .../tests/common/sanity.yaml | 47 +++++++++++++++++-- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vpc_interface.py b/lib/ansible/modules/network/nxos/nxos_vpc_interface.py index cbf445d110c..def6947c338 100644 --- a/lib/ansible/modules/network/nxos/nxos_vpc_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vpc_interface.py @@ -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)) diff --git a/test/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml b/test/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml index fa05b915e4d..749d4ae2305 100644 --- a/test/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_vpc_interface/tests/common/sanity.yaml @@ -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