mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
refactor iosxr_system for cliconf and netconf (#34749)
* * refactor iosxr_system for cliconf and netconf * * Fix unit tests and sanity issues
This commit is contained in:
committed by
Chris Alfonso
parent
0f692f1fe7
commit
93acd7c651
@@ -1,2 +1,3 @@
|
||||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
|
||||
22
test/integration/targets/iosxr_system/tasks/netconf.yaml
Normal file
22
test/integration/targets/iosxr_system/tasks/netconf.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/netconf"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=local)
|
||||
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
|
||||
# - name: run test case (connection=netconf)
|
||||
# include: "{{ test_case_to_run }} ansible_connection=netconf"
|
||||
# with_items: "{{ test_items }}"
|
||||
# loop_control:
|
||||
# loop_var: test_case_to_run
|
||||
@@ -81,6 +81,13 @@
|
||||
- result.commands|length == 1
|
||||
- "'no domain name-server 3.3.3.3' in result.commands"
|
||||
|
||||
# FIXME: No teardown
|
||||
#
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no ip name-server 1.1.1.1
|
||||
- no ip name-server 2.2.2.2
|
||||
- no ip name-server 3.3.3.3
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- debug: msg="END cli/set_name_servers.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "START netconf/set_domain_search.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- block:
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no domain list ansible.com
|
||||
- no domain list redhat.com
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure domain_search
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ansible.com' in result.xml[0]"
|
||||
- "'redhat.com' in result.xml[0]"
|
||||
|
||||
- name: configure domain_search with vrf
|
||||
iosxr_system: &domainvrf
|
||||
vrf: ansiblevrf
|
||||
domain_search:
|
||||
- redhat.com
|
||||
- ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ansiblevrf' in result.xml[0]"
|
||||
- "'ansible.com' in result.xml[0]"
|
||||
- "'redhat.com' in result.xml[0]"
|
||||
|
||||
- name: verify domain_search with vrf
|
||||
iosxr_system: *domainvrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: delete domain_search with vrf
|
||||
iosxr_system: &deldomainvrf
|
||||
vrf: ansiblevrf
|
||||
domain_search:
|
||||
- redhat.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'ansiblevrf' in result.xml[0]"
|
||||
- "'ansible.com' in result.xml[0]"
|
||||
|
||||
- name: verify delete domain_search with vrf
|
||||
iosxr_system: *deldomainvrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: remove one entry
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'redhat.com' in result.xml[0]"
|
||||
|
||||
- name: verify remove one entry
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: add one entry
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'redhat.com' in result.xml[0]"
|
||||
|
||||
- name: verify add one entry
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: add and remove one entry
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- eng.ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'redhat.com' in result.xml[1]"
|
||||
- "'eng.ansible.com' in result.xml[0]"
|
||||
- result.xml|length == 2
|
||||
|
||||
- name: verify add and remove one entry
|
||||
iosxr_system:
|
||||
domain_search:
|
||||
- ansible.com
|
||||
- eng.ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- always:
|
||||
- name: teardown
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no domain list ansible.com
|
||||
- no domain list redhat.com
|
||||
- no domain list eng.ansible.com
|
||||
- no domain vrf ansiblevrf list redhat.com
|
||||
- no domain vrf ansiblevrf list ansible.com
|
||||
match: none
|
||||
provider: "{{ netconf }}"
|
||||
|
||||
- debug:
|
||||
msg: "END netconf/set_domain_search.yaml on connection={{ ansible_connection }}"
|
||||
@@ -0,0 +1,79 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "START netconf/set_domain_name.yaml on connection={{ ansible_connection }}"
|
||||
- block:
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no domain name
|
||||
- no domain vrf ansiblevrf name
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure domain_name
|
||||
iosxr_system: &domain
|
||||
domain_name: eng.ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: verify domain_name
|
||||
iosxr_system: *domain
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure domain_name
|
||||
iosxr_system: &deldomain
|
||||
domain_name: eng.ansible.com
|
||||
provider: "{{ netconf }}"
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: verify domain_name
|
||||
iosxr_system: *deldomain
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure domain_name with vrf
|
||||
iosxr_system: &domainvrf
|
||||
domain_name: eng.ansible.com
|
||||
vrf: ansiblevrf
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: verify domain_name with vrf
|
||||
iosxr_system: *domainvrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- always:
|
||||
- name: teardown
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no domain name
|
||||
- no domain vrf ansiblevrf name
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- debug:
|
||||
msg: "END netconf/set_domain_name.yaml on connection={{ ansible_connection }}"
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "START netconf/set_hostname.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- block:
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: hostname switch
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure hostname
|
||||
iosxr_system:
|
||||
hostname: foo
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: verify hostname
|
||||
iosxr_system:
|
||||
hostname: foo
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
- always:
|
||||
- name: teardown
|
||||
iosxr_config:
|
||||
lines: "hostname {{ inventory_hostname }}"
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- debug:
|
||||
msg: "END netconf/set_hostname.yaml on connection={{ ansible_connection }}"
|
||||
@@ -0,0 +1,150 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "START netconf/set_lookup_source.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- block:
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no domain lookup source-interface Loopback10
|
||||
- no domain vrf ansiblevrf lookup source-interface Loopback10
|
||||
- no domain lookup disable
|
||||
- no domain vrf ansiblevrf lookup disable
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: configure lookup_source
|
||||
iosxr_system: &lookup
|
||||
lookup_source: Loopback10
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'Loopback10' in result.xml[0]"
|
||||
|
||||
- name: verify lookup_source
|
||||
iosxr_system: *lookup
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: disable lookup
|
||||
iosxr_system: &disable
|
||||
lookup_enabled: False
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'lookup' in result.xml[0]"
|
||||
|
||||
- name: verify disable lookup
|
||||
iosxr_system: *disable
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: delete lookup_source
|
||||
iosxr_system: &dellookup
|
||||
lookup_source: Loopback10
|
||||
provider: "{{ netconf }}"
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'Loopback10' in result.xml[0]"
|
||||
|
||||
- name: verify lookup_source
|
||||
iosxr_system: *dellookup
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: configure lookup_source with vrf
|
||||
iosxr_system: &lookupvrf
|
||||
lookup_source: Loopback10
|
||||
vrf: ansiblevrf
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'Loopback10' in result.xml[0]"
|
||||
- "'ansiblevrf' in result.xml[0]"
|
||||
|
||||
- name: verify lookup_source
|
||||
iosxr_system: *lookupvrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: disable lookup
|
||||
iosxr_system: &disablevrf
|
||||
lookup_enabled: False
|
||||
vrf: ansiblevrf
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'lookup' in result.xml[0]"
|
||||
- "'ansiblevrf' in result.xml[0]"
|
||||
|
||||
- name: verify disable lookup
|
||||
iosxr_system: *disablevrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: delete lookup_source
|
||||
iosxr_system: &dellookupvrf
|
||||
lookup_source: Loopback10
|
||||
vrf: ansiblevrf
|
||||
provider: "{{ netconf }}"
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- "'Loopback10' in result.xml[0]"
|
||||
- "'ansiblevrf' in result.xml[0]"
|
||||
|
||||
- name: verify lookup_source
|
||||
iosxr_system: *dellookupvrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- always:
|
||||
- name: teardown
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no domain lookup source-interface Loopback10
|
||||
- no domain vrf ansiblevrf lookup source-interface Loopback10
|
||||
- no domain lookup disable
|
||||
- no domain vrf ansiblevrf lookup disable
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- debug:
|
||||
msg: "END netconf/set_lookup_source.yaml on connection={{ ansible_connection }}"
|
||||
@@ -0,0 +1,120 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "START netconf/set_name_servers.yaml on connection={{ ansible_connection }}"
|
||||
- block:
|
||||
- name: configure name_servers
|
||||
iosxr_system:
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
- 3.3.3.3
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.xml|length == 1
|
||||
- "'1.1.1.1' in result.xml[0]"
|
||||
- "'2.2.2.2' in result.xml[0]"
|
||||
- "'3.3.3.3' in result.xml[0]"
|
||||
|
||||
- name: verify name_servers
|
||||
iosxr_system:
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
- 3.3.3.3
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: add with to vrf
|
||||
iosxr_system: &addvrf
|
||||
vrf: ansible
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
- 3.3.3.3
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.xml|length == 1
|
||||
- "'ansible' in result.xml[0]"
|
||||
- "'1.1.1.1' in result.xml[0]"
|
||||
- "'2.2.2.2' in result.xml[0]"
|
||||
- "'3.3.3.3' in result.xml[0]"
|
||||
|
||||
- name: verify change to vrf
|
||||
iosxr_system: *addvrf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
- name: remove one
|
||||
iosxr_system:
|
||||
name_servers:
|
||||
- 1.1.1.1
|
||||
- 2.2.2.2
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.xml|length == 1
|
||||
- "'3.3.3.3' in result.xml[0]"
|
||||
|
||||
## multiple name-servers deletion commands doesn't work in single
|
||||
# config session (only the 1st one takes effect). May or may not be
|
||||
# a VIRL software issue.
|
||||
- always:
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: no domain name-server 1.1.1.1
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: no domain name-server 2.2.2.2
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: no domain name-server 3.3.3.3
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: no domain vrf ansible name-server 1.1.1.1
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: no domain vrf ansible name-server 2.2.2.2
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: setup
|
||||
iosxr_config:
|
||||
lines: no domain vrf ansible name-server 3.3.3.3
|
||||
match: none
|
||||
provider: "{{ cli }}"
|
||||
ignore_errors: true
|
||||
|
||||
- debug:
|
||||
msg: "END netconf/set_name_servers.yaml on connection={{ ansible_connection }}"
|
||||
Reference in New Issue
Block a user