From 970e2f52ff0c387f73d93e8a283fef1b9f402cce Mon Sep 17 00:00:00 2001 From: Tim Weippert Date: Fri, 6 Sep 2024 07:04:34 +0000 Subject: [PATCH 1/4] static_routes - Ensure idempotency with encapsulated interfaces (e.g. TenGigE0/0/0/23.1234) --- .../fragments/static_route_encap_intf.yaml | 3 ++ .../facts/static_routes/static_routes.py | 1 + .../fixtures/iosxr_static_routes_config.cfg | 1 + .../network/iosxr/test_iosxr_static_routes.py | 29 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 changelogs/fragments/static_route_encap_intf.yaml diff --git a/changelogs/fragments/static_route_encap_intf.yaml b/changelogs/fragments/static_route_encap_intf.yaml new file mode 100644 index 000000000..bd2009856 --- /dev/null +++ b/changelogs/fragments/static_route_encap_intf.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fixes idempotency for static routes with encap interfaces diff --git a/plugins/module_utils/network/iosxr/facts/static_routes/static_routes.py b/plugins/module_utils/network/iosxr/facts/static_routes/static_routes.py index e6e37482e..d83aa9ee7 100644 --- a/plugins/module_utils/network/iosxr/facts/static_routes/static_routes.py +++ b/plugins/module_utils/network/iosxr/facts/static_routes/static_routes.py @@ -154,6 +154,7 @@ def parse_faddr(self, item): def parse_intf(self, item): inf_search_strs = [ + r" ((\w+)((?:\d)/(?:\d)/(?:\d)/(?:\d+))\.(?:\d+))", r" ((\w+)((?:\d)/(?:\d)/(?:\d)/(?:\d+)))", r" (([a-zA-Z]+)(?:\d+))", ] diff --git a/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg b/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg index 359483363..bc7a2c655 100644 --- a/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg +++ b/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg @@ -4,6 +4,7 @@ router static 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1 192.0.2.32/28 192.0.2.11 100 + 192.0.2.48/28 TenGigE0/0/0/23.2500 192.0.2.10 ! address-family ipv6 unicast 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC diff --git a/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py b/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py index 4cce2eb6e..73ef88851 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py @@ -262,6 +262,35 @@ def test_iosxr_static_routes_replaced_idempotent(self): ) self.execute_module(changed=False, commands=[]) + def test_iosxr_static_routes_replaced_idempotent_encap_intf(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.0.2.48/28", + next_hops=[ + dict( + interface="TenGigE0/0/0/23.2500", + forward_router_address="192.0.2.10", + ), + ], + ), + ], + ), + ], + ), + ], + state="replaced", + ), + ) + self.execute_module(changed=False, commands=[]) + def test_iosxr_static_routes_overridden(self): set_module_args( dict( From 95221e8f7fd929ab60d19a3c2ef5140555201997 Mon Sep 17 00:00:00 2001 From: Tim Weippert Date: Mon, 2 Dec 2024 10:44:59 +0000 Subject: [PATCH 2/4] Adding integration test for merged action --- .../targets/iosxr_static_routes/tests/cli/merged.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml b/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml index c848e7c2b..434f62e4e 100644 --- a/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml +++ b/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml @@ -28,6 +28,11 @@ next_hops: - forward_router_address: 192.0.2.11 admin_distance: 100 + + - dest: 192.0.2.48/28 + next_hops: + - forward_outer_address: 192.0.2.10 + interface: TenGigE0/0/0/23.2500 - afi: ipv6 safi: unicast From 6b9db6c0b34747707f92f6ec93af15e2cfbb6fdb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:46:43 +0000 Subject: [PATCH 3/4] chore: auto fixes from pre-commit.com hooks --- .../targets/iosxr_static_routes/tests/cli/merged.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml b/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml index 434f62e4e..b4a0d5bb9 100644 --- a/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml +++ b/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml @@ -28,7 +28,7 @@ next_hops: - forward_router_address: 192.0.2.11 admin_distance: 100 - + - dest: 192.0.2.48/28 next_hops: - forward_outer_address: 192.0.2.10 From 9f3e017e0010c96100a780cde1214199c2e4f191 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:54:56 +0000 Subject: [PATCH 4/4] chore: auto fixes from pre-commit.com hooks --- .../targets/iosxr_static_routes/tests/cli/merged.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml b/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml index ce3a74a60..79549aa81 100644 --- a/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml +++ b/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml @@ -33,7 +33,7 @@ next_hops: - forward_outer_address: 192.0.2.10 interface: TenGigE0/0/0/23.2500 - + - dest: 192.168.17.0/24 next_hops: - interface: Loopback0