Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: route-maps ACL removal in replaced state #1138

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions changelogs/fragments/route_maps_acl_fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "ios_route_maps - Fix removal of ACLs in replaced state to properly remove unspecified ACLs while leaving specified ones intact."
36 changes: 27 additions & 9 deletions plugins/module_utils/network/ios/config/route_maps/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,34 @@ def list_type_compare(self, compare_type, want, have):
if val != have_val:
if have_val:
if self.state == "overridden" or self.state == "replaced":
self.compare(
parsers=parsers,
want=dict(),
have={compare_type: {k: {key: have_val}}},
list_type = next(iter(val))
# Get sets of values for comparison
want_values = set(str(v) for v in val[list_type].values())
have_values = (
set(str(v) for v in have_val[list_type].values())
if have_val
else set()
)
self.compare(
parsers=parsers,
want={compare_type: {k: {key: val}}},
have={compare_type: {k: {key: have_val}}},
)
# Find values that need to be removed (in have but not in want)
to_remove = have_values - want_values
# Find values that need to be added (in want but not in have)
to_add = want_values - have_values
# Handle removals first
if to_remove:
diff = {f"acl_{v}": v for v in to_remove}
self.compare(
parsers=parsers,
want=dict(),
have={compare_type: {k: {key: {list_type: diff}}}},
)
# Then handle additions
if to_add:
diff = {f"acl_{v}": v for v in to_add}
self.compare(
parsers=parsers,
want={compare_type: {k: {key: {list_type: diff}}}},
have=dict(),
)
else:
self.compare(
parsers=parsers,
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/modules/network/ios/test_ios_route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_ios_route_maps_replaced(self):
exact_match=True,
name=["new_replace"],
),
ip=dict(address=dict(acls=[10, 100])),
ip=dict(address=dict(acls=[10, 20, 30])),
length=dict(maximum=50000, minimum=5000),
mpls_label=True,
policy_lists=["ip_policy"],
Expand Down Expand Up @@ -332,7 +332,9 @@ def test_ios_route_maps_replaced(self):
"continue 20",
"description this is replace test",
"match community new_replace exact-match",
"match ip address 20 30",
"match length 5000 50000",
"no match ip address 100",
"no match mdt-group 25 30",
"no match community 98 99 test_1 test_2 exact-match",
"no match extcommunity 110 130",
Expand Down