diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:35 +0000 |
commit | 7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch) | |
tree | efb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/cisco/iosxr/tests | |
parent | Releasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff) | |
download | ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip |
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/cisco/iosxr/tests')
138 files changed, 3088 insertions, 712 deletions
diff --git a/ansible_collections/cisco/iosxr/tests/__init__.py b/ansible_collections/cisco/iosxr/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/__init__.py diff --git a/ansible_collections/cisco/iosxr/tests/config.yml b/ansible_collections/cisco/iosxr/tests/config.yml new file mode 100644 index 000000000..41f529264 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/config.yml @@ -0,0 +1,3 @@ +--- +modules: + python_requires: ">=3.6" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/cli.yaml index 01bf509b4..588af81d2 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/cli.yaml @@ -8,13 +8,15 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli + ansible_command_timeout: 100 with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml index b86f3d843..6b08c8d17 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml @@ -1,27 +1,45 @@ --- -- name: Remove/default resources +- name: Remove/Default Resources vars: lines: - "default interface GigabitEthernet0/0/0/0\ndefault interface GigabitEthernet0/0/0/1\nno ipv4 access-list acl_1\nno ipv4 access-list acl_2\nno ipv6 access-list\ + "default interface GigabitEthernet0/0/0/0\ndefault interface GigabitEthernet0/0/0/1\n\ + no ipv4 access-list acl_1\nno ipv4 access-list acl_2\nno ipv6 access-list\ \ acl6_1\nno ipv6 access-list acl6_2\nno ipv6 access-list acl6_3\n" ansible.netcommon.cli_config: config: "{{ lines }}" -- name: Initialize interfaces - loop: - - interface GigabitEthernet0/0/0/0 - - interface GigabitEthernet0/0/0/1 - cisco.iosxr.iosxr_config: - lines: shutdown - parents: "{{ item }}" +- name: Delete all acls from the device + cisco.iosxr.iosxr_acls: + state: deleted - name: Remove unwanted interfaces from configuration loop: + - 0/0/0/0 + - 0/0/0/1 - 0/0/0/2 - - 0/0/0/3 + - 0/0/0/4.1 - 0/0/0/4 - - 0/0/0/5 + - 0/0/0/8 + - 0/0/0/9 ignore_errors: true cisco.iosxr.iosxr_config: lines: - no interface GigabitEthernet{{ item }} + +- name: Remove unwanted interfaces from configuration + loop: + - 777 + - 888 + - 999 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface loopback{{ item }} + +- name: Initialize interfaces + loop: + - interface GigabitEthernet0/0/0/0 + - interface GigabitEthernet0/0/0/1 + cisco.iosxr.iosxr_config: + lines: shutdown + parents: "{{ item }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml index 59a889b45..507142664 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml index 8ff2ae685..a868698e9 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test cases (connection=ansible.netcommon.netconf) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml index 6a15c6b6e..258640c0d 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml @@ -1,8 +1,4 @@ --- -- name: Pause for 1 min - ansible.builtin.pause: - minutes: 1 - - name: Setup - remove login cisco.iosxr.iosxr_banner: banner: login diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml index 3117ad794..7b8f5b479 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml @@ -1,8 +1,4 @@ --- -- name: Pause for 1 min - ansible.builtin.pause: - minutes: 1 - - name: Setup - remove MOTD cisco.iosxr.iosxr_banner: banner: motd diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml index ce30de3f8..d785870f9 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml @@ -1,8 +1,4 @@ --- -- name: Pause for 1 min - ansible.builtin.pause: - minutes: 1 - - name: Setup cisco.iosxr.iosxr_banner: banner: login diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml index f1262c45a..3a3b647a3 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml @@ -1,8 +1,4 @@ --- -- name: Sleep for 30 seconds and continue with play - ansible.builtin.wait_for: - timeout: 30 - - name: Setup - remove login cisco.iosxr.iosxr_banner: banner: login diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml index 6fe84deaf..02dc5b972 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml @@ -1,8 +1,4 @@ --- -- name: Sleep for 30 seconds and continue with play - ansible.builtin.wait_for: - timeout: 30 - - name: Setup - remove MOTD cisco.iosxr.iosxr_banner: banner: motd diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml index 9c2d06ed6..9379c1cf1 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml @@ -1,8 +1,4 @@ --- -- name: Sleep for 30 seconds and continue with play - ansible.builtin.wait_for: - timeout: 30 - - name: Setup cisco.iosxr.iosxr_banner: banner: login diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/defaults/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/defaults/main.yaml deleted file mode 100644 index 9ef5ba516..000000000 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/meta/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/meta/main.yaml deleted file mode 100644 index be631e5d8..000000000 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_iosxr_tests diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tests/cli/basic.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tests/cli/basic.yaml deleted file mode 100644 index 608a4400e..000000000 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tests/cli/basic.yaml +++ /dev/null @@ -1,239 +0,0 @@ ---- -- ansible.builtin.debug: msg="START iosxr cli/iosxr_bgp.yaml on connection={{ ansible_connection }}" - -- name: Check ios-xr version - register: facts - cisco.iosxr.iosxr_facts: - gather_subset: default - -- block: - - name: Clear existing BGP configuration - ignore_errors: true - cisco.iosxr.iosxr_bgp: - operation: delete - - - name: Configure BGP with as 64496 and a router-id - register: result - cisco.iosxr.iosxr_bgp: &id001 - operation: merge - config: - bgp_as: 64496 - router_id: 192.0.2.2 - - - ansible.builtin.assert: - that: - - result.changed == true - - "'router bgp 64496' in result.commands" - - "'bgp router-id 192.0.2.2' in result.commands" - - - name: Configure BGP with as 64496 and a router-id (idempotent) - register: result - cisco.iosxr.iosxr_bgp: *id001 - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Configure BGP neighbors - register: result - cisco.iosxr.iosxr_bgp: &id002 - operation: merge - config: - bgp_as: 64496 - neighbors: - - neighbor: 192.0.2.10 - remote_as: 64496 - description: IBGP_NBR_1 - advertisement_interval: 120 - timers: - keepalive: 300 - holdtime: 360 - - - neighbor: 192.0.2.15 - remote_as: 64496 - description: IBGP_NBR_2 - tcp_mss: 1500 - - - ansible.builtin.assert: - that: - - result.changed == true - - "'router bgp 64496' in result.commands" - - "'neighbor 192.0.2.10' in result.commands" - - "'remote-as 64496' in result.commands" - - "'description IBGP_NBR_1' in result.commands" - - "'timers 300 360' in result.commands" - - "'advertisement-interval 120' in result.commands" - - "'neighbor 192.0.2.15' in result.commands" - - "'remote-as 64496' in result.commands" - - "'description IBGP_NBR_2' in result.commands" - - "'tcp mss 1500' in result.commands" - - - name: Configure BGP neighbors (idempotent) - register: result - cisco.iosxr.iosxr_bgp: *id002 - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Configure BGP neighbors with operation replace - register: result - cisco.iosxr.iosxr_bgp: &id003 - operation: replace - config: - bgp_as: 64496 - neighbors: - - neighbor: 192.0.2.15 - remote_as: 64496 - description: IBGP_NBR_2 - tcp_mss: 1500 - - - neighbor: 203.0.113.10 - remote_as: 64511 - description: EBGP_NBR_1 - - - ansible.builtin.assert: - that: - - result.changed == true - - "'neighbor 203.0.113.10' in result.commands" - - "'remote-as 64511' in result.commands" - - "'description EBGP_NBR_1' in result.commands" - - "'no neighbor 192.0.2.10' in result.commands" - - - name: Configure BGP neighbors with operation replace (idempotent) - register: result - cisco.iosxr.iosxr_bgp: *id003 - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Create route-policy as prerequisite for BGP configuration - register: result - cisco.iosxr.iosxr_config: - lines: - - no route-policy RMAP_1 - - route-policy RMAP_1 - - exit - - - name: Configure networks under address family - register: result - cisco.iosxr.iosxr_bgp: &id004 - operation: merge - config: - bgp_as: 64496 - address_family: - - afi: ipv4 - networks: - - prefix: 198.51.100.48 - masklen: 28 - route_map: RMAP_1 - - - prefix: 192.0.2.64 - masklen: 27 - - - prefix: 203.0.113.160 - masklen: 27 - - - afi: ipv4 - safi: multicast - networks: - - prefix: 198.51.100.64 - masklen: 28 - - - ansible.builtin.assert: - that: - - result.changed == true - - "'router bgp 64496' in result.commands" - - "'address-family ipv4 unicast' in result.commands" - - "'network 198.51.100.48/28 route-policy RMAP_1' in result.commands" - - "'network 192.0.2.64/27' in result.commands" - - "'network 203.0.113.160/27' in result.commands" - - "'address-family ipv4 multicast' in result.commands" - - "'network 198.51.100.64/28' in result.commands" - - - name: Configure networks under address family (idempotent) - register: result - cisco.iosxr.iosxr_bgp: *id004 - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Configure networks under address family with operation replace - register: result - cisco.iosxr.iosxr_bgp: &id005 - operation: replace - config: - bgp_as: 64496 - address_family: - - afi: ipv4 - safi: unicast - networks: - - prefix: 198.51.100.80 - masklen: 28 - - - prefix: 192.0.2.64 - masklen: 27 - - - prefix: 203.0.113.192 - masklen: 27 - - - afi: ipv4 - safi: multicast - networks: - - prefix: 198.51.100.64 - masklen: 28 - - - ansible.builtin.assert: - that: - - result.changed == true - - '"router bgp 64496" in result.commands' - - '"address-family ipv4 unicast" in result.commands' - - '"network 198.51.100.80/28" in result.commands' - - '"network 203.0.113.192/27" in result.commands' - - '"no network 198.51.100.48/28" in result.commands' - - '"no network 203.0.113.160/27" in result.commands' - - - name: Configure networks under address family with operation replace (idempotent) - register: result - cisco.iosxr.iosxr_bgp: *id005 - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Override all the existing BGP configuration - register: result - cisco.iosxr.iosxr_bgp: - operation: override - config: - bgp_as: 64497 - router_id: 192.0.2.10 - log_neighbor_changes: true - - - ansible.builtin.assert: - that: - - result.changed == true - - "'router bgp 64497' in result.commands" - - "'bgp router-id 192.0.2.10' in result.commands" - - "'bgp log neighbor changes detail' in result.commands" - - - name: Teardown - register: result - cisco.iosxr.iosxr_bgp: &id006 - operation: delete - - - ansible.builtin.assert: - that: - - result.changed == true - - "'no router bgp 64497' in result.commands" - - - name: Teardown again (idempotent) - register: result - cisco.iosxr.iosxr_bgp: *id006 - - ansible.builtin.assert: - that: - - result.changed == false - - - name: Delete route-policy configures as prerequisite for BGP configuration (teardown) - cisco.iosxr.iosxr_config: - lines: no route-policy RMAP_1 - when: facts['ansible_facts']['ansible_net_version'].split('[')[0] == '6.1.3' - -- ansible.builtin.debug: msg="END iosxr cli/iosxr_bgp.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_address_family/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_address_family/tasks/cli.yaml index a1b57ab45..86ca0d9cb 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_address_family/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_address_family/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tasks/cli.yaml index 1b019a5ab..39471d59f 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) vars: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/_populate_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/_populate_config.yaml index c164070b8..eb9c2a173 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/_populate_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/_populate_config.yaml @@ -10,6 +10,8 @@ - "default-metric 4" - "socket receive-buffer-size 514" - "socket send-buffer-size 4098" + - "neighbor-group test_ng" + - "session-group test_sg" - "neighbor 192.0.2.11" - "cluster-id 3" - "remote-as 65537" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/replaced.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/replaced.yaml index b4f981808..0ab60252e 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/replaced.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/tests/common/replaced.yaml @@ -24,6 +24,16 @@ neighbors: - neighbor: 192.0.2.13 remote_as: 65538 + use: + neighbor_group: test_ng + session_group: test_sg + password: + inheritance_disable: true + local_as: + value: 65539 + no_prepend: + replace_as: + set: true bfd: fast_detect: set: true diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/vars/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/vars/main.yaml index ef656a41b..274e28948 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/vars/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_global/vars/main.yaml @@ -59,6 +59,10 @@ replaced: - bfd minimum-interval 20 - bfd multiplier 6 - remote-as 65538 + - use neighbor-group test_ng + - use session-group test_sg + - local-as 65539 no-prepend replace-as + - password inheritance-disable after: as_number: "65536" default_metric: 5 @@ -74,11 +78,22 @@ replaced: neighbors: - neighbor_address: "192.0.2.13" remote_as: 65538 + use: + neighbor_group: test_ng + session_group: test_sg + password: + inheritance_disable: true + local_as: + value: 65539 + no_prepend: + replace_as: + set: true bfd: fast_detect: set: true multiplier: 6 minimum_interval: 20 + rendered: commands: - router bgp 65536 diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_neighbor_address_family/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_neighbor_address_family/tasks/cli.yaml index 1b019a5ab..39471d59f 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_neighbor_address_family/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_neighbor_address_family/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) vars: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/defaults/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/defaults/main.yaml new file mode 100644 index 000000000..871ea460c --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "[^_].*" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/meta/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/meta/main.yaml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/meta/main.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tasks/cli.yaml index 29e7f60cd..39471d59f 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tasks/cli.yaml @@ -1,19 +1,22 @@ --- - name: Collect all CLI test cases ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" + paths: "{{ role_path }}/tests/common" patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli + ansible.builtin.include_tasks: "{{ test_case_to_run }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + tags: + - network_cli diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tasks/main.yaml index 4b7d599c6..f75f2f031 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tasks/main.yaml @@ -2,4 +2,4 @@ - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - - network_cli + - cli diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_parsed.cfg b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_parsed.cfg new file mode 100644 index 000000000..2523fdf31 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_parsed.cfg @@ -0,0 +1,33 @@ +router bgp 65536 + neighbor-group neighbor-group1 + bfd fast-detect strict-mode + precedence critical + advertisement-interval 10 + internal-vpn-client + address-family ipv4 unicast + advertise local-labeled-route + ! + ! + neighbor-group neighbor-group2 + ebgp-multihop 255 + egress-engineering + precedence flash + graceful-maintenance + as-prepends 0 + ! + tcp mss inheritance-disable + local-as 6 + cluster-id 1 + dmz-link-bandwidth + description neighbor-group2 + ttl-security + local address inheritance-disable + update-source Loopback919 + idle-watch-time 30 + ignore-connected-check + session-open-mode both + send-buffer-size 4096 + receive-buffer-size 512 + internal-vpn-client + ! +! diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_populate_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_populate_config.yaml new file mode 100644 index 000000000..82013c204 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_populate_config.yaml @@ -0,0 +1,34 @@ +--- +- name: "Setup" + cisco.iosxr.iosxr_config: + lines: + - "neighbor-group neighbor-group1" + - " advertisement-interval 10" + - " bfd fast-detect strict-mode" + - " internal-vpn-client" + - " precedence critical" + - " address-family ipv4 unicast" + - " advertise local-labeled-route" + - "neighbor-group neighbor-group2" + - " dmz-link-bandwidth" + - " description neighbor-group2" + - " cluster-id 1" + - " ebgp-multihop 255" + - " egress-engineering" + - " internal-vpn-client" + - " ignore-connected-check" + - " local-as 6" + - " local address inheritance-disable" + - " precedence flash" + - " receive-buffer-size 512" + - " send-buffer-size 4096" + - " session-open-mode both" + - " tcp mss inheritance-disable" + - " update-source Loopback919" + - " ttl-security" + - " graceful-maintenance" + - " graceful-maintenance as-prepends 0" + parents: "router bgp 65536" + + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_remove_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_remove_config.yaml new file mode 100644 index 000000000..812cd1bd4 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove pre-existing BGP configurations + cisco.iosxr.iosxr_config: + lines: + - no router bgp 65536 + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/deleted.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/deleted.yaml new file mode 100644 index 000000000..0a600d8d9 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/deleted.yaml @@ -0,0 +1,33 @@ +--- +- ansible.builtin.debug: + msg: Start iosxr_bgp_templates deleted integration tests connection={{ ansible_connection}} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Delete given bgp_nbr_address_family configuration + become: true + register: result + cisco.iosxr.iosxr_bgp_templates: &deleted + config: + state: deleted + + - ansible.builtin.assert: + that: + - result.commands|length == 3 + - result.changed == true + - "'no router bgp 65536' not in result.commands" + - result.after == deleted.after + + - name: Idempotency check + become: true + register: result + cisco.iosxr.iosxr_bgp_templates: *deleted + - ansible.builtin.assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/empty_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/empty_config.yaml new file mode 100644 index 000000000..4af884189 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/empty_config.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: START iosxr_bgp_templates empty_config integration tests on connection={{ ansible_connection }} + +- name: Merged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_bgp_templates: + config: + state: merged + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_bgp_templates: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Rendered with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_bgp_templates: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- name: Parsed with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_bgp_templates: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- ansible.builtin.debug: + msg: END iosxr_bgp_templates empty_config integration tests on connection={{ ansible_connection }} diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/gathered.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/gathered.yaml new file mode 100644 index 000000000..2199c1446 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/gathered.yaml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: START iosxr_bgp_templates gathered integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Gathered the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_bgp_templates: + config: + state: gathered + + - name: Assert + ansible.builtin.assert: + that: + - "{{ merged['after']['neighbor'] | symmetric_difference(result['gathered']['neighbor']) |length == 0 }}" + - merged['after']['as_number'] == result['gathered']['as_number'] + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/merged.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/merged.yaml new file mode 100644 index 000000000..6a31c1095 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/merged.yaml @@ -0,0 +1,79 @@ +--- +- ansible.builtin.debug: + msg: Start iosxr_bgp_templates merged integration tests connection={{ ansible_connection}} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the existing running configuration + cisco.iosxr.iosxr_bgp_templates: &id001 + config: + as_number: 65536 + neighbor: + - address_family: + - advertise: + local_labeled_route: + set: true + afi: ipv4 + safi: unicast + advertisement_interval: 10 + bfd: + fast_detect: + strict_mode: true + internal_vpn_client: true + name: neighbor-group1 + precedence: critical + - cluster_id: "1" + description: neighbor-group2 + dmz_link_bandwidth: + set: true + ebgp_multihop: + value: 255 + egress_engineering: + set: true + graceful_maintenance: + as_prepends: + value: 0 + set: true + ignore_connected_check: + set: true + internal_vpn_client: true + local: + address: + inheritance_disable: true + local_as: + value: 6 + name: neighbor-group2 + precedence: flash + receive_buffer_size: 512 + send_buffer_size: 4096 + session_open_mode: both + tcp: + mss: + inheritance_disable: true + ttl_security: + set: true + update_source: Loopback919 + register: result + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that after dicts were correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['after'] + + - name: Merge the provided configuration with the existing running configuration (idempotent) + cisco.iosxr.iosxr_bgp_templates: *id001 + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/overridden.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/overridden.yaml new file mode 100644 index 000000000..640bcc124 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/overridden.yaml @@ -0,0 +1,44 @@ +--- +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Override given bgp_address_family configuration + become: true + register: result + cisco.iosxr.iosxr_bgp_templates: &overridden + config: + as_number: 65536 + neighbor: + - address_family: + - advertise: + local_labeled_route: + disable: true + afi: ipv4 + safi: unicast + advertisement_interval: 12 + bfd: + fast_detect: + strict_mode: true + name: neighbor-group1 + precedence: flash + state: overridden + + - ansible.builtin.assert: + that: + - result.commands|length == 9 + - result.changed == true + - "'no router bgp 65536' not in result.commands" + - overridden['commands'] == result['commands'] + + - name: Idempotency check + become: true + register: result + cisco.iosxr.iosxr_bgp_templates: *overridden + - ansible.builtin.assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/parsed.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/parsed.yaml new file mode 100644 index 000000000..58e34c939 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/parsed.yaml @@ -0,0 +1,14 @@ +--- +- ansible.builtin.debug: + msg: START iosxr_bgp_templates parsed integration tests on connection={{ ansible_connection }} + +- name: Parse externally provided BGP configuration + register: result + cisco.iosxr.iosxr_bgp_templates: + running_config: "{{ lookup('file', './_parsed.cfg') }}" + state: parsed + +- name: Assert that configuration was correctly parsed + ansible.builtin.assert: + that: + - "{{ parsed == result['parsed']}}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/rendered.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/rendered.yaml new file mode 100644 index 000000000..6843a14e2 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/rendered.yaml @@ -0,0 +1,62 @@ +--- +- ansible.builtin.debug: + msg: START iosxr_bgp_template rendered integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- name: Render platform specific configuration lines with state rendered (without connecting to the device) + cisco.iosxr.iosxr_bgp_templates: + config: + as_number: 65536 + neighbor: + - address_family: + - advertise: + local_labeled_route: + set: true + afi: ipv4 + safi: unicast + advertisement_interval: 10 + bfd: + fast_detect: + strict_mode: true + internal_vpn_client: true + name: neighbor-group1 + precedence: critical + - cluster_id: "1" + description: neighbor-group2 + dmz_link_bandwidth: + set: true + ebgp_multihop: + value: 255 + egress_engineering: + set: true + graceful_maintenance: + as_prepends: + value: 0 + set: true + ignore_connected_check: + set: true + internal_vpn_client: true + local: + address: + inheritance_disable: true + local_as: + value: 6 + name: neighbor-group2 + precedence: flash + receive_buffer_size: 512 + send_buffer_size: 4096 + session_open_mode: both + tcp: + mss: + inheritance_disable: true + ttl_security: + set: true + update_source: Loopback919 + state: rendered + register: result + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - merged['commands'] == result['rendered'] diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/replaced.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/replaced.yaml new file mode 100644 index 000000000..dde597889 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/tests/common/replaced.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Replaced given bgp_templates configuration + become: true + register: result + cisco.iosxr.iosxr_bgp_templates: &replaced + config: + as_number: 65536 + neighbor: + - address_family: + - advertise: + local_labeled_route: + set: true + afi: ipv4 + safi: unicast + advertisement_interval: 12 + name: neighbor-group1 + precedence: flash + - cluster_id: "2" + description: replace neighbor-group2 + ebgp_multihop: + value: 254 + graceful_maintenance: + as_prepends: + value: 2 + set: true + update_source: Loopback917 + name: neighbor-group2 + state: replaced + + - ansible.builtin.assert: + that: + - result.changed == true + - "'no router bgp 65536' not in result.commands" + - replaced['commands'] == result['commands'] + + - name: Idempotency check + become: true + register: result + cisco.iosxr.iosxr_bgp_templates: *replaced + - ansible.builtin.assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/vars/main.yml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/vars/main.yml new file mode 100644 index 000000000..266f172fd --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp_templates/vars/main.yml @@ -0,0 +1,170 @@ +--- +merged: + commands: + - router bgp 65536 + - neighbor-group neighbor-group1 + - advertisement-interval 10 + - bfd fast-detect strict-mode + - internal-vpn-client + - precedence critical + - address-family ipv4 unicast + - advertise local-labeled-route + - neighbor-group neighbor-group2 + - dmz-link-bandwidth + - description neighbor-group2 + - cluster-id 1 + - ebgp-multihop 255 + - egress-engineering + - internal-vpn-client + - ignore-connected-check + - local-as 6 + - local address inheritance-disable + - precedence flash + - receive-buffer-size 512 + - send-buffer-size 4096 + - session-open-mode both + - tcp mss inheritance-disable + - update-source Loopback919 + - ttl-security + - graceful-maintenance + - graceful-maintenance as-prepends 0 + + after: + as_number: "65536" + neighbor: + - address_family: + - advertise: + local_labeled_route: + set: true + afi: ipv4 + safi: unicast + advertisement_interval: 10 + bfd: + fast_detect: + strict_mode: true + internal_vpn_client: true + name: neighbor-group1 + precedence: critical + - cluster_id: "1" + description: neighbor-group2 + dmz_link_bandwidth: + set: true + ebgp_multihop: + value: 255 + egress_engineering: + set: true + graceful_maintenance: + as_prepends: + value: 0 + set: true + ignore_connected_check: + set: true + internal_vpn_client: true + local: + address: + inheritance_disable: true + local_as: + value: 6 + name: neighbor-group2 + precedence: flash + receive_buffer_size: 512 + send_buffer_size: 4096 + session_open_mode: both + tcp: + mss: + inheritance_disable: true + ttl_security: + set: true + update_source: Loopback919 + +deleted: + after: + as_number: "65536" + +overridden: + commands: + - router bgp 65536 + - no neighbor-group neighbor-group2 + - neighbor-group neighbor-group1 + - no internal-vpn-client + - advertisement-interval 12 + - precedence flash + - address-family ipv4 unicast + - no advertise local-labeled-route + - advertise local-labeled-route disable + +replaced: + commands: + - router bgp 65536 + - neighbor-group neighbor-group1 + - no bfd fast-detect strict-mode + - no internal-vpn-client + - advertisement-interval 12 + - precedence flash + - neighbor-group neighbor-group2 + - no dmz-link-bandwidth + - no egress-engineering + - no internal-vpn-client + - no ignore-connected-check + - no local-as 6 + - no local address inheritance-disable + - no precedence flash + - no receive-buffer-size 512 + - no send-buffer-size 4096 + - no session-open-mode both + - no tcp mss inheritance-disable + - no ttl-security + - description replace neighbor-group2 + - cluster-id 2 + - ebgp-multihop 254 + - update-source Loopback917 + - graceful-maintenance as-prepends 2 + +parsed: + as_number: "65536" + neighbor: + - address_family: + - advertise: + local_labeled_route: + set: true + afi: ipv4 + safi: unicast + advertisement_interval: 10 + bfd: + fast_detect: + strict_mode: true + internal_vpn_client: true + name: neighbor-group1 + precedence: critical + - cluster_id: "1" + description: neighbor-group2 + dmz_link_bandwidth: + set: true + ebgp_multihop: + value: 255 + egress_engineering: + set: true + graceful_maintenance: + as_prepends: + value: 0 + set: true + idle_watch_time: 30 + ignore_connected_check: + set: true + internal_vpn_client: true + local: + address: + inheritance_disable: true + local_as: + value: 6 + name: neighbor-group2 + precedence: flash + receive_buffer_size: 512 + send_buffer_size: 4096 + session_open_mode: both + tcp: + mss: + inheritance_disable: true + ttl_security: + set: true + update_source: Loopback919 diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tasks/cli.yaml index a1b57ab45..86ca0d9cb 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tests/common/commit_conf.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tests/common/commit_conf.yaml index 05ddfd8e1..cedbb5075 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tests/common/commit_conf.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_cliconf/tests/common/commit_conf.yaml @@ -2,32 +2,45 @@ - ansible.builtin.debug: msg: START iosxr_cliconf integration tests on connection={{ ansible_connection }} -- name: Apply interface description - register: result - cisco.iosxr.iosxr_interfaces: - state: merged - config: - - name: GigabitEthernet0/0/0/2 - description: TestCommitConfirmed +- block: + - name: Remove interfaces from configuration before actual testing + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface loopback 777 -- name: Do commit confirmed - cisco.iosxr.iosxr_command: - commands: - - commit confirmed - when: result["changed"] == true + - name: Apply interface description + register: result + cisco.iosxr.iosxr_interfaces: + state: merged + config: + - name: loopback 777 + description: TestCommitConfirmed -- name: Sleep for 35 sec. - ansible.builtin.wait_for: - timeout: 35 - when: result["changed"] == true + - name: Do commit confirmed + cisco.iosxr.iosxr_command: + commands: + - commit confirmed + when: result["changed"] == true -- name: Get interface description - register: get_desc - iosxr_command: - commands: - - "show interfaces GigabitEthernet 0/0/0/2 | include Description" - ignore_errors: true + - name: Sleep for 35 sec. + ansible.builtin.wait_for: + timeout: 35 + when: result["changed"] == true -- ansible.builtin.assert: - that: - - "'TestCommitConfirmed' in get_desc.stdout[0]" + - name: Get interface description + register: get_desc + iosxr_command: + commands: + - show running-config interface loopback 777 description + ignore_errors: true + + - ansible.builtin.assert: + that: + - "'TestCommitConfirmed' in get_desc.stdout[0]" + always: + - name: Remove interfaces from configuration before actual testing + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface loopback 777 diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/cli.yaml index fd2202fa2..e88cb28a3 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml index 59a889b45..507142664 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml index 0b6332e96..2115b4b15 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/redirection.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/redirection.yaml index bc4b47e20..cbfe809e5 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/redirection.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/redirection.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items for redirection - ansible.builtin.set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/interface_config.j2 b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/interface_config.j2 new file mode 100644 index 000000000..a4659a5d0 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/interface_config.j2 @@ -0,0 +1,5 @@ +interface GigabitEthernet 0/0/0/5 +description this is interface0 +mtu 65 +speed 10 +no shutdown diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_block.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_block.yaml new file mode 100644 index 000000000..b5dce6496 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_block.yaml @@ -0,0 +1,33 @@ +--- +- name: Setup + cisco.iosxr.iosxr_config: + commands: + - no interface GigabitEthernet 0/0/0/5 + ignore_errors: true + +- name: "Populate interface configuration with replace block and lines options" + register: result1 + cisco.iosxr.iosxr_config: + lines: "{{ lookup('template', 'basic/interface_config.j2') }}" + replace: block + +- ansible.builtin.assert: + that: + - result1.changed == true + +- name: Setup + cisco.iosxr.iosxr_config: + commands: + - no interface GigabitEthernet 0/0/0/5 + ignore_errors: true + +- name: "Populate interface configuration with replace block and src options" + register: result2 + iosxr_config: + src: basic/interface_config.j2 + replace: block + +- ansible.builtin.assert: + that: + - result2.changed == true + - result1.commands == result2.commands diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yml index 6cd72dbad..6cd72dbad 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/cli.yaml index 59a889b45..507142664 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml index 065f07bf5..1a90c3332 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml @@ -11,12 +11,11 @@ - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'config' not in result.ansible_facts.ansible_net_gather_subset" - result.ansible_facts.ansible_net_hostname is defined - - result.ansible_facts.ansible_net_image is defined - result.ansible_facts.ansible_net_model is defined - result.ansible_facts.ansible_net_python_version is defined - - result.ansible_facts.ansible_net_serialnum is defined - result.ansible_facts.ansible_net_system is defined - result.ansible_facts.ansible_net_version is defined + - result.ansible_facts.ansible_net_serialnum is defined - result.ansible_facts.ansible_network_resources == {} - ansible.builtin.debug: msg="END cli/default.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_hostname/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_hostname/tasks/cli.yaml index a1b57ab45..86ca0d9cb 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_hostname/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_hostname/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml index 1512a4b31..83b07d6ea 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml @@ -11,6 +11,7 @@ - GigabitEthernet 0/0/0/1 - GigabitEthernet 0/0/0/2 - GigabitEthernet 0/0/0/3 + - loopback 777 ignore_errors: true cisco.iosxr.iosxr_config: lines: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml index c4bb4fdae..fb4cbffa1 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml @@ -5,6 +5,8 @@ merged: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: this is interface0 enabled: true mtu: 65 @@ -31,6 +33,8 @@ merged: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: Configured and Merged by Ansible-Network duplex: half enabled: true @@ -49,6 +53,8 @@ merged: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 commands: - interface GigabitEthernet0/0/0/2 - description Configured and Merged by Ansible-Network @@ -66,6 +72,8 @@ merged: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: Configured and Merged by Ansible-Network duplex: half enabled: true @@ -83,6 +91,8 @@ parsed: - description: test for ansible enabled: false name: Loopback888 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: Configured and Merged by Ansible-Network duplex: half enabled: true @@ -98,6 +108,8 @@ replaced: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: this is interface0 enabled: true mtu: 65 @@ -122,6 +134,8 @@ replaced: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: Configured and Replaced by Ansible-Network enabled: true mtu: 110 @@ -149,6 +163,8 @@ overridden: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: this is interface0 enabled: true mtu: 65 @@ -175,6 +191,8 @@ overridden: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: Configured and Overridden by Ansible-Network duplex: full enabled: false @@ -187,6 +205,8 @@ gathered: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: This interface is Configured and Merged by Ansible-Network duplex: half enabled: true @@ -205,6 +225,8 @@ deleted: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 - description: this is interface0 enabled: true mtu: 65 @@ -229,3 +251,5 @@ deleted: name: Loopback888 - enabled: true name: Loopback999 + - enabled: true + name: MgmtEth0/RP0/CPU0/0 diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml index 5b96e4a77..d8205e5ac 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml @@ -1,8 +1,14 @@ --- -- name: Remove configuration - vars: +- name: Remove interfaces from configuration before actual testing + loop: + - GigabitEthernet 0/0/0/0 + - GigabitEthernet 0/0/0/1 + - GigabitEthernet 0/0/0/2 + - GigabitEthernet 0/0/0/3 + - GigabitEthernet 0/0/0/3.900 + - GigabitEthernet 0/0/0/4 + - GigabitEthernet0/0/0/4.1 + ignore_errors: true + cisco.iosxr.iosxr_config: lines: - "interface GigabitEthernet 0/0/0/1\nno l2transport\nno interface GigabitEthernet 0/0/0/2\nno interface GigabitEthernet 0/0/0/3\nno interface GigabitEthernet\ - \ 0/0/0/3.900\nno interface GigabitEthernet 0/0/0/4\n" - ansible.netcommon.cli_config: - config: "{{ lines }}" + - no interface {{ item }} diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml index 3d8b1c7fb..d3a560600 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml @@ -12,6 +12,10 @@ cisco.iosxr.iosxr_l2_interfaces: &id001 state: deleted + - name: Sleep for 5 seconds and continue with play + ansible.builtin.wait_for: + timeout: 5 + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml index 8f3471618..baafd1896 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml @@ -21,6 +21,10 @@ second_dot1q: 40 state: overridden + - name: Sleep for 5 seconds and continue with play + ansible.builtin.wait_for: + timeout: 5 + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml index 82c06b185..3b8ed9aae 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml @@ -11,4 +11,4 @@ - name: Assert that configuration was correctly parsed ansible.builtin.assert: that: - - "{{ merged['after'] | symmetric_difference(result['parsed']) |length == 0 }}" + - "{{ parsed | symmetric_difference(result['parsed']) |length == 0 }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml index 54c7ef626..e8d60bbe9 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml @@ -1,6 +1,21 @@ --- +parsed: + - name: Loopback888 + - name: MgmtEth0/RP0/CPU0/0 + - l2protocol: + - cpsv: tunnel + l2transport: true + name: GigabitEthernet0/0/0/1 + propagate: true + - name: GigabitEthernet0/0/0/3.900 + encapsulation: + dot1q: 20 + second_dot1q: 40 merged: - before: [] + before: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 commands: - interface GigabitEthernet0/0/0/1 - l2transport l2protocol cpsv tunnel @@ -8,6 +23,9 @@ merged: - interface GigabitEthernet0/0/0/3.900 - encapsulation dot1q 20 second-dot1q 40 after: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - l2protocol: - cpsv: tunnel l2transport: true @@ -20,6 +38,9 @@ merged: replaced: before: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - l2protocol: - cpsv: tunnel l2transport: true @@ -38,6 +59,9 @@ replaced: - no l2transport - l2transport l2protocol cpsv drop after: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - l2protocol: - cpsv: drop l2transport: true @@ -53,6 +77,9 @@ replaced: overridden: before: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - l2protocol: - cpsv: tunnel l2transport: true @@ -72,6 +99,9 @@ overridden: - interface GigabitEthernet0/0/0/3.900 - encapsulation dot1q 20 second-dot1q 40 after: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - name: GigabitEthernet0/0/0/3.900 encapsulation: dot1q: 20 @@ -82,6 +112,9 @@ overridden: name: GigabitEthernet0/0/0/4 deleted: before: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - l2protocol: - cpsv: tunnel l2transport: true @@ -103,5 +136,7 @@ deleted: - interface GigabitEthernet0/0/0/4 - no l2transport after: + - name: Loopback888 + - name: Loopback999 + - name: MgmtEth0/RP0/CPU0/0 - name: GigabitEthernet0/0/0/3.900 - - name: GigabitEthernet0/0/0/4 diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml index 3813ccce6..265242981 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml @@ -1,6 +1,9 @@ --- -- name: Remove configuration - vars: - lines: "interface GigabitEthernet 0/0/0/0\nno ipv4 address\nno ipv6 address\ninterface GigabitEthernet 0/0/0/1\nno ipv4 address\nno ipv6 address\n" - ansible.netcommon.cli_config: - config: "{{ lines }}" +- name: Remove interfaces from configuration before actual testing + loop: + - GigabitEthernet 0/0/0/0 + - GigabitEthernet 0/0/0/1 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface {{ item }} diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml index b8562c85e..ab89448e7 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml @@ -4,6 +4,11 @@ - ansible.builtin.include_tasks: _remove_config.yaml +- name: Gather management_interface facts using gathered state + register: management_interface + cisco.iosxr.iosxr_l3_interfaces: + state: gathered + - ansible.builtin.include_tasks: _populate_config.yaml - block: @@ -16,6 +21,18 @@ - name: GigabitEthernet0/0/0/1 state: deleted + - name: Sleep for 5 seconds and continue with play + ansible.builtin.wait_for: + timeout: 5 + + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_before: "{{ deleted['before'] | ansible.builtin.union(management_interface['gathered']) }}" + + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_after: "{{ deleted['after'] | ansible.builtin.union(management_interface['gathered']) }}" + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: @@ -24,12 +41,12 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ deleted['before'] | symmetric_difference(result['before']) | length == 0 }}" + - "{{ combined_before | symmetric_difference(result['before']) | length == 0 }}" - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - "{{ deleted['after'] | symmetric_difference(result['after']) | length == 0 }}" + - "{{ combined_after | symmetric_difference(result['after']) | length == 0 }}" - name: Delete attributes of all configured interfaces (idempotent) register: result diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml index abd09c021..59620f209 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml @@ -5,6 +5,11 @@ - ansible.builtin.include_tasks: _remove_config.yaml - block: + - name: Gather management_interface facts using gathered state + register: management_interface + cisco.iosxr.iosxr_l3_interfaces: + state: gathered + - name: Gather the provided configuration with the existing running configuration register: result cisco.iosxr.iosxr_l3_interfaces: @@ -23,6 +28,10 @@ secondary: true state: merged + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_after: "{{ merged['after'] | ansible.builtin.union(management_interface['gathered']) }}" + - name: Gather layer 3 interfaces facts using gathered state register: result cisco.iosxr.iosxr_l3_interfaces: @@ -30,6 +39,6 @@ - name: Assert that facts were correctly generated ansible.builtin.assert: - that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length == 0 }}" + that: "{{ combined_after | symmetric_difference(result['gathered']) |length == 0 }}" always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml index 6660b9afc..7b32faf7c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml @@ -5,6 +5,11 @@ - ansible.builtin.include_tasks: _remove_config.yaml - block: + - name: Gather management_interface facts using gathered state + register: management_interface + cisco.iosxr.iosxr_l3_interfaces: + state: gathered + - name: Merge provided configuration with device configuration register: result cisco.iosxr.iosxr_l3_interfaces: &id001 @@ -23,6 +28,14 @@ secondary: true state: merged + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_before: "{{ merged['before'] | ansible.builtin.union(management_interface['gathered']) }}" + + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_after: "{{ merged['after'] | ansible.builtin.union(management_interface['gathered']) }}" + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: @@ -31,12 +44,12 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ merged['before'] | symmetric_difference(result['before']) | length == 0 }}" + - "{{ combined_before | symmetric_difference(result['before']) | length == 0 }}" - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - "{{ merged['after'] | symmetric_difference(result['after']) | length == 0 }}" + - "{{ combined_after | symmetric_difference(result['after']) | length == 0 }}" - name: Merge provided configuration with device configuration (idempotent) register: result diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml index ded36a390..6ff8c649f 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml @@ -4,20 +4,32 @@ - ansible.builtin.include_tasks: _remove_config.yaml +- name: Gather management_interface facts using gathered state + register: management_interface + cisco.iosxr.iosxr_l3_interfaces: + state: gathered + - ansible.builtin.include_tasks: _populate_config.yaml - block: + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_before: "{{ overridden['before'] | ansible.builtin.union(management_interface['gathered']) }}" + + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_after: "{{ overridden['after'] | ansible.builtin.union(management_interface['gathered']) }}" + - name: Override device configuration of all interfaces with provided configuration register: result cisco.iosxr.iosxr_l3_interfaces: &id001 - config: - - name: GigabitEthernet0/0/0/1 - ipv4: - - address: 198.51.102.1/24 - ipv6: - - address: 2001:db8:1::/64 + config: "{{ combined_after }}" state: overridden + - name: Sleep for 5 seconds and continue with play + ansible.builtin.wait_for: + timeout: 5 + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: @@ -26,12 +38,12 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ overridden['before'] | symmetric_difference(result['before']) | length == 0 }}" + - "{{ combined_before | symmetric_difference(result['before']) | length == 0 }}" - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - "{{ overridden['after'] | symmetric_difference(result['after']) | length == 0 }}" + - "{{ combined_after | symmetric_difference(result['after']) | length == 0 }}" - name: Override device configuration of all interfaces with provided configuration (idempotent) register: result diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml index 10a77a3c8..ea4ef13cd 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml @@ -4,19 +4,26 @@ - ansible.builtin.include_tasks: _remove_config.yaml +- name: Gather management_interface facts using gathered state + register: management_interface + cisco.iosxr.iosxr_l3_interfaces: + state: gathered + - ansible.builtin.include_tasks: _populate_config.yaml - block: + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_before: "{{ replaced['before'] | ansible.builtin.union(management_interface['gathered']) }}" + + - name: Combine all the dictionaries based on match_keys + ansible.builtin.set_fact: + combined_after: "{{ replaced['after'] | ansible.builtin.union(management_interface['gathered']) }}" + - name: Replaces device configuration of listed interfaces with provided configuration register: result cisco.iosxr.iosxr_l3_interfaces: &id001 - config: - - name: GigabitEthernet0/0/0/0 - ipv4: - - address: 203.0.113.27/24 - - - address: 203.0.114.1/24 - secondary: true + config: "{{ combined_after }}" state: replaced - name: Assert that correct set of commands were generated @@ -27,12 +34,12 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ replaced['before'] | symmetric_difference(result['before']) | length == 0 }}" + - "{{ combined_before | symmetric_difference(result['before']) | length == 0 }}" - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - "{{ replaced['after'] | symmetric_difference(result['after']) | length == 0 }}" + - "{{ combined_after | symmetric_difference(result['after']) | length == 0 }}" - name: Replaces device configuration of listed interfaces with provided configuration (idempotent) register: result diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml index c144276d3..593dc89aa 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml @@ -14,11 +14,11 @@ merged: - name: Loopback888 - name: Loopback999 - ipv4: - - address: 198.51.100.1 255.255.255.0 + - address: 198.51.100.1/24 name: GigabitEthernet0/0/0/0 - ipv4: - - address: 192.0.2.1 255.255.255.0 - - address: 192.0.2.2 255.255.255.0 + - address: 192.0.2.1/24 + - address: 192.0.2.2/24 secondary: true ipv6: - address: 2001:db8:0:3::/64 @@ -28,13 +28,13 @@ replaced: - name: Loopback888 - name: Loopback999 - ipv4: - - address: 198.51.100.1 255.255.255.0 + - address: 198.51.100.1/24 ipv6: - address: 2001:db8::/32 name: GigabitEthernet0/0/0/0 - ipv4: - - address: 192.0.2.1 255.255.255.0 - - address: 192.0.2.2 255.255.255.0 + - address: 192.0.2.1/24 + - address: 192.0.2.2/24 secondary: true name: GigabitEthernet0/0/0/1 commands: @@ -46,13 +46,13 @@ replaced: - name: Loopback888 - name: Loopback999 - ipv4: - - address: 203.0.113.27 255.255.255.0 - - address: 203.0.114.1 255.255.255.0 + - address: 203.0.113.27/24 + - address: 203.0.114.1/24 secondary: true name: GigabitEthernet0/0/0/0 - ipv4: - - address: 192.0.2.1 255.255.255.0 - - address: 192.0.2.2 255.255.255.0 + - address: 192.0.2.1/24 + - address: 192.0.2.2/24 secondary: true name: GigabitEthernet0/0/0/1 overridden: @@ -60,13 +60,13 @@ overridden: - name: Loopback888 - name: Loopback999 - ipv4: - - address: 198.51.100.1 255.255.255.0 + - address: 198.51.100.1/24 ipv6: - address: 2001:db8::/32 name: GigabitEthernet0/0/0/0 - ipv4: - - address: 192.0.2.1 255.255.255.0 - - address: 192.0.2.2 255.255.255.0 + - address: 192.0.2.1/24 + - address: 192.0.2.2/24 secondary: true name: GigabitEthernet0/0/0/1 commands: @@ -81,7 +81,7 @@ overridden: - name: Loopback888 - name: Loopback999 - ipv4: - - address: 198.51.102.1 255.255.255.0 + - address: 198.51.102.1/24 ipv6: - address: 2001:db8:1::/64 name: GigabitEthernet0/0/0/1 @@ -96,30 +96,33 @@ rendered: parsed: after: - name: Loopback888 + - ipv4: + - address: 10.8.38.70/24 + name: MgmtEth0/RP0/CPU0/0 - ipv6: - address: 2001:db8:0:3::/64 ipv4: - - address: 192.0.2.1 255.255.255.0 - - address: 192.0.2.2 255.255.255.0 + - address: 192.0.2.1/24 + - address: 192.0.2.2/24 secondary: true name: GigabitEthernet0/0/0/0 - name: GigabitEthernet0/0/0/1 - ipv4: - - address: 192.0.22.1 255.255.255.0 - - address: 192.0.23.1 255.255.255.0 + - address: 192.0.22.1/24 + - address: 192.0.23.1/24 name: GigabitEthernet0/0/0/3 deleted: before: - name: Loopback888 - name: Loopback999 - ipv4: - - address: 198.51.100.1 255.255.255.0 + - address: 198.51.100.1/24 ipv6: - address: 2001:db8::/32 name: GigabitEthernet0/0/0/0 - ipv4: - - address: 192.0.2.1 255.255.255.0 - - address: 192.0.2.2 255.255.255.0 + - address: 192.0.2.1/24 + - address: 192.0.2.2/24 secondary: true name: GigabitEthernet0/0/0/1 commands: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml index 8ae46e432..88e4708f8 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml index e5f214d1f..26f9ab49a 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.netconf) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging_global/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging_global/tasks/cli.yaml index 1b019a5ab..39471d59f 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging_global/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging_global/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) vars: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/cli.yaml index 05e3269d9..3f630e36e 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ntp_global/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ntp_global/tasks/cli.yaml index 1b019a5ab..39471d59f 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ntp_global/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ntp_global/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) vars: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml index f2652af6d..b94b49c61 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml @@ -31,7 +31,7 @@ - name: Assert that the after dicts were correctly generated ansible.builtin.assert: that: - - "{{ deleted['after'] == result['after'] }}" + - "{{ {} == result['after'] }}" - name: Delete a single OSPF process (idempotent) register: result @@ -61,7 +61,7 @@ - name: Assert that the after dicts were correctly generated ansible.builtin.assert: that: - - "{{ deleted['after'] == result['after'] }}" + - "{{ {} == result['after'] }}" - name: Delete all OSPF processes (idempotent) register: result @@ -71,6 +71,6 @@ - name: Assert that the before dicts were correctly generated ansible.builtin.assert: that: - - "{{ deleted['after'] == result['before'] }}" + - "{{ {} == result['before'] }}" always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml index a10380985..fba6695ee 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml @@ -177,30 +177,13 @@ replaced: overridden: commands: - - router ospfv3 10 - - no area 11 default-cost 5 - - no area 11 cost 11 - - no area 22 default-cost 6 - - router ospfv3 30 - - no cost 2 - - no priority 1 - - no default-metric 10 - - no router-id 2.2.2.2 - - no demand-circuit - - no packet-size 577 - - no transmit-delay 2 - - no dead-interval 2 - - no hello-interval 1 - - no retransmit-interval 2 - - no mtu-ignore - - no area 11 default-cost 5 - - no area 22 default-cost 6 + - no router ospfv3 10 + - no router ospfv3 30 - router ospfv3 27 - area 20 default-cost 2 - area 20 cost 2 after: processes: - - process_id: "10" - authentication: disable: true process_id: "26" @@ -211,42 +194,16 @@ overridden: cost: 2 default_cost: 2 process_id: "27" - - process_id: "30" deleted: commands: - - router ospfv3 10 - - no area 11 default-cost 5 - - no area 11 cost 11 - - no area 22 default-cost 6 - - router ospfv3 26 - - no authentication disable - - router ospfv3 27 - - no area 10 hello-interval 2 - - router ospfv3 30 - - no cost 2 - - no priority 1 - - no default-metric 10 - - no router-id 2.2.2.2 - - no demand-circuit - - no packet-size 577 - - no transmit-delay 2 - - no dead-interval 2 - - no hello-interval 1 - - no retransmit-interval 2 - - no mtu-ignore - - no area 11 default-cost 5 - - no area 22 default-cost 6 + - no router ospfv3 26 + - no router ospfv3 27 + - no router ospfv3 30 + - no router ospfv3 10 - after: - processes: - - process_id: "10" - - process_id: "26" - - process_id: "27" - - process_id: "30" round_trip: after: processes: - - process_id: "10" - authentication: disable: true process_id: "26" @@ -257,4 +214,3 @@ round_trip: cost: 2 default_cost: 2 process_id: "27" - - process_id: "30" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ping/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ping/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ping/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ping/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_prefix_lists/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_prefix_lists/tasks/cli.yaml index 01bf509b4..6f505600c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_prefix_lists/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_prefix_lists/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml index f0489b91e..e9f2156f5 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml index 7488554f2..e5e2bb27d 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test cases (connection=netconf) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_snmp_server/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_snmp_server/tasks/cli.yaml index a1b57ab45..86ca0d9cb 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_snmp_server/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_snmp_server/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/cli.yaml index 01bf509b4..46e4015a6 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/cli.yaml @@ -8,7 +8,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) @@ -18,3 +19,5 @@ with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + tags: + - iosxr_static_routes diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml index 4b7d599c6..70cc8fee7 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml @@ -2,4 +2,4 @@ - name: Include the CLI tasks ansible.builtin.include_tasks: cli.yaml tags: - - network_cli + - iosxr_static_routes diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/delete_specific.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/delete_specific.yaml new file mode 100644 index 000000000..5ba3bc052 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/delete_specific.yaml @@ -0,0 +1,34 @@ +--- +- ansible.builtin.debug: + msg: Start iosxr_static_routes deleted integration tests ansible_connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Delete specific static route entry. + register: result + cisco.iosxr.iosxr_static_routes: &id001 + config: + - vrf: DEV_SITE + address_families: + - afi: ipv4 + safi: unicast + routes: + - dest: 192.0.2.48/28 + next_hops: + - forward_router_address: 192.0.2.12 + description: DEV + dest_vrf: test_1 + state: deleted + + - ansible.builtin.assert: + that: + - '"router static" in result.commands' + - '"vrf DEV_SITE" in result.commands' + - '"address-family ipv4 unicast" in result.commands' + - '"no 192.0.2.48/28 vrf test_1 192.0.2.12" in result.commands' + - result.commands|length == 4 + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml index 8ae46e432..88e4708f8 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml index d04b02101..49e51671c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml @@ -7,7 +7,8 @@ delegate_to: localhost - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.netconf) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml index e83cda978..63b094e91 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml @@ -3,7 +3,8 @@ msg: START netconf/set_domain_search.yaml on connection={{ ansible_connection }} - name: Setup - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_config: lines: - no domain list ansible.com @@ -14,7 +15,8 @@ match: none - name: Configure domain_search - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: @@ -28,7 +30,8 @@ - "'redhat.com' in result.xml[0]" - name: Configure domain_search with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id001 vrf: ansiblevrf @@ -44,15 +47,18 @@ - "'redhat.com' in result.xml[0]" - name: Verify domain_search with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id001 + - ansible.builtin.assert: that: - result.changed == false - name: Delete domain_search with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id002 vrf: ansiblevrf @@ -66,7 +72,8 @@ - "'ansible.com' in result.xml[0]" - name: Verify delete domain_search with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id002 - ansible.builtin.assert: @@ -74,7 +81,8 @@ - result.changed == false - name: Remove one entry - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: @@ -86,7 +94,8 @@ - "'redhat.com' in result.xml[0]" - name: Verify remove one entry - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: @@ -97,7 +106,8 @@ - result.changed == false - name: Add one entry - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: @@ -110,7 +120,8 @@ - "'redhat.com' in result.xml[0]" - name: Verify add one entry - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: @@ -122,7 +133,8 @@ - result.changed == false - name: Add and remove one entry - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: @@ -137,7 +149,8 @@ - result.xml|length == 2 - name: Verify add and remove one entry - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: domain_search: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml index b2b9d7b47..0b50df722 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml @@ -3,7 +3,8 @@ msg: START netconf/set_domain_name.yaml on connection={{ ansible_connection }} - name: Setup - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_config: lines: - no domain name @@ -11,7 +12,8 @@ match: none - name: Configure domain_name - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id001 domain_name: eng.ansible.com @@ -21,7 +23,8 @@ - result.changed == true - name: Verify domain_name - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id001 - ansible.builtin.assert: @@ -29,7 +32,8 @@ - result.changed == false - name: Configure domain_name - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id002 domain_name: eng.ansible.com @@ -40,7 +44,8 @@ - result.changed == true - name: Verify domain_name - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id002 - ansible.builtin.assert: @@ -48,7 +53,8 @@ - result.changed == false - name: Configure domain_name with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id003 domain_name: eng.ansible.com @@ -59,9 +65,11 @@ - result.changed == true - name: Verify domain_name with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id003 + - ansible.builtin.assert: that: - result.changed == false diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml index 61277e0d6..3080c9db3 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml @@ -3,7 +3,8 @@ msg: START netconf/set_lookup_source.yaml on connection={{ ansible_connection }} - name: Setup - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_config: lines: - no domain lookup source-interface Loopback10 @@ -16,7 +17,8 @@ ansible.builtin.meta: reset_connection - name: Configure lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id001 lookup_source: Loopback10 @@ -27,15 +29,18 @@ - "'Loopback10' in result.xml[0]" - name: Verify lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id001 + - ansible.builtin.assert: that: - result.changed == false - name: Disable lookup - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id002 lookup_enabled: false @@ -46,7 +51,8 @@ - "'lookup' in result.xml[0]" - name: Verify disable lookup - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id002 - ansible.builtin.assert: @@ -54,7 +60,8 @@ - result.changed == false - name: Delete lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id003 lookup_source: Loopback10 @@ -66,7 +73,8 @@ - "'Loopback10' in result.xml[0]" - name: Verify lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id003 - ansible.builtin.assert: @@ -74,7 +82,8 @@ - result.changed == false - name: Configure lookup_source with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id004 lookup_source: Loopback10 @@ -87,15 +96,18 @@ - "'ansiblevrf' in result.xml[0]" - name: Verify lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id004 + - ansible.builtin.assert: that: - result.changed == false - name: Disable lookup - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id005 lookup_enabled: false @@ -108,7 +120,8 @@ - "'ansiblevrf' in result.xml[0]" - name: Verify disable lookup - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id005 - ansible.builtin.assert: @@ -116,7 +129,8 @@ - result.changed == false - name: Delete lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id006 lookup_source: Loopback10 @@ -130,7 +144,8 @@ - "'ansiblevrf' in result.xml[0]" - name: Verify lookup_source - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id006 - ansible.builtin.assert: @@ -138,7 +153,8 @@ - result.changed == false - name: Teardown - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_config: lines: - no domain lookup disable diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml index dc8881587..1f40d0b1a 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml @@ -3,7 +3,8 @@ msg: START netconf/set_name_servers.yaml on connection={{ ansible_connection }} - name: Setup - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_config: lines: - no domain name-server 192.0.2.1 @@ -12,7 +13,8 @@ match: none - name: Setup - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf ignore_errors: true register: result cisco.iosxr.iosxr_system: @@ -24,7 +26,8 @@ state: absent - name: Configure name_servers - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: name_servers: @@ -41,7 +44,8 @@ - "'192.0.2.3' in result.xml[0]" - name: Verify name_servers - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: name_servers: @@ -54,7 +58,8 @@ - result.changed == false - name: Add name servers with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: &id001 vrf: ansible @@ -73,7 +78,8 @@ - "'192.0.2.3' in result.xml[0]" - name: Verify change to VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: *id001 - ansible.builtin.assert: @@ -81,7 +87,8 @@ - result.changed == false - name: Remove one - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_system: name_servers: @@ -95,7 +102,8 @@ - "'192.0.2.3' in result.xml[0]" - name: Remove one with VRF - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf ignore_errors: true register: result cisco.iosxr.iosxr_system: @@ -105,7 +113,8 @@ - 192.0.2.2 - name: Teardown - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_config: lines: - no domain name-server 192.0.2.1 @@ -113,7 +122,8 @@ match: none - name: Teardown - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf ignore_errors: true register: result cisco.iosxr.iosxr_system: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/private b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/private deleted file mode 100644 index bf2425bb8..000000000 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/private +++ /dev/null @@ -1,30 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,A823A6B5ED873917 - -mLZ1xM1+xwutkRy+K/c9QsstDPQ9F6UWtDpoYyIgs7n9VgMjhIMbWQC9CkTvnFJM -ey+iwGdQZZOThwxalm+k3pMibwRjhnF+PNFhiVkzWH8/K8QvXRQiW/vYmE/QB9pY -T0IWbMcC7/ktEfQn+6GLXoe/L7yH+aNv/2Flsa2jN2cfSXpzbneUA06/LVVOw6E+ -C74NKRWUmMPA39Zd4WOeBoWUdS5Kgwl57SOtrKs1LIGh33+TPu+Go8gJ7h/t/kaN -kverVSz+0eeX+exKumejfo1UfosplRhcjRG8YgiQ8l7SN3NBF/gXiiSrH3fLwmRJ -hbokJ8TmCozrYBs1MNe3LoU2iuIqVnJ5Sd6DJELs6vCuFz+v6J/s80NaaYMlBCbB -1lahelYqoyLb4uiDd4zQSpaxzO+Cx/d50Wpee8mFxbAL/YxacOzD3b/VCBgB+AZN -TTHr1ayd+ITd8gewXAyERKWyrDcC2beJI0fOil23PYowWvEncS6I1f4hKQY28sRf -vHSbwQdltky/xiib2/feQTaMSQFvsY67uTHipMwl5wJNOKcbeqDVMWPYST3XUsBg -LRlbT+VTUEehbOJAJ6Hh7Yv4nqu7fEh95HUQK7Ed56rMLKpmdorYO49JtewkEUsj -LJn7tcxMUuOcWKHMPu6vB/63f6Ulthqp1SEG8aNBaZMuPyLWAPAJc2okOmkiSbvO -0Hxe6BtAGn2fUo2jK6E3tD/dsIR2qqMlL09FkACGT8D5Lfh5d3z+lo9DxpXl281R -ablehPyHgHcIC6cD2/7FwwjzUuyj/kYcETnMs51agcWFAXTom/ehqD+IQ8jZ73zT -5O4FFgslnNmB/vddh9PeYpjDYdR4y5xMrlMxJ+qcZuQOq7dfaiodq8oj+XPmwgxA -audX/sHMutOpmOagrsQfaQXaPqRXdQTnuwHacQfwq+tBBhrft5gwt1HE7Ir2ulwD -Q19kefchkJu/0c1cAGg1VHtQic0a6tX6PrwqZOMDfpSywcImMCF4KHgD2EC5/8h6 -tq0PqPLNcwiM2NhpypCuYmkYZ0gnJ/xAwtM85Ck9nmPFptLSd0b7YB7dtGsFYY5A -rhIcq5lZhy06/RRAPluIkniscA50iEO/EXKwzYzovBJh6jQz7oYsbEUW5kwg0gm/ -YPSa6lqv2kTpXS+UiGyeNWdUkr5DpdwKe4lrAsN94HE9/SoLgFvz0X5/WyTssSzo -IO3WfLfBc7SOkZK1ibcleIqilzd+LSoIqqGrft2yonXgJD3p9xO+Hlldczx2kHmu -z4lZBq53AkVAQ4os5L7ZRnmxoqKn2XAQRwVH3M9ZFYFEqEyDmZhlFdJSGEnKws81 -Ej48t6KWwqml02cx675bSYI22tL3+RL7AGmlC0/Xh8wIVesgulsYmnhW4BtpBYf2 -fwv5esJJMjkh2LvLNG3edYChugudeZXtcBJdNr0GYRbBAhvO25bRcr6z8nYDusKX -e/+30vATOcBO/zaOYIwDGT5ZwMQAV1aQl8HyeyYESNjb0fBXQ3OYObOrTTs8MLyC -I4b6wr1vlbN+lMOm+RIXCDgmC3COdlgCHyo3qiIu2YNYQVoNF4NN4A== ------END RSA PRIVATE KEY----- diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public.pub b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public.pub deleted file mode 100644 index db1847f45..000000000 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAkvLTTJdwZ0lg1cUCn13Hi3+ho2+G6/96XuAP7jA7Ghz9NPbC/eqXnjvb27BA8CxtFXYuXR5eZWSq2UN5zFcfrFb57XFxdAg2q21hGEX+FGiTUuRZh8+ByVEh0LUetFTwsEZ1iGv6GZiLBt7IJvClXbyNTJEt3DZncHfGwudyGFviV4dGrzusDAGAcoHqvD/5uXYl4PjMH9oSfraO3sG4Q7soQwxNeiM8qOLf3c1SabHBAtSewwnA0E/jhzpOLD2QUncU5s+Oa9PvEXXhGv5eZo9lp71brsgyWj32m2UuXx/n+EZg78GVJT5mFO7LG239n3gTnwkMVdr6zVBFNX5Mvw== rsa-key-20171025 diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public2.pub b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public2.pub deleted file mode 100644 index 26af0db95..000000000 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public2.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAhTxbibM8hKZn7xDURs15L3gkcsnpDoZ+tNm5zpP9dcboASnIyJzfC7J/RdRCQsO/pDmUY4y/tsTx18uenyfazxtNkyCHdANlp8XVF1fGNv5GM+QbsDqxe54sdG9csASX0/Ljvl538IbcLFVH0zxyKspbDOgkAkUSuKIAH5x+/GhkAoGQO2tOhYjqofNtUxLSvfRsf4Gm1M0WgdWmz3MW4NOdZhsL4S+STgRPU1jy1dKGj7BKY9cpnCWBFHa2wSaOXJEBZEKNaFVxlBBrFs5brjRQA0mVPmE+pz+/+IJeSNEEma9cXur0ONeb6OoXvkManxKfkaswT2ybOChAzJR8dQ== T-MOBILE diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml index ab72bff13..e5474513c 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml @@ -21,7 +21,8 @@ files: "{{ common_test_cases.files + test_cases.files }}" - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml index 855bba5cf..342026211 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml @@ -19,7 +19,8 @@ files: "{{ common_test_cases.files + test_cases.files }}" - name: Set test_items - ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" - name: Run test case (connection=ansible.netcommon.netconf) ansible.builtin.include_tasks: "{{ test_case_to_run }}" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/auth.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/_auth.yaml index 3c2e6e468..3af284335 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/auth.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/_auth.yaml @@ -1,5 +1,15 @@ --- - block: + - name: Generate /etc/ssh/ RSA host key + ansible.builtin.command: ssh-keygen -q -t rsa -f "{{role_path}}"/mykey -C "" -N "" + args: + creates: "{{role_path}}/mykey" + + - name: Generate /etc/ssh/ RSA host key + ansible.builtin.command: ssh-keygen -q -t rsa -f "{{role_path}}"/mykey1 -C "" -N "" + args: + creates: "{{role_path}}/mykey1" + - name: Create user with password connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_user: @@ -33,13 +43,11 @@ cisco.iosxr.iosxr_user: name: auth_user state: present - public_key_contents: '{{ lookup(''file'', "{{ role_path }}/files/public.pub") }}' + public_key_contents: '{{ lookup(''file'', "{{role_path}}/mykey.pub") }}' - name: Test login with private key ansible.builtin.expect: - command: - ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path - }}/files/private show version + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{role_path}}/mykey show version responses: (?i)password: pass123 connection: ansible.netcommon.network_cli @@ -52,9 +60,7 @@ - name: Test login with private key (should fail, no user) ansible.builtin.expect: - command: - ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path - }}/files/private show version + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{role_path}}/mykey show version responses: (?i)password: pass123 ignore_errors: true @@ -64,15 +70,13 @@ - name: Create user with private key (path input) connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_user: - name: auth_user + name: auth_user1 state: present - public_key: "{{ role_path }}/files/public.pub" + public_key: "{{role_path}}/mykey.pub" - name: Test login with private key ansible.builtin.expect: - command: - ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path - }}/files/private show version + command: ssh auth_user1@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{role_path}}/mykey show version responses: (?i)password: pass123 ignore_errors: true @@ -81,15 +85,13 @@ - name: Change private key for user connection: ansible.netcommon.network_cli cisco.iosxr.iosxr_user: - name: auth_user + name: auth_user1 state: present - public_key_contents: '{{ lookup(''file'', "{{ role_path }}/files/public2.pub") }}' + public_key_contents: '{{ lookup(''file'', "{{role_path}}/mykey1.pub") }}' - name: Test login with invalid private key (should fail) ansible.builtin.expect: - command: - ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path - }}/files/private show version + command: ssh auth_user1@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{role_path}}/mykey show version responses: (?i)password: pass123 ignore_errors: true @@ -103,7 +105,12 @@ always: - name: Delete user connection: ansible.netcommon.network_cli - register: result cisco.iosxr.iosxr_user: - name: auth_user + name: "{{item}}" state: absent + with_items: + - auth_user + - auth_user1 + + - name: Remove keys + ansible.builtin.command: "rm -rf {{role_path}}/mykey*" diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/_basic.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/basic.yaml index 6107ff021..3d5bf6e29 100644 --- a/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/_basic.yaml +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/basic.yaml @@ -1,6 +1,7 @@ --- - name: Remove users prior to tests - connection: ansible.netcommon.network_cli + vars: + ansible_connection: ansible.netcommon.netconf cisco.iosxr.iosxr_config: lines: - no username ansible1 @@ -8,7 +9,8 @@ - no username ansible3 - name: Create user (setup) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: name: ansible1 @@ -22,7 +24,8 @@ - '"secret" in result.xml[0]' - name: Create user with update_password always (not idempotent) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: name: ansible1 @@ -37,7 +40,8 @@ - '"secret" in result.xml[0]' - name: Create user again with update_password on_create (idempotent) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: name: ansible1 @@ -51,7 +55,8 @@ - result.xml | length == 0 - name: Modify user group - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: name: ansible1 @@ -67,7 +72,8 @@ - '"sysadmin" in result.xml[0]' - name: Modify user group again (idempotent) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: name: ansible1 @@ -82,7 +88,8 @@ - result.xml | length == 0 - name: Collection of users (setup) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: aggregate: @@ -104,7 +111,8 @@ - '"sysadmin" in result.xml[1]' - name: Add collection of users again with update_password always (not idempotent) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: aggregate: @@ -123,7 +131,8 @@ - '"secret" in result.xml[0]' - name: Add collection of users again with update_password on_create (idempotent) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: aggregate: @@ -141,7 +150,8 @@ - result.xml | length == 0 - name: Delete collection of users - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: aggregate: @@ -160,7 +170,8 @@ - '"ansible3" in result.xml[0]' - name: Delete collection of users again (idempotent) - connection: ansible.netcommon.netconf + vars: + ansible_connection: ansible.netcommon.netconf register: result cisco.iosxr.iosxr_user: aggregate: diff --git a/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/meta/main.yaml b/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/meta/main.yaml new file mode 100644 index 000000000..61d3ffe4f --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/meta/main.yaml @@ -0,0 +1,2 @@ +--- +allow_duplicates: true diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt index b61dcef1d..c2f1a6018 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt @@ -1,6 +1,4 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation plugins/module_utils/network/iosxr/config/acl_interfaces/acl_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospfv2/ospfv2.py compile-2.6!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.11.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.11.txt index b83ac9dcf..b492817fc 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.11.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.11.txt @@ -1,6 +1,4 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation plugins/module_utils/network/iosxr/config/acl_interfaces/acl_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospfv2/ospfv2.py compile-2.6!skip @@ -29,8 +27,5 @@ plugins/modules/iosxr_bgp_global.py import-2.6!skip plugins/modules/iosxr_prefix_lists.py import-2.6!skip plugins/modules/iosxr_logging_global.py import-2.6!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.7!skip -plugins/sub_plugins/grpc/iosxr.py import-3.7!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.8!skip -plugins/sub_plugins/grpc/iosxr.py import-3.8!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip -plugins/sub_plugins/grpc/iosxr.py import-3.9!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.12.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.12.txt index 393d598b4..14952a817 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.12.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.12.txt @@ -1,6 +1,4 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation plugins/module_utils/network/iosxr/config/acl_interfaces/acl_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospfv2/ospfv2.py compile-2.6!skip @@ -28,12 +26,6 @@ plugins/modules/iosxr_bgp_address_family.py import-2.6!skip plugins/modules/iosxr_bgp_global.py import-2.6!skip plugins/modules/iosxr_prefix_lists.py import-2.6!skip plugins/modules/iosxr_logging_global.py import-2.6!skip -plugins/cliconf/iosxr.py pylint:arguments-renamed -plugins/netconf/iosxr.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.8!skip -plugins/sub_plugins/grpc/iosxr.py import-3.8!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip -plugins/sub_plugins/grpc/iosxr.py import-3.9!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip -plugins/sub_plugins/grpc/iosxr.py import-3.10!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.13.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.13.txt index b00006c2b..5d99b9b08 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.13.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.13.txt @@ -1,12 +1,4 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation -plugins/cliconf/iosxr.py pylint:arguments-renamed -plugins/netconf/iosxr.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.8!skip -plugins/sub_plugins/grpc/iosxr.py import-3.8!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip -plugins/sub_plugins/grpc/iosxr.py import-3.9!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip -plugins/sub_plugins/grpc/iosxr.py import-3.10!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.14.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.14.txt index ad1f84d84..63b93ff5a 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.14.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.14.txt @@ -1,12 +1,4 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation -plugins/cliconf/iosxr.py pylint:arguments-renamed -plugins/netconf/iosxr.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip -plugins/sub_plugins/grpc/iosxr.py import-3.9!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip -plugins/sub_plugins/grpc/iosxr.py import-3.10!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip -plugins/sub_plugins/grpc/iosxr.py import-3.11!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.15.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.15.txt index ad1f84d84..63b93ff5a 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.15.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.15.txt @@ -1,12 +1,4 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation -plugins/cliconf/iosxr.py pylint:arguments-renamed -plugins/netconf/iosxr.py pylint:arguments-renamed -tests/unit/mock/loader.py pylint:arguments-renamed plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip -plugins/sub_plugins/grpc/iosxr.py import-3.9!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip -plugins/sub_plugins/grpc/iosxr.py import-3.10!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip -plugins/sub_plugins/grpc/iosxr.py import-3.11!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.16.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.16.txt new file mode 100644 index 000000000..450f3eab7 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.16.txt @@ -0,0 +1,4 @@ +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.12!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.17.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.17.txt new file mode 100644 index 000000000..450f3eab7 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.17.txt @@ -0,0 +1,4 @@ +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.12!skip diff --git a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt index eedc28b70..aab3e8dfc 100644 --- a/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt +++ b/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt @@ -1,8 +1,6 @@ plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local plugins/modules/iosxr_logging.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/iosxr_logging.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict -plugins/modules/iosxr_bgp.py validate-modules:deprecation-mismatch -plugins/modules/iosxr_bgp.py validate-modules:invalid-documentation plugins/module_utils/network/iosxr/config/acl_interfaces/acl_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/iosxr/config/ospfv2/ospfv2.py compile-2.6!skip diff --git a/ansible_collections/cisco/iosxr/tests/unit/compat/builtins.py b/ansible_collections/cisco/iosxr/tests/unit/compat/builtins.py deleted file mode 100644 index e898a081e..000000000 --- a/ansible_collections/cisco/iosxr/tests/unit/compat/builtins.py +++ /dev/null @@ -1,35 +0,0 @@ -# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -# -# Compat for python2.7 -# - -# One unittest needs to import builtins via __import__() so we need to have -# the string that represents it -try: - import __builtin__ -except ImportError: - BUILTINS = "builtins" -else: - BUILTINS = "__builtin__" diff --git a/ansible_collections/cisco/iosxr/tests/unit/mock/loader.py b/ansible_collections/cisco/iosxr/tests/unit/mock/loader.py index 2b5eb36a1..0fc53edcd 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/mock/loader.py +++ b/ansible_collections/cisco/iosxr/tests/unit/mock/loader.py @@ -31,7 +31,7 @@ from ansible.parsing.dataloader import DataLoader class DictDataLoader(DataLoader): def __init__(self, file_mapping=None): file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict + assert isinstance(file_mapping, dict) super(DictDataLoader, self).__init__() @@ -47,12 +47,12 @@ class DictDataLoader(DataLoader): # TODO: the real _get_file_contents returns a bytestring, so we actually convert the # unicode/text it's created with to utf-8 - def _get_file_contents(self, path): - path = to_text(path) - if path in self._file_mapping: - return (to_bytes(self._file_mapping[path]), False) + def _get_file_contents(self, file_name): + file_name = to_text(file_name) + if file_name in self._file_mapping: + return (to_bytes(self._file_mapping[file_name]), False) else: - raise AnsibleParserError("file not found: %s" % path) + raise AnsibleParserError("file not found: %s" % file_name) def path_exists(self, path): path = to_text(path) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_acl_replace_config.cfg b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_acl_replace_config.cfg new file mode 100644 index 000000000..7b2917fa6 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_acl_replace_config.cfg @@ -0,0 +1,2 @@ +ipv4 access-list ACL-TEST +10 remark THIS IS A REMARK diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_interface_gathered.cfg b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_interface_gathered.cfg new file mode 100644 index 000000000..f05a6eb71 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_interface_gathered.cfg @@ -0,0 +1,11 @@ + +interface GigabitEthernet0/0/0/5 + description RTI-DSKMPLS-LP201 #G0/0 + mtu 9216 + ipv4 address 10.255.2.9 255.255.255.252 +! +interface GigabitEthernet0/0/0/6 + description RTI-DSKMPLS-LP301 #G0/1 + mtu 9216 + ipv4 address 10.255.2.17 255.255.255.252 +! diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_processes_cpu___include_CPU_utilization b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_processes_cpu___include_CPU_utilization new file mode 100644 index 000000000..b2dc00f6e --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_processes_cpu___include_CPU_utilization @@ -0,0 +1 @@ +CPU utilization for one minute: 21%; five minutes: 13%; fifteen minutes: 8% diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py index 1915b07ea..f94f4d222 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py @@ -62,7 +62,6 @@ class TestIosxrModule(ModuleTestCase): sort=True, defaults=False, ): - self.load_fixtures(commands) if failed: diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py index ed826b930..181b239d8 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py @@ -54,14 +54,14 @@ class TestIosxrAclsModule(TestIosxrModule): self.mock_load_config.stop() self.mock_execute_show_command.stop() - def _prepare(self): + def _prepare(self, config): def load_from_file(*args, **kwargs): - return load_fixture("iosxr_acls_config.cfg") + return load_fixture(config) self.execute_show_command.side_effect = load_from_file def test_iosxr_acls_merged(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -120,7 +120,7 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=True, commands=commands) def test_iosxr_acls_merged_idempotent(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -148,7 +148,7 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=False, commands=[]) def test_iosxr_acls_replaced(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -209,7 +209,7 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=True, commands=commands) def test_iosxr_acls_replaced_idempotent(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -244,7 +244,7 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=False, commands=[]) def test_iosxr_acls_overridden(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -307,7 +307,7 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=True, commands=commands) def test_iosxr_acls_overridden_idempotent(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -388,7 +388,7 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=False, commands=[]) def test_iosxr_acls_deletedacls(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[dict(afi="ipv6", acls=[dict(name="acl6_1")])], @@ -399,13 +399,13 @@ class TestIosxrAclsModule(TestIosxrModule): self.execute_module(changed=True, commands=commands) def test_iosxr_acls_deletedafis(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args(dict(config=[dict(afi="ipv4")], state="deleted")) commands = ["no ipv4 access-list acl_2", "no ipv4 access-list acl_1"] self.execute_module(changed=True, commands=commands) def test_iosxr_acls_rendered(self): - self._prepare() + self._prepare("iosxr_acls_config.cfg") set_module_args( dict( config=[ @@ -494,3 +494,39 @@ class TestIosxrAclsModule(TestIosxrModule): }, ] self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_acls_replaced_remark(self): + self._prepare("iosxr_acl_replace_config.cfg") + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="ACL-TEST", + aces=[ + dict( + sequence="10", + grant="permit", + protocol="ipv4", + source=dict( + any=True, + ), + destination=dict( + host="1.1.1.1", + ), + ), + ], + ), + ], + ), + ], + state="replaced", + ), + ) + commands = [ + "ipv4 access-list ACL-TEST", + "10 permit ipv4 any host 1.1.1.1", + ] + self.execute_module(changed=True, commands=commands) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_banner.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_banner.py index 8c426f832..5dcbada13 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_banner.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_banner.py @@ -47,7 +47,6 @@ from .iosxr_module import TestIosxrModule, load_fixture class TestIosxrBannerModule(TestIosxrModule): - module = iosxr_banner def setUp(self): diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py index 05480d092..901b5b4d8 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py @@ -224,6 +224,19 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): minimum_interval=20, fast_detect=dict(strict_mode=True), ), + use=dict( + neighbor_group="test_ng", + session_group="test_sg", + ), + password=dict( + inheritance_disable="true", + ), + local_as=dict( + value="65539", + no_prepend=dict( + set="true", + ), + ), ), ], vrfs=[dict(vrf="vrf1", default_metric=5)], @@ -240,6 +253,10 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): "bfd fast-detect strict-mode", "bfd minimum-interval 20", "bfd multiplier 6", + "use session-group test_sg", + "use neighbor-group test_ng", + "local-as 65539 no-prepend", + "password inheritance-disable", "remote-as 65538", ] result = self.execute_module(changed=True) @@ -264,6 +281,8 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): bfd fast-detect strict-mode bfd multiplier 6 bfd minimum-interval 20 + use session-group test_sg + use neighbor-group test_ng vrf vrf1 default-metric 5 """, @@ -298,6 +317,10 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): minimum_interval=20, fast_detect=dict(strict_mode=True), ), + use=dict( + neighbor_group="test_ng", + session_group="test_sg", + ), ), ], vrfs=[dict(vrf="vrf1", default_metric=5)], @@ -386,6 +409,10 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): dict( neighbor="192.0.2.14", remote_as="65538", + use=dict( + neighbor_group="test_nb", + session_group="test_sg", + ), bfd=dict( multiplier=6, minimum_interval=20, @@ -415,6 +442,8 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): "bfd fast-detect", "bfd minimum-interval 20", "bfd multiplier 6", + "use neighbor-group test_nb", + "use session-group test_sg", "remote-as 65538", "vrf vrf1", "default-metric 5", @@ -429,7 +458,9 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): running_config="router bgp 65536\n bgp confederation identifier 4\n " "bgp router-id 192.0.2.10\n bgp cluster-id 5\n default-metric 4\n " "socket send-buffer-size 4098\n bgp bestpath med confed\n " - "socket receive-buffer-size 514\n neighbor 192.0.2.11\n remote-as 65537\n " + "socket receive-buffer-size 514\n neighbor 192.0.2.11\n " + "local-as 4 no-prepend replace-as\n " + "password encrypted 15060E1F107B\n remote-as 65537\n " "cluster-id 3\n !\n neighbor 192.0.2.14\n remote-as 65538\n description test nbr description\n" " bfd fast-detect strict-mode\n " " bfd multiplier 6\n bfd minimum-interval 20\n !\n!", @@ -448,7 +479,16 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): "default_metric": 4, "socket": {"send_buffer_size": 4098, "receive_buffer_size": 514}, "neighbors": [ - {"neighbor_address": "192.0.2.11", "remote_as": 65537, "cluster_id": "3"}, + { + "neighbor_address": "192.0.2.11", + "remote_as": 65537, + "cluster_id": "3", + "password": {"encrypted": "15060E1F107B"}, + "local_as": { + "no_prepend": {"replace_as": {"set": True}}, + "value": 4, + }, + }, { "neighbor_address": "192.0.2.14", "remote_as": 65538, @@ -491,3 +531,158 @@ class TestIosxrBgpGlobalModule(TestIosxrModule): result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) + + def test_iosxr_bgp_global_ovrridden(self): + run_cfg = dedent( + """\ + router bgp 65536 + bgp confederation identifier 4 + bgp router-id 192.0.2.10 + bgp cluster-id 5 + default-metric 4 + socket send-buffer-size 4098 + bgp bestpath med confed + socket receive-buffer-size 514 + neighbor 192.0.2.11 + remote-as 65537 + cluster-id 3 + neighbor 192.0.2.14 + remote-as 65538 + bfd fast-detect strict-mode + bfd multiplier 6 + bfd minimum-interval 20 + vrf vrf1 + default-metric 5 + """, + ) + self.get_config.return_value = run_cfg + set_module_args( + dict( + config=dict( + as_number="65536", + default_metric=5, + socket=dict( + receive_buffer_size=514, + send_buffer_size=4098, + ), + bgp=dict( + confederation=dict(identifier=4), + bestpath=dict(med=dict(confed=True)), + cluster_id=5, + router_id="192.0.2.10", + ), + neighbors=[ + dict( + neighbor="192.0.2.13", + remote_as="65538", + bfd=dict( + multiplier=6, + minimum_interval=20, + fast_detect=dict(strict_mode=True), + ), + use=dict( + neighbor_group="test_ng", + session_group="test_sg", + ), + password=dict( + inheritance_disable="true", + ), + local_as=dict( + value="65539", + no_prepend=dict( + set="true", + ), + ), + ), + ], + vrfs=[dict(vrf="vrf1", default_metric=5)], + ), + state="overridden", + ), + ) + commands = [ + "router bgp 65536", + "no neighbor 192.0.2.11", + "no neighbor 192.0.2.14", + "default-metric 5", + "neighbor 192.0.2.13", + "bfd fast-detect strict-mode", + "bfd minimum-interval 20", + "bfd multiplier 6", + "use session-group test_sg", + "use neighbor-group test_ng", + "local-as 65539 no-prepend", + "password inheritance-disable", + "remote-as 65538", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_bgp_global_overridden_idempotent(self): + run_cfg = dedent( + """\ + router bgp 65536 + bgp confederation identifier 4 + bgp router-id 192.0.2.10 + bgp cluster-id 5 + default-metric 4 + socket send-buffer-size 4098 + bgp bestpath med confed + socket receive-buffer-size 514 + neighbor 192.0.2.11 + remote-as 65537 + cluster-id 3 + neighbor 192.0.2.14 + remote-as 65538 + bfd fast-detect strict-mode + bfd multiplier 6 + bfd minimum-interval 20 + use session-group test_sg + use neighbor-group test_ng + vrf vrf1 + default-metric 5 + """, + ) + self.get_config.return_value = run_cfg + set_module_args( + dict( + config=dict( + as_number="65536", + default_metric=4, + socket=dict( + receive_buffer_size=514, + send_buffer_size=4098, + ), + bgp=dict( + confederation=dict(identifier=4), + bestpath=dict(med=dict(confed=True)), + cluster_id=5, + router_id="192.0.2.10", + ), + neighbors=[ + dict( + neighbor="192.0.2.11", + cluster_id=3, + remote_as="65537", + ), + dict( + neighbor="192.0.2.14", + remote_as="65538", + bfd=dict( + multiplier=6, + minimum_interval=20, + fast_detect=dict(strict_mode=True), + ), + use=dict( + neighbor_group="test_ng", + session_group="test_sg", + ), + ), + ], + vrfs=[dict(vrf="vrf1", default_metric=5)], + ), + state="overridden", + ), + ) + + self.execute_module(changed=False, commands=[]) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py new file mode 100644 index 000000000..4efc04503 --- /dev/null +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py @@ -0,0 +1,1266 @@ +# (c) 2021 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from textwrap import dedent + +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_bgp_templates +from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args + +from .iosxr_module import TestIosxrModule + + +class TestIosxrBgptemplatesModule(TestIosxrModule): + module = iosxr_bgp_templates + + def setUp(self): + super(TestIosxrBgptemplatesModule, self).setUp() + + self.mock_get_resource_connection = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection = self.mock_get_resource_connection.start() + + self.mock_get_config = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.bgp_templates.bgp_templates." + "Bgp_templatesFacts.get_config", + ) + self.get_config = self.mock_get_config.start() + + def tearDown(self): + super(TestIosxrBgptemplatesModule, self).tearDown() + self.get_resource_connection.stop() + self.get_config.stop() + + def test_iosxr_bgp_tmpl_merged_idempotent(self): + run_cfg = dedent( + """\ + router bgp 1 + neighbor-group test + bfd fast-detect strict-mode + precedence critical + advertisement-interval 10 + internal-vpn-client + address-family ipv4 unicast + advertise local-labeled-route + ! + ! + neighbor-group test1 + bfd fast-detect + bfd minimum-interval 3 + keychain test + ebgp-multihop 255 + egress-engineering + precedence flash + graceful-maintenance + as-prepends 0 + ! + advertisement-interval 2 + tcp mss inheritance-disable + local-as 6 + password inheritance-disable + cluster-id 1 + dmz-link-bandwidth + description test + ttl-security + local address inheritance-disable + update-source Loopback919 + idle-watch-time 30 + ignore-connected-check + session-open-mode both + send-buffer-size 4096 + receive-buffer-size 512 + internal-vpn-client + address-family ipv4 unicast + origin-as validation disable + bestpath origin-as allow invalid + aigp + weight 0 + send-community-ebgp + multipath + route-reflector-client + allowas-in 1 + maximum-prefix 1 75 + as-override + capability orf prefix send + send-extended-community-ebgp + default-originate + long-lived-graceful-restart capable + next-hop-self + send-community-gshut-ebgp inheritance-disable + soft-reconfiguration inbound + send-multicast-attributes disable + Signalling bgp disable + remove-private-AS inbound + update out originator-loopcheck disable + advertise local-labeled-route + next-hop-unchanged inheritance-disable + ! + ! + + """, + ) + self.get_config.return_value = run_cfg + set_module_args( + dict( + config=dict( + as_number="1", + neighbor=[ + dict( + name="test", + bfd=dict(fast_detect=dict(strict_mode=True)), + advertisement_interval=10, + precedence="critical", + internal_vpn_client=True, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + advertise=dict(local_labeled_route=dict(set=True)), + ), + ], + ), + dict( + name="test1", + bfd=dict( + fast_detect=dict(set=True), + minimum_interval=3, + ), + keychain=dict(name="test"), + ebgp_multihop=dict(value=255), + egress_engineering=dict(set=True), + precedence="flash", + graceful_maintenance=dict( + as_prepends=dict( + value="0", + ), + set=True, + ), + advertisement_interval=2, + tcp=dict(mss=dict(inheritance_disable=True)), + local_as=dict(value=6), + password=dict(inheritance_disable=True), + cluster_id=1, + dmz_link_bandwidth=dict(set=True), + description="test", + ttl_security=dict(set=True), + local_address_subnet="1.1.1.1/24", + update_source="Loopback919", + idle_watch_time=30, + ignore_connected_check=dict(set=True), + session_open_mode="both", + send_buffer_size=4096, + receive_buffer_size=512, + internal_vpn_client=True, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + origin_as=dict(validation=dict(disable=True)), + bestpath_origin_as_allow_invalid=True, + aigp=dict(set=True), + weight=0, + multipath=True, + send_community_ebgp=dict(set=True), + route_reflector_client=dict(set=True), + allowas_in=dict(value=1), + maximum_prefix=dict( + max_limit=1, + threshold_value=75, + ), + as_override=dict(set=True), + capability_orf_prefix="send", + send_extended_community_ebgp=dict(set=True), + default_originate=dict(set=True), + long_lived_graceful_restart=dict( + capable=True, + ), + next_hop_self=dict(set=True), + send_community_gshut_ebgp=dict(inheritance_disable=True), + soft_reconfiguration=dict(inbound=dict(set=True)), + send_multicast_attributes=dict(disable=True), + signalling=dict(bgp_disable=True), + remove_private_AS=dict( + inbound=True, + ), + next_hop_unchanged=dict(inheritance_disable=True), + advertise=dict(local_labeled_route=dict(set=True)), + update=dict( + out_originator_loopcheck_disable=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_bgp_tmpl_merged(self): + self.maxDiff = None + set_module_args( + dict( + config=dict( + as_number="1", + neighbor=[ + dict( + name="test", + bfd=dict(fast_detect=dict(strict_mode=True)), + advertisement_interval=10, + precedence="critical", + internal_vpn_client=True, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + advertise=dict(local_labeled_route=dict(set=True)), + ), + ], + ), + dict( + name="test1", + bfd=dict( + fast_detect=dict(set=True), + minimum_interval=3, + ), + keychain=dict(name="test"), + ebgp_multihop=dict(value=255), + egress_engineering=dict(set=True), + precedence="flash", + graceful_maintenance=dict( + as_prepends=dict( + value="0", + ), + set=True, + ), + advertisement_interval=2, + tcp=dict(mss=dict(inheritance_disable=True)), + local_as=dict(value=6), + password=dict(inheritance_disable=True), + cluster_id=1, + dmz_link_bandwidth=dict(set=True), + description="test", + ttl_security=dict(set=True), + local_address_subnet="1.1.1.1/24", + update_source="Loopback919", + idle_watch_time=30, + ignore_connected_check=dict(set=True), + session_open_mode="both", + send_buffer_size=4096, + receive_buffer_size=512, + internal_vpn_client=True, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + origin_as=dict(validation=dict(disable=True)), + bestpath_origin_as_allow_invalid=True, + aigp=dict(set=True), + weight=0, + multipath=True, + send_community_ebgp=dict(set=True), + route_reflector_client=dict(set=True), + allowas_in=dict(value=1), + maximum_prefix=dict( + max_limit=1, + threshold_value=75, + ), + as_override=dict(set=True), + capability_orf_prefix="send", + send_extended_community_ebgp=dict(set=True), + default_originate=dict(set=True), + long_lived_graceful_restart=dict( + capable=True, + ), + next_hop_self=dict(set=True), + send_community_gshut_ebgp=dict(inheritance_disable=True), + soft_reconfiguration=dict(inbound=dict(set=True)), + send_multicast_attributes=dict(disable=True), + signalling=dict(bgp_disable=True), + remove_private_AS=dict( + inbound=True, + ), + next_hop_unchanged=dict(inheritance_disable=True), + advertise=dict(local_labeled_route=dict(set=True)), + update=dict( + out_originator_loopcheck_disable=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + "router bgp 1", + "neighbor-group test", + "advertisement-interval 10", + "bfd fast-detect strict-mode", + "internal-vpn-client", + "precedence critical", + "address-family ipv4 unicast", + "advertise local-labeled-route", + "neighbor-group test1", + "advertisement-interval 2", + "bfd fast-detect", + "bfd minimum-interval 3", + "dmz-link-bandwidth", + "description test", + "cluster-id 1", + "ebgp-multihop 255", + "egress-engineering", + "idle-watch-time 30 ", + "internal-vpn-client", + "ignore-connected-check", + "keychain test", + "local-as 6", + "password inheritance-disable", + "precedence flash", + "receive-buffer-size 512", + "send-buffer-size 4096", + "session-open-mode both", + "tcp mss inheritance-disable", + "update-source Loopback919", + "ttl-security", + "graceful-maintenance", + "graceful-maintenance as-prepends 0", + "address-family ipv4 unicast", + "advertise local-labeled-route", + "aigp", + "allowas-in 1", + "as-override", + "bestpath origin-as allow invalid", + "capability orf prefix send", + "default-originate", + "long-lived-graceful-restart capable", + "maximum-prefix 1 75", + "multipath", + "next-hop-self", + "next-hop-unchanged inheritance-disable", + "origin-as validation disable", + "remove-private-AS inbound", + "route-reflector-client", + "send-community-ebgp", + "send-community-gshut-ebgp inheritance-disable", + "send-extended-community-ebgp", + "send-multicast-attributes disable", + "soft-reconfiguration inbound", + "weight 0", + "signalling bgp disable ", + "update out originator-loopcheck disable", + ] + + result = self.execute_module(changed=True) + print(result["commands"]) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_bgp_tmpl_deleted(self): + self.maxDiff = None + run_cfg = dedent( + """\ + router bgp 1 + neighbor-group test + bfd fast-detect strict-mode + precedence critical + advertisement-interval 10 + internal-vpn-client + address-family ipv4 unicast + advertise local-labeled-route + ! + ! + neighbor-group test1 + bfd fast-detect + bfd minimum-interval 3 + keychain test + ebgp-multihop 255 + egress-engineering + precedence flash + graceful-maintenance + as-prepends 0 + ! + advertisement-interval 2 + tcp mss inheritance-disable + local-as 6 + password inheritance-disable + cluster-id 1 + dmz-link-bandwidth + description test + ttl-security + local address inheritance-disable + update-source Loopback919 + idle-watch-time 30 + ignore-connected-check + session-open-mode both + send-buffer-size 4096 + receive-buffer-size 512 + internal-vpn-client + address-family ipv4 unicast + origin-as validation disable + bestpath origin-as allow invalid + aigp + weight 0 + send-community-ebgp + multipath + route-reflector-client + allowas-in 1 + maximum-prefix 1 75 + as-override + capability orf prefix send + send-extended-community-ebgp + default-originate + long-lived-graceful-restart capable + next-hop-self + send-community-gshut-ebgp inheritance-disable + soft-reconfiguration inbound + send-multicast-attributes disable + Signalling bgp disable + remove-private-AS inbound + update out originator-loopcheck disable + advertise local-labeled-route + next-hop-unchanged inheritance-disable + ! + ! + + """, + ) + self.get_config.return_value = run_cfg + set_module_args(dict(config=dict(), state="deleted")) + commands = [ + "router bgp 1", + "no neighbor-group test", + "no neighbor-group test1", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_bgp_tmpl_deleted_idempotent(self): + run_cfg = dedent( + """\ + """, + ) + self.get_config.return_value = run_cfg + set_module_args(dict(config=dict(as_number="1"), state="deleted")) + + result = self.execute_module(changed=False) + self.assertEqual(result["commands"], []) + + def test_iosxr_bgp_tmpl_rendered(self): + set_module_args( + dict( + config=dict( + as_number="1", + neighbor=[ + dict( + name="test", + bfd=dict(fast_detect=dict(strict_mode=True)), + advertisement_interval=10, + precedence="critical", + internal_vpn_client=True, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + advertise=dict(local_labeled_route=dict(set=True)), + ), + ], + ), + dict( + name="test1", + bfd=dict( + fast_detect=dict(set=True), + minimum_interval=3, + ), + keychain=dict(name="test"), + ebgp_multihop=dict(value=255), + egress_engineering=dict(set=True), + precedence="flash", + graceful_maintenance=dict( + as_prepends=dict( + value="0", + ), + set=True, + ), + advertisement_interval=2, + tcp=dict(mss=dict(inheritance_disable=True)), + local_as=dict(no_prepend=dict(replace_as=dict(dual_as=True))), + password=dict(inheritance_disable=True), + cluster_id=1, + dmz_link_bandwidth=dict(set=True), + description="test", + ttl_security=dict(set=True), + local_address_subnet="1.1.1.1/24", + update_source="Loopback919", + idle_watch_time=30, + ignore_connected_check=dict(set=True), + session_open_mode="both", + send_buffer_size=4096, + receive_buffer_size=512, + internal_vpn_client=True, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + origin_as=dict(validation=dict(disable=True)), + bestpath_origin_as_allow_invalid=True, + aigp=dict(set=True), + weight=0, + multipath=True, + send_community_ebgp=dict(set=True), + route_reflector_client=dict(set=True), + allowas_in=dict(value=1), + maximum_prefix=dict( + warning_only=True, + ), + as_override=dict(set=True), + capability_orf_prefix="send", + send_extended_community_ebgp=dict(set=True), + default_originate=dict(set=True), + long_lived_graceful_restart=dict( + capable=True, + ), + next_hop_self=dict(set=True), + send_community_gshut_ebgp=dict(inheritance_disable=True), + soft_reconfiguration=dict(inbound=dict(always=True)), + send_multicast_attributes=dict(disable=True), + signalling=dict(bgp_disable=True), + remove_private_AS=dict( + inbound=True, + entire_aspath=True, + inheritance_disable=True, + ), + next_hop_unchanged=dict(multipath=True), + advertise=dict(local_labeled_route=dict(set=True)), + update=dict( + out_originator_loopcheck_disable=True, + ), + ), + ], + ), + ], + ), + state="rendered", + ), + ) + commands = [ + "router bgp 1", + "neighbor-group test", + "advertisement-interval 10", + "bfd fast-detect strict-mode", + "internal-vpn-client", + "precedence critical", + "address-family ipv4 unicast", + "advertise local-labeled-route", + "neighbor-group test1", + "advertisement-interval 2", + "bfd fast-detect", + "bfd minimum-interval 3", + "dmz-link-bandwidth", + "description test", + "cluster-id 1", + "ebgp-multihop 255", + "egress-engineering", + "idle-watch-time 30 ", + "internal-vpn-client", + "ignore-connected-check", + "keychain test", + "local-as no-prepend replace-as dual-as", + "password inheritance-disable", + "precedence flash", + "receive-buffer-size 512", + "send-buffer-size 4096", + "session-open-mode both", + "tcp mss inheritance-disable", + "update-source Loopback919", + "ttl-security", + "graceful-maintenance", + "graceful-maintenance as-prepends 0", + "address-family ipv4 unicast", + "advertise local-labeled-route", + "aigp", + "allowas-in 1", + "as-override", + "bestpath origin-as allow invalid", + "capability orf prefix send", + "default-originate", + "long-lived-graceful-restart capable", + "maximum-prefix warning-only", + "multipath", + "next-hop-self", + "next-hop-unchanged multipath", + "origin-as validation disable", + "remove-private-AS inbound entire-aspath inheritance-disable", + "route-reflector-client", + "send-community-ebgp", + "send-community-gshut-ebgp inheritance-disable", + "send-extended-community-ebgp", + "send-multicast-attributes disable", + "soft-reconfiguration inbound always", + "weight 0", + "signalling bgp disable ", + "update out originator-loopcheck disable", + ] + + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(commands)) + + def test_iosxr_bgp_tmpl_replaced(self): + run_cfg = dedent( + """\ + router bgp 1 + neighbor-group test + bfd fast-detect strict-mode + precedence critical + advertisement-interval 10 + internal-vpn-client + address-family ipv4 unicast + advertise local-labeled-route + ! + ! + neighbor-group test1 + bfd fast-detect + bfd minimum-interval 3 + keychain test + ebgp-multihop 255 + egress-engineering + precedence flash + graceful-maintenance + as-prepends 0 + ! + advertisement-interval 2 + tcp mss inheritance-disable + local-as 6 + password inheritance-disable + cluster-id 1 + dmz-link-bandwidth + description test + ttl-security + local address inheritance-disable + update-source Loopback919 + idle-watch-time 30 + ignore-connected-check + session-open-mode both + send-buffer-size 4096 + receive-buffer-size 512 + internal-vpn-client + address-family ipv4 unicast + origin-as validation disable + bestpath origin-as allow invalid + aigp + weight 0 + send-community-ebgp + multipath + route-reflector-client + allowas-in 1 + maximum-prefix 1 75 + as-override + capability orf prefix send + send-extended-community-ebgp + default-originate + long-lived-graceful-restart capable + next-hop-self + send-community-gshut-ebgp inheritance-disable + soft-reconfiguration inbound + send-multicast-attributes disable + Signalling bgp disable + remove-private-AS inbound + update out originator-loopcheck disable + advertise local-labeled-route + next-hop-unchanged inheritance-disable + ! + ! + + """, + ) + set_module_args( + dict( + config=dict( + as_number="1", + neighbor=[ + dict( + name="test", + advertisement_interval=11, + internal_vpn_client=True, + ), + dict( + name="test1", + bfd=dict( + minimum_interval=4, + ), + ebgp_multihop=dict(value=254), + egress_engineering=dict(set=True), + precedence="critical", + graceful_maintenance=dict( + as_prepends=dict( + value="4", + ), + set=True, + ), + advertisement_interval=3, + password=dict(encrypted="test"), + cluster_id=3, + description="test1", + ttl_security=dict(set=True), + local_address_subnet="1.1.1.2/24", + update_source="Loopback912", + idle_watch_time=34, + session_open_mode="active-only", + send_buffer_size=4097, + receive_buffer_size=513, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + weight=2, + multipath=True, + allowas_in=dict(value=2), + maximum_prefix=dict( + max_limit=1, + threshold_value=75, + ), + soft_reconfiguration=dict(inbound=dict(always=True)), + remove_private_AS=dict( + inbound=True, + entire_aspath=True, + inheritance_disable=True, + ), + next_hop_unchanged=dict(multipath=True), + ), + ], + ), + ], + ), + state="replaced", + ), + ) + self.get_config.return_value = run_cfg + + commands = [ + "router bgp 1", + "neighbor-group test", + "no bfd fast-detect strict-mode", + "no precedence critical", + "advertisement-interval 11", + "no address-family ipv4 unicast", + "neighbor-group test1", + "no bfd fast-detect", + "no dmz-link-bandwidth", + "no internal-vpn-client", + "no ignore-connected-check", + "no keychain test", + "no local-as 6", + "no local address inheritance-disable", + "no password inheritance-disable", + "no tcp mss inheritance-disable", + "advertisement-interval 3", + "bfd minimum-interval 4", + "description test1", + "cluster-id 3", + "ebgp-multihop 254", + "idle-watch-time 34 ", + "password encrypted test", + "precedence critical", + "receive-buffer-size 513", + "send-buffer-size 4097", + "session-open-mode active-only", + "update-source Loopback912", + "graceful-maintenance as-prepends 4", + "address-family ipv4 unicast", + "no advertise local-labeled-route", + "no aigp", + "no as-override", + "no bestpath origin-as allow invalid", + "no capability orf prefix send", + "no default-originate", + "no long-lived-graceful-restart capable", + "no next-hop-self", + "no next-hop-unchanged inheritance-disable", + "no origin-as validation disable", + "no route-reflector-client", + "no send-community-ebgp", + "no send-community-gshut-ebgp inheritance-disable", + "no send-extended-community-ebgp", + "no send-multicast-attributes disable", + "no signalling bgp disable ", + "no update out originator-loopcheck disable", + "allowas-in 2", + "next-hop-unchanged multipath", + "remove-private-AS inbound entire-aspath inheritance-disable", + "soft-reconfiguration inbound always", + "weight 2", + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_bgp_tmpl_overridden(self): + run_cfg = dedent( + """\ + router bgp 1 + neighbor-group test + bfd fast-detect strict-mode + precedence critical + advertisement-interval 10 + internal-vpn-client + address-family ipv4 unicast + advertise local-labeled-route + ! + ! + neighbor-group test1 + bfd fast-detect + bfd minimum-interval 3 + keychain test + ebgp-multihop 255 + egress-engineering + precedence flash + graceful-maintenance + as-prepends 0 + ! + advertisement-interval 2 + tcp mss inheritance-disable + local-as 6 + password inheritance-disable + cluster-id 1 + dmz-link-bandwidth + description test + ttl-security + local address inheritance-disable + update-source Loopback919 + idle-watch-time 30 + ignore-connected-check + session-open-mode both + send-buffer-size 4096 + receive-buffer-size 512 + internal-vpn-client + address-family ipv4 unicast + origin-as validation disable + bestpath origin-as allow invalid + aigp + weight 0 + send-community-ebgp + multipath + route-reflector-client + allowas-in 1 + maximum-prefix 1 75 + as-override + capability orf prefix send + send-extended-community-ebgp + default-originate + long-lived-graceful-restart capable + next-hop-self + send-community-gshut-ebgp inheritance-disable + soft-reconfiguration inbound + send-multicast-attributes disable + Signalling bgp disable + remove-private-AS inbound + update out originator-loopcheck disable + advertise local-labeled-route + next-hop-unchanged inheritance-disable + ! + ! + + """, + ) + set_module_args( + dict( + config=dict( + as_number="1", + neighbor=[ + dict( + name="test1", + bfd=dict( + minimum_interval=4, + ), + ebgp_multihop=dict(value=254), + egress_engineering=dict(set=True), + precedence="critical", + graceful_maintenance=dict( + as_prepends=dict( + value="4", + ), + set=True, + ), + advertisement_interval=3, + password=dict(encrypted="test"), + cluster_id=3, + description="test1", + ttl_security=dict(set=True), + local_address_subnet="1.1.1.2/24", + update_source="Loopback912", + idle_watch_time=34, + session_open_mode="active-only", + send_buffer_size=4097, + receive_buffer_size=513, + address_family=[ + dict( + afi="ipv4", + safi="unicast", + weight=2, + multipath=True, + allowas_in=dict(value=2), + maximum_prefix=dict( + max_limit=1, + threshold_value=75, + ), + soft_reconfiguration=dict(inbound=dict(always=True)), + remove_private_AS=dict( + inbound=True, + entire_aspath=True, + inheritance_disable=True, + ), + next_hop_unchanged=dict(multipath=True), + ), + ], + ), + ], + ), + state="overridden", + ), + ) + self.get_config.return_value = run_cfg + commands = [ + "router bgp 1", + "no neighbor-group test", + "neighbor-group test1", + "no bfd fast-detect", + "no dmz-link-bandwidth", + "no internal-vpn-client", + "no ignore-connected-check", + "no keychain test", + "no local-as 6", + "no local address inheritance-disable", + "no password inheritance-disable", + "no tcp mss inheritance-disable", + "advertisement-interval 3", + "bfd minimum-interval 4", + "description test1", + "cluster-id 3", + "ebgp-multihop 254", + "idle-watch-time 34 ", + "password encrypted test", + "precedence critical", + "receive-buffer-size 513", + "send-buffer-size 4097", + "session-open-mode active-only", + "update-source Loopback912", + "graceful-maintenance as-prepends 4", + "address-family ipv4 unicast", + "no advertise local-labeled-route", + "no aigp", + "no as-override", + "no bestpath origin-as allow invalid", + "no capability orf prefix send", + "no default-originate", + "no long-lived-graceful-restart capable", + "no next-hop-self", + "no next-hop-unchanged inheritance-disable", + "no origin-as validation disable", + "no route-reflector-client", + "no send-community-ebgp", + "no send-community-gshut-ebgp inheritance-disable", + "no send-extended-community-ebgp", + "no send-multicast-attributes disable", + "no signalling bgp disable ", + "no update out originator-loopcheck disable", + "allowas-in 2", + "next-hop-unchanged multipath", + "remove-private-AS inbound entire-aspath inheritance-disable", + "soft-reconfiguration inbound always", + "weight 2", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_bgp_tmpl_parsed(self): + self.maxDiff = None + set_module_args( + dict( + running_config="router bgp 1\n neighbor-group ********\n " + "bfd fast-detect strict-mode\n update in filtering\n" + " message buffers 0 non-circular\n logging disable\n" + " !\n precedence critical\n timers 0 3 3\n " + "advertisement-interval 10\n maximum-peers 10\n " + "local-address-subnet 1.1.1.5/24\n internal-vpn-client\n" + " address-family ipv4 unicast\n advertise local-labeled-route\n" + " !\n !\n neighbor-group ********1\n bfd fast-detect\n " + "update in filtering\n !\n bfd minimum-interval 3\n " + "capability additional-paths send disable\n keychain ********\n" + " ebgp-multihop 255\n egress-engineering\n precedence flash\n " + "graceful-maintenance\n as-prepends 0\n !\n advertisement-interval 2\n" + " tcp mss inheritance-disable\n local-as 6\n password inheritance-disable\n" + " shutdown inheritance-disable\n maximum-peers 1\n cluster-id 1\n" + " dmz-link-bandwidth\n description ********\n ttl-security\n " + "ebgp-recv-extcommunity-dmz\n ebgp-send-extcommunity-dmz cumulative\n" + " local address inheritance-disable\n update-source Loopback919\n " + "idle-watch-time 30\n enforce-first-as\n ignore-connected-check\n " + "session-open-mode both\n send-buffer-size 4096\n " + "local-address-subnet 1.1.1.1/24\n receive-buffer-size 512\n" + " internal-vpn-client\n address-family ipv4 unicast\n " + "origin-as validation disable\n bestpath origin-as allow invalid\n" + " weight 0\n aigp send med\n send-community-ebgp\n multipath\n" + " route-reflector-client\n allowas-in 1\n " + "encapsulation-type srv6\n maximum-prefix 1 75\n as-override\n capability orf prefix send\n" + " send-extended-community-ebgp\n default-originate\n long-lived-graceful-restart capable\n" + " next-hop-self\n send-community-gshut-ebgp inheritance-disable\n soft-reconfiguration inbound\n" + " site-of-origin 1.1:1\n send-multicast-attributes disable\n Signalling bgp disable\n " + " remove-private-AS inbound\n update out originator-loopcheck disable\n " + " advertise local-labeled-route\n next-hop-unchanged inheritance-disable\n " + " cluster-id allow-equal disable\n ! \n ! " + "\n neighbor 1.1.1.1\n ! " + "\n!", + state="parsed", + ), + ) + result = self.execute_module(changed=False) + parsed_list = { + "as_number": "1", + "neighbor": [ + { + "name": "********", + "bfd": {"fast_detect": {"strict_mode": True}}, + "update": {"in": {"filtering": {"logging": {"disable": True}}}}, + "precedence": "critical", + "advertisement_interval": 10, + "maximum_peers": 10, + "internal_vpn_client": True, + "address_family": [ + { + "afi": "ipv4", + "safi": "unicast", + "advertise": {"local_labeled_route": {"set": True}}, + }, + ], + }, + { + "name": "********1", + "bfd": {"fast_detect": {"set": True}, "minimum_interval": 3}, + "capability": {"additional_paths": {"send": {"disable": True}}}, + "keychain": {"name": "********"}, + "ebgp_multihop": {"value": 255}, + "egress_engineering": {"set": True}, + "precedence": "flash", + "graceful_maintenance": {"set": True, "as_prepends": {"value": 0}}, + "advertisement_interval": 2, + "tcp": {"mss": {"inheritance_disable": True}}, + "local_as": {"value": 6}, + "password": {"inheritance_disable": True}, + "maximum_peers": 1, + "cluster_id": "1", + "dmz_link_bandwidth": {"set": True}, + "description": "********", + "ttl_security": {"set": True}, + "ebgp_recv_extcommunity_dmz": {"set": True}, + "local": {"address": {"inheritance_disable": True}}, + "update_source": "Loopback919", + "idle_watch_time": 30, + "ignore_connected_check": {"set": True}, + "session_open_mode": "both", + "send_buffer_size": 4096, + "receive_buffer_size": 512, + "internal_vpn_client": True, + "address_family": [ + { + "afi": "ipv4", + "safi": "unicast", + "origin_as": {"validation": {"disable": True}}, + "bestpath_origin_as_allow_invalid": True, + "weight": 0, + "aigp": {"send_med": {"set": True}}, + "send_community_ebgp": {"set": True}, + "multipath": True, + "route_reflector_client": {"set": True}, + "allowas_in": {"value": 1}, + "encapsulation_type_srv6": True, + "maximum_prefix": {"max_limit": 1, "threshold_value": 75}, + "as_override": {"set": True}, + "capability_orf_prefix": "send", + "send_extended_community_ebgp": {"set": True}, + "default_originate": {"set": True}, + "long_lived_graceful_restart": {"capable": True}, + "next_hop_self": {"set": True}, + "send_community_gshut_ebgp": {"inheritance_disable": True}, + "soft_reconfiguration": {"inbound": {"set": True}}, + "send_multicast_attributes": {"disable": True}, + "signalling": {"bgp_disable": True}, + "remove_private_AS": {"inbound": True}, + "update": {"out_originator_loopcheck_disable": True}, + "advertise": {"local_labeled_route": {"set": True}}, + "next_hop_unchanged": {"inheritance_disable": True}, + }, + ], + }, + ], + } + self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_bgp_tmpl_gathered(self): + self.maxDiff = None + run_cfg = dedent( + """\ + router bgp 1 + neighbor-group test + bfd fast-detect strict-mode + precedence critical + advertisement-interval 10 + internal-vpn-client + address-family ipv4 unicast + advertise local-labeled-route + ! + ! + neighbor-group test1 + bfd fast-detect + bfd minimum-interval 3 + keychain test + ebgp-multihop 255 + egress-engineering + precedence flash + graceful-maintenance + as-prepends 0 + ! + advertisement-interval 2 + tcp mss inheritance-disable + local-as 6 + password inheritance-disable + cluster-id 1 + dmz-link-bandwidth + description test + ttl-security + local address inheritance-disable + update-source Loopback919 + idle-watch-time 30 + ignore-connected-check + session-open-mode both + send-buffer-size 4096 + receive-buffer-size 512 + internal-vpn-client + address-family ipv4 unicast + origin-as validation disable + bestpath origin-as allow invalid + aigp + weight 0 + send-community-ebgp + multipath + route-reflector-client + allowas-in 1 + maximum-prefix 1 75 + as-override + capability orf prefix send + send-extended-community-ebgp + default-originate + long-lived-graceful-restart capable + next-hop-self + send-community-gshut-ebgp inheritance-disable + soft-reconfiguration inbound + send-multicast-attributes disable + Signalling bgp disable + remove-private-AS inbound + update out originator-loopcheck disable + advertise local-labeled-route + next-hop-unchanged inheritance-disable + ! + ! + + """, + ) + self.get_config.return_value = run_cfg + set_module_args(dict(state="gathered")) + gathered = { + "as_number": "1", + "neighbor": [ + { + "name": "test", + "bfd": {"fast_detect": {"strict_mode": True}}, + "precedence": "critical", + "advertisement_interval": 10, + "internal_vpn_client": True, + "address_family": [ + { + "afi": "ipv4", + "safi": "unicast", + "advertise": {"local_labeled_route": {"set": True}}, + }, + ], + }, + { + "name": "test1", + "bfd": {"fast_detect": {"set": True}, "minimum_interval": 3}, + "keychain": {"name": "test"}, + "ebgp_multihop": {"value": 255}, + "egress_engineering": {"set": True}, + "precedence": "flash", + "graceful_maintenance": {"set": True, "as_prepends": {"value": 0}}, + "advertisement_interval": 2, + "tcp": {"mss": {"inheritance_disable": True}}, + "local_as": {"value": 6}, + "password": {"inheritance_disable": True}, + "cluster_id": "1", + "dmz_link_bandwidth": {"set": True}, + "description": "test", + "ttl_security": {"set": True}, + "local": {"address": {"inheritance_disable": True}}, + "update_source": "Loopback919", + "idle_watch_time": 30, + "ignore_connected_check": {"set": True}, + "session_open_mode": "both", + "send_buffer_size": 4096, + "receive_buffer_size": 512, + "internal_vpn_client": True, + "address_family": [ + { + "afi": "ipv4", + "safi": "unicast", + "origin_as": {"validation": {"disable": True}}, + "bestpath_origin_as_allow_invalid": True, + "aigp": {"set": True}, + "weight": 0, + "send_community_ebgp": {"set": True}, + "multipath": True, + "route_reflector_client": {"set": True}, + "allowas_in": {"value": 1}, + "maximum_prefix": {"max_limit": 1, "threshold_value": 75}, + "as_override": {"set": True}, + "capability_orf_prefix": "send", + "send_extended_community_ebgp": {"set": True}, + "default_originate": {"set": True}, + "long_lived_graceful_restart": {"capable": True}, + "next_hop_self": {"set": True}, + "send_community_gshut_ebgp": {"inheritance_disable": True}, + "soft_reconfiguration": {"inbound": {"set": True}}, + "send_multicast_attributes": {"disable": True}, + "signalling": {"bgp_disable": True}, + "remove_private_AS": {"inbound": True}, + "update": {"out_originator_loopcheck_disable": True}, + "advertise": {"local_labeled_route": {"set": True}}, + "next_hop_unchanged": {"inheritance_disable": True}, + }, + ], + }, + ], + } + result = self.execute_module(changed=False) + self.assertEqual(gathered, result["gathered"]) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py index feb708769..cd691d6c4 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py @@ -29,7 +29,6 @@ from .iosxr_module import TestIosxrModule, load_fixture class TestIosxrCommandModule(TestIosxrModule): - module = iosxr_command def setUp(self): diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py index bbfdcb3e6..9ac6866af 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py @@ -31,7 +31,6 @@ from .iosxr_module import TestIosxrModule, load_fixture class TestIosxrConfigModule(TestIosxrModule): - module = iosxr_config def setUp(self): @@ -282,6 +281,41 @@ class TestIosxrConfigModule(TestIosxrModule): self.execute_module(changed=True, commands=commands, sort=False) + def test_iosxr_replace_block_src(self): + src = load_fixture("iosxr_config_src.cfg") + set_module_args(dict(replace="block", src=src)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, self.running_config), + ) + commands = [ + "hostname foo", + "interface GigabitEthernet0/0", + "no ip address", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_replace_block_lines(self): + lines = [ + "ip address 1.2.3.4 255.255.255.0", + "description test string", + "shutdown", + ] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, parents=parents, replace="block")) + commands = parents + lines + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = iosxr_config.get_candidate(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="none", + path=parents, + ), + ) + self.execute_module(changed=True, commands=commands, sort=False) + def test_iosxr_config_src_and_lines_fails(self): args = dict(src="foo", lines="foo") set_module_args(args) @@ -302,7 +336,7 @@ class TestIosxrConfigModule(TestIosxrModule): set_module_args(args) self.execute_module(failed=True) - def test_iosxr_config_replace_block_requires_lines(self): + def test_iosxr_config_replace_block_requires_lines_or_src(self): args = dict(replace="block") set_module_args(args) self.execute_module(failed=True) @@ -311,3 +345,17 @@ class TestIosxrConfigModule(TestIosxrModule): args = dict(replace="config") set_module_args(args) self.execute_module(failed=True) + + def test_iosxr_config_updates(self): + src = load_fixture("iosxr_config_src.cfg") + set_module_args(dict(src=src)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, self.running_config), + ) + commands = [ + "hostname foo", + "interface GigabitEthernet0/0", + "no ip address", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["updates"]), sorted(commands)) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py index 7848f798f..da7d597ae 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py @@ -31,7 +31,6 @@ from .iosxr_module import TestIosxrModule, load_fixture class TestIosxrFacts(TestIosxrModule): - module = iosxr_facts def setUp(self): @@ -118,3 +117,17 @@ class TestIosxrFacts(TestIosxrModule): self.assertIn("config", ansible_facts["ansible_net_gather_subset"]) self.assertEqual("iosxr01", ansible_facts["ansible_net_hostname"]) self.assertIn("ansible_net_config", ansible_facts) + + def test_iosxr_facts_cpu_utilization(self): + set_module_args({"gather_subset": "hardware"}) + result = self.execute_module() + ansible_facts = result["ansible_facts"] + cpu_utilization_data = { + "one_minute": 21, + "five_minutes": 13, + "fifteen_minutes": 8, + } + self.assertEqual( + ansible_facts["ansible_net_cpu_utilization"], + cpu_utilization_data, + ) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py index 4b7a0bcdd..bff925c60 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py @@ -68,14 +68,14 @@ class TestIosxrInterfacesModule(TestIosxrModule): self.mock_load_config.stop() self.mock_execute_show_command.stop() - def _prepare(self): + def _prepare(self, interface_conf): def load_from_file(*args, **kwargs): - return load_fixture("iosxr_interface_config.cfg") + return load_fixture(interface_conf) self.execute_show_command.side_effect = load_from_file def test_iosxr_interfaces_merged_idempotent(self): - self._prepare() + self._prepare("iosxr_interface_config.cfg") set_module_args( dict( config=[ @@ -138,7 +138,7 @@ class TestIosxrInterfacesModule(TestIosxrModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_iosxr_interfaces_replaced(self): - self._prepare() + self._prepare("iosxr_interface_config.cfg") set_module_args( dict( config=[ @@ -168,7 +168,7 @@ class TestIosxrInterfacesModule(TestIosxrModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_iosxr_interfaces_deleted(self): - self._prepare() + self._prepare("iosxr_interface_config.cfg") set_module_args(dict(state="deleted")) commands = [ @@ -203,6 +203,13 @@ class TestIosxrInterfacesModule(TestIosxrModule): duplex="full", speed=100, ), + dict( + name="FourHundredGigE0/0/0/2", + description="Configured and Merged by Ansible-Network", + mtu=9216, + enabled=True, + duplex="full", + ), ], state="rendered", ), @@ -220,6 +227,11 @@ class TestIosxrInterfacesModule(TestIosxrModule): "speed 100", "duplex full", "shutdown", + "interface FourHundredGigE0/0/0/2", + "description Configured and Merged by Ansible-Network", + "mtu 9216", + "duplex full", + "no shutdown", ] result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), sorted(commands)) @@ -256,7 +268,7 @@ class TestIosxrInterfacesModule(TestIosxrModule): def test_iosxr_interfaces_overridden(self): self.maxDiff = None - self._prepare() + self._prepare("iosxr_interface_config.cfg") set_module_args( dict( config=[ @@ -286,3 +298,23 @@ class TestIosxrInterfacesModule(TestIosxrModule): result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_interfaces_gathered(self): + self._prepare("iosxr_interface_gathered.cfg") + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gathered = [ + { + "name": "GigabitEthernet0/0/0/5", + "description": "RTI-DSKMPLS-LP201 #G0/0", + "enabled": True, + "mtu": 9216, + }, + { + "name": "GigabitEthernet0/0/0/6", + "description": "RTI-DSKMPLS-LP301 #G0/1", + "enabled": True, + "mtu": 9216, + }, + ] + self.assertEqual(gathered, result["gathered"]) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py index 100538780..f28561777 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py @@ -244,3 +244,82 @@ class TestIosxrL2InterfacesModule(TestIosxrModule): result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + + +class TestIosxrL2InterfacesModule1(TestIosxrModule): + module = iosxr_l2_interfaces + + def setUp(self): + super(TestIosxrL2InterfacesModule1, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.mock_get_os_version = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.l2_interfaces.l2_interfaces.get_os_version", + ) + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = "6.1.3" + self.mock_get_os_version1 = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.l2_interfaces.l2_interfaces.get_os_version", + ) + self.get_os_version1 = self.mock_get_os_version1.start() + self.get_os_version1.return_value = "6.1.3" + self.mock_execute_show_command = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.l2_interfaces.l2_interfaces.L2_InterfacesFacts.get_config", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosxrL2InterfacesModule1, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_get_config.stop() + self.mock_get_os_version.stop() + self.get_os_version1.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def _prepare(self): + def load_from_file(*args, **kwargs): + return load_fixture("iosxr_l2_interface_config.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_iosxr_l2_interfaces_qvlan_parsed(self): + self.get_os_version.return_value = "6.1.3" + self.maxDiff = None + set_module_args( + dict( + running_config="interface Bundle-Ether399.2900\n l2transport\n encapsulation dot1q 2900-2902\n ", + state="parsed", + ), + ) + result = self.execute_module(changed=False) + print(result["parsed"]) + parsed_list = [ + { + "name": "Bundle-Ether399.2900", + "l2transport": True, + "qvlan": [ + "2900-2902", + ], + }, + ] + self.assertEqual(parsed_list, result["parsed"]) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py index 5fab9f7ea..071b16b8f 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py @@ -67,14 +67,14 @@ class TestIosxrL3InterfacesModule(TestIosxrModule): self.mock_load_config.stop() self.mock_execute_show_command.stop() - def _prepare(self): + def _prepare(self, l3_interface_config): def load_from_file(*args, **kwargs): - return load_fixture("iosxr_l3_interface_config.cfg") + return load_fixture(l3_interface_config) self.execute_show_command.side_effect = load_from_file def test_iosxr_l3_interfaces_merged_idempotent(self): - self._prepare() + self._prepare("iosxr_l3_interface_config.cfg") set_module_args( dict( config=[ @@ -128,7 +128,7 @@ class TestIosxrL3InterfacesModule(TestIosxrModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_iosxr_l3_interfaces_replaced(self): - self._prepare() + self._prepare("iosxr_l3_interface_config.cfg") set_module_args( dict( config=[ @@ -153,7 +153,7 @@ class TestIosxrL3InterfacesModule(TestIosxrModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_iosxr_l3_interfaces_deleted(self): - self._prepare() + self._prepare("iosxr_l3_interface_config.cfg") set_module_args(dict(state="deleted")) commands = [ @@ -213,14 +213,14 @@ class TestIosxrL3InterfacesModule(TestIosxrModule): parsed_list = [ { "name": "GigabitEthernet0/0/0/0", - "ipv4": [{"address": "198.51.100.1 255.255.255.0"}], + "ipv4": [{"address": "198.51.100.1/24"}], "ipv6": [{"address": "2001:db8::/32"}], }, { "name": "GigabitEthernet0/0/0/1", "ipv4": [ - {"address": "192.0.2.1 255.255.255.0"}, - {"address": "192.0.2.2 255.255.255.0", "secondary": True}, + {"address": "192.0.2.1/24"}, + {"address": "192.0.2.2/24", "secondary": True}, ], }, ] @@ -228,7 +228,7 @@ class TestIosxrL3InterfacesModule(TestIosxrModule): def test_iosxr_l3_interfaces_overridden(self): self.maxDiff = None - self._prepare() + self._prepare("iosxr_l3_interface_config.cfg") set_module_args( dict( config=[ @@ -253,3 +253,13 @@ class TestIosxrL3InterfacesModule(TestIosxrModule): result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_3_interfaces_gathered(self): + self._prepare("iosxr_interface_gathered.cfg") + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gathered = [ + {"name": "GigabitEthernet0/0/0/5", "ipv4": [{"address": "10.255.2.9/30"}]}, + {"name": "GigabitEthernet0/0/0/6", "ipv4": [{"address": "10.255.2.17/30"}]}, + ] + self.assertEqual(gathered, result["gathered"]) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lacp.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lacp.py index e4c9c467e..23c4b8cd9 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lacp.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lacp.py @@ -91,3 +91,87 @@ class TestIosxrLacpModule(TestIosxrModule): ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_lacp_merged_idempotent(self): + self._prepare() + set_module_args( + dict( + config=dict( + system=dict( + priority=12, + mac=dict(address="00c1.4c00.bd15"), + ), + ), + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_lacp_replaced(self): + self._prepare() + set_module_args( + dict( + config=dict( + system=dict( + priority=11, + mac=dict(address="00c1.4c00.bd12"), + ), + ), + state="replaced", + ), + ) + commands = [ + "lacp system mac 00c1.4c00.bd12", + "lacp system priority 11", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_lacp_overridden(self): + self._prepare() + set_module_args( + dict( + config=dict( + system=dict( + priority=11, + mac=dict(address="00c1.4c00.bd12"), + ), + ), + state="overridden", + ), + ) + commands = [ + "lacp system mac 00c1.4c00.bd12", + "lacp system priority 11", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_lacp_deleted(self): + self._prepare() + set_module_args(dict(state="deleted")) + commands = [ + "no lacp system mac", + "no lacp system priority", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_lacp_rendered(self): + set_module_args( + dict( + config=dict( + system=dict( + priority=11, + mac=dict(address="00c1.4c00.bd12"), + ), + ), + state="rendered", + ), + ) + commands = [ + "lacp system mac 00c1.4c00.bd12", + "lacp system priority 11", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(commands)) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py index 65f749ec8..4830058df 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py @@ -204,3 +204,27 @@ class TestIosxrLldpModule(TestIosxrModule): "tlv_select": {"system_description": False}, } self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_lldp_global_overridden(self): + self._prepare() + set_module_args( + dict( + config=dict( + holdtime=100, + tlv_select=dict( + management_address=False, + system_description=False, + port_description=False, + ), + ), + state="overridden", + ), + ) + commands = [ + "no lldp reinit 2", + "no lldp subinterfaces enable", + "no lldp timer 3000", + "lldp tlv-select port-description disable", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py index bbd61050a..727752948 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py @@ -29,7 +29,6 @@ from .iosxr_module import TestIosxrModule class TestIosxrNetconfModule(TestIosxrModule): - module = iosxr_netconf def setUp(self): diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py index 8c9769445..5b967be00 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py @@ -43,11 +43,6 @@ class TestIosxrOspf_InterfacesModule(TestIosxrModule): ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.ospf_interfaces.ospf_interfaces." "Ospf_interfacesFacts.get_ospf_interfaces", @@ -58,7 +53,6 @@ class TestIosxrOspf_InterfacesModule(TestIosxrModule): super(TestIosxrOspf_InterfacesModule, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() self.mock_get_config.stop() self.mock_load_config.stop() self.mock_execute_show_command.stop() diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py index 6d00a8250..b51727dbd 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py @@ -43,11 +43,6 @@ class TestIosxrOspfV2Module(TestIosxrModule): ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.ospfv2.ospfv2." "Ospfv2Facts.get_ospfv2_data", @@ -58,7 +53,6 @@ class TestIosxrOspfV2Module(TestIosxrModule): super(TestIosxrOspfV2Module, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() self.mock_get_config.stop() self.mock_load_config.stop() self.mock_execute_show_command.stop() diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py index 1b8e491fd..23c9d071b 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py @@ -43,11 +43,6 @@ class TestIosxrOspfV3Module(TestIosxrModule): ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.ospfv3.ospfv3." "Ospfv3Facts.get_ospfv3_data", @@ -58,7 +53,6 @@ class TestIosxrOspfV3Module(TestIosxrModule): super(TestIosxrOspfV3Module, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() self.mock_get_config.stop() self.mock_load_config.stop() self.mock_execute_show_command.stop() @@ -180,10 +174,7 @@ class TestIosxrOspfV3Module(TestIosxrModule): ) commands = [ - "router ospfv3 30", - "no cost 2", - "no default-metric 10", - "no area 11 default-cost 5", + "no router ospfv3 30", "router ospfv3 40", "cost 2", "default-metric 10", @@ -218,10 +209,7 @@ class TestIosxrOspfV3Module(TestIosxrModule): ), ) commands = [ - "router ospfv3 30", - "no cost 2", - "no default-metric 10", - "no area 11 default-cost 5", + "no router ospfv3 30", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py index ba91d7f3d..a185b0c4f 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py @@ -378,3 +378,37 @@ class TestIosxrStaticRoutesModule(TestIosxrModule): }, ] self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_static_routes_delete_specific_static_route(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv6", + safi="unicast", + routes=[ + dict( + dest="2001:db8:1000::/36", + next_hops=[ + dict( + interface="FastEthernet0/0/0/7", + description="DC", + ), + ], + ), + ], + ), + ], + ), + ], + state="deleted", + ), + ) + commands = [ + "router static", + "address-family ipv6 unicast", + "no 2001:db8:1000::/36 FastEthernet0/0/0/7", + ] + self.execute_module(changed=True, commands=commands) diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py index 4e09671e4..253725979 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py @@ -29,7 +29,6 @@ from .iosxr_module import TestIosxrModule, load_fixture class TestIosxrSystemModule(TestIosxrModule): - module = iosxr_system def setUp(self): diff --git a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py index 3bb6f5042..0d783d4cd 100644 --- a/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py +++ b/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py @@ -29,7 +29,6 @@ from .iosxr_module import TestIosxrModule, load_fixture class TestIosxrUserModule(TestIosxrModule): - module = iosxr_user def setUp(self): |