From e8f1c1511cc140c7a8f32326dc2802ea9ab4000b Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Thu, 10 Aug 2017 19:59:32 +0200 Subject: [PATCH] Implement purge on eos_vrf (#28013) --- lib/ansible/modules/network/eos/eos_vrf.py | 9 +++++- .../targets/eos_vrf/tests/cli/basic.yaml | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/network/eos/eos_vrf.py b/lib/ansible/modules/network/eos/eos_vrf.py index 2bade69df0a..9dbd84c7dd7 100644 --- a/lib/ansible/modules/network/eos/eos_vrf.py +++ b/lib/ansible/modules/network/eos/eos_vrf.py @@ -91,6 +91,7 @@ def map_obj_to_commands(updates, module): commands = list() want, have = updates state = module.params['state'] + purge = module.params['purge'] for w in want: name = w['name'] @@ -100,7 +101,7 @@ def map_obj_to_commands(updates, module): obj_in_have = search_obj_in_list(name, have) if state == 'absent': - if have: + if obj_in_have: commands.append('no vrf definition %s' % name) elif state == 'present': if not obj_in_have: @@ -130,6 +131,12 @@ def map_obj_to_commands(updates, module): commands.append('interface %s' % i) commands.append('vrf forwarding %s' % w['name']) + if purge: + for h in have: + obj_in_want = search_obj_in_list(h['name'], want) + if not obj_in_want: + commands.append('no vrf definition %s' % h['name']) + return commands diff --git a/test/integration/targets/eos_vrf/tests/cli/basic.yaml b/test/integration/targets/eos_vrf/tests/cli/basic.yaml index 55d6a5aa196..546b314d874 100644 --- a/test/integration/targets/eos_vrf/tests/cli/basic.yaml +++ b/test/integration/targets/eos_vrf/tests/cli/basic.yaml @@ -161,6 +161,30 @@ # Ensure sessions contains epoc. Will fail after 18th May 2033 - "result.session_name is not defined" +- name: Create aggregate of VRFs with purge + eos_vrf: + aggregate: + - { name: test4, rd: "1:204" } + - { name: test5, rd: "1:205" } + state: present + purge: yes + authorize: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.changed == true" + - "'vrf definition test4' in result.commands" + - "'rd 1:204' in result.commands" + - "'vrf definition test5' in result.commands" + - "'rd 1:205' in result.commands" + - "'no vrf definition test' in result.commands" + - "'no vrf definition test2' in result.commands" + - "'no vrf definition test3' in result.commands" + # Ensure sessions contains epoc. Will fail after 18th May 2033 + - "'ansible_1' in result.session_name" + - name: Delete VRFs eos_vrf: name: test @@ -180,6 +204,8 @@ aggregate: - { name: test2 } - { name: test3 } + - { name: test4 } + - { name: test5 } state: absent authorize: yes provider: "{{ cli }}" @@ -189,6 +215,8 @@ aggregate: - { name: test2 } - { name: test3 } + - { name: test4 } + - { name: test5 } state: absent authorize: yes provider: "{{ cli }}"