diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_af.py b/lib/ansible/modules/network/nxos/nxos_vrf_af.py index 281674ea17..1a653e0ae6 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_af.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_af.py @@ -124,14 +124,14 @@ def main(): if current: have = 'route-target both auto evpn' in current - want = bool(module.params['route_target_both_auto_evpn']) - - if want and not have: - commands.append('address-family %s unicast' % module.params['afi']) - commands.append('route-target both auto evpn') - elif have and not want: - commands.append('address-family %s unicast' % module.params['afi']) - commands.append('no route-target both auto evpn') + if module.params['route_target_both_auto_evpn'] is not None: + want = bool(module.params['route_target_both_auto_evpn']) + if want and not have: + commands.append('address-family %s unicast' % module.params['afi']) + commands.append('route-target both auto evpn') + elif have and not want: + commands.append('address-family %s unicast' % module.params['afi']) + commands.append('no route-target both auto evpn') else: commands.append('address-family %s unicast' % module.params['afi']) diff --git a/test/integration/targets/nxos_vrf_af/tests/common/sanity.yaml b/test/integration/targets/nxos_vrf_af/tests/common/sanity.yaml index 1f88064d06..6ae55d97dc 100644 --- a/test/integration/targets/nxos_vrf_af/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_vrf_af/tests/common/sanity.yaml @@ -13,18 +13,20 @@ nxos_config: commands: "feature nv overlay" provider: "{{ connection }}" + ignore_errors: yes - name: Configure nv overlay evpn nxos_config: commands: "nv overlay evpn" provider: "{{ connection }}" + ignore_errors: yes - block: - - name: Configure vrf af - nxos_vrf_af: &configure + - name: Configure vrf af ipv4 + nxos_vrf_af: &configure4 vrf: ansible afi: ipv4 - route_target_both_auto_evpn: true + route_target_both_auto_evpn: True provider: "{{ connection }}" register: result @@ -33,18 +35,66 @@ - "result.changed == true" - name: "Conf Idempotence" - nxos_vrf_af: *configure + nxos_vrf_af: *configure4 register: result - assert: &false that: - "result.changed == false" - - name: Remove vrf af - nxos_vrf_af: &remove + - name: Configure vrf af ipv6 + nxos_vrf_af: &configure6 + vrf: ansible + afi: ipv6 + route_target_both_auto_evpn: True + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Conf Idempotence" + nxos_vrf_af: *configure6 + register: result + + - assert: *false + + - name: Remove router target4 + nxos_vrf_af: &rrt4 vrf: ansible afi: ipv4 - route_target_both_auto_evpn: true + route_target_both_auto_evpn: False + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Conf Idempotence" + nxos_vrf_af: *rrt4 + register: result + + - assert: *false + + - name: Remove router target6 + nxos_vrf_af: &rrt6 + vrf: ansible + afi: ipv6 + route_target_both_auto_evpn: False + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Conf Idempotence" + nxos_vrf_af: *rrt6 + register: result + + - assert: *false + + - name: Remove vrf af v6 + nxos_vrf_af: &remove6 + vrf: ansible + afi: ipv6 + route_target_both_auto_evpn: True state: absent provider: "{{ connection }}" register: result @@ -55,21 +105,37 @@ seconds: 30 - name: "Remove Idempotence" - nxos_vrf_af: *remove + nxos_vrf_af: *remove6 register: result - assert: *false - always: - - name: Remove feature bgp - nxos_feature: - feature: bgp - state: disabled + - name: Remove vrf af v4 + nxos_vrf_af: &remove4 + vrf: ansible + afi: ipv4 + route_target_both_auto_evpn: True + state: absent provider: "{{ connection }}" + register: result - - name: Remove feature nv overlay + - assert: *true + + - pause: + seconds: 30 + + - name: "Remove Idempotence" + nxos_vrf_af: *remove4 + register: result + + - assert: *false + + when: not platform is search("N35") + + always: + - name: Remove vrf nxos_config: - commands: "no feature nv overlay" + commands: "no vrf context ansible" provider: "{{ connection }}" ignore_errors: yes @@ -79,4 +145,16 @@ provider: "{{ connection }}" ignore_errors: yes + - name: Remove feature nv overlay + nxos_config: + commands: "no feature nv overlay" + provider: "{{ connection }}" + ignore_errors: yes + + - name: Remove feature bgp + nxos_feature: + feature: bgp + state: disabled + provider: "{{ connection }}" + - debug: msg="END connection={{ ansible_connection }} nxos_vrf_af sanity test"