Skip to content

Commit

Permalink
fix state overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-perByte committed Oct 4, 2024
1 parent 9f194e2 commit 6f1114f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
17 changes: 11 additions & 6 deletions plugins/module_utils/network/iosxr/config/route_maps/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def generate_commands(self):
else: # for all other states
self._compare(want=want, have=haved.pop(k, {}), policy_name=k)

# clean anything that is surplus
if self.state == "overridden":
for h, haved in iteritems(haved):
self._handle_purged(h)

def _handle_purged(self, policy_name):
self.commands.append(f"no route-policy {policy_name}")

Expand Down Expand Up @@ -220,17 +225,17 @@ def process_apply(apply_conf):
if cond == "global":
temp_rmap[cond] = rm_conf
else:
temp_rmap[cond + "_" + (rm_conf.get("condition").replace(" ", "_"))] = (
rm_conf
)
temp_rmap[
cond + "_" + (rm_conf.get("condition").replace(" ", "_"))
] = rm_conf
elif cond == "elseif":
for elif_config in rm_conf:
if elif_config.get("apply"):
elif_config["apply"] = process_apply(elif_config.get("apply"))
elif_config["conf_type"] = cond
temp_rmap[cond + "_" + (elif_config.get("condition").replace(" ", "_"))] = (
elif_config
)
temp_rmap[
cond + "_" + (elif_config.get("condition").replace(" ", "_"))
] = elif_config
elif (
cond == "else"
): # wanted to do recursion but the overall performance is better this way
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/modules/network/iosxr/test_iosxr_route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_iosxr_route_maps_merged_simple(self):
),
)
result = self.execute_module(changed=True)
print(result["commands"])

commands = [
"route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE",
"if destination in ILOVEROUTEPOLICY then",
Expand Down Expand Up @@ -379,7 +379,6 @@ def test_iosxr_route_maps_merged_complex(self):
),
)
result = self.execute_module(changed=True)
print(result["commands"])

commands = [
"route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX",
Expand Down Expand Up @@ -576,7 +575,6 @@ def test_iosxr_route_maps_overridden(self):
),
)
result = self.execute_module(changed=True)
print(result["commands"])

commands = [
"route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX",
Expand Down Expand Up @@ -622,6 +620,7 @@ def test_iosxr_route_maps_overridden(self):
"set community (24680:1) additive",
"endif",
"end-policy",
"no route-policy TEST_ROUTE_POLICY_COMPLEX",
]
self.assertEqual(sorted(result["commands"]), sorted(commands))

Expand Down Expand Up @@ -773,7 +772,6 @@ def test_iosxr_route_maps_replaced(self):
),
)
result = self.execute_module(changed=True)
print(result["commands"])

commands = [
"route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX",
Expand Down Expand Up @@ -1119,7 +1117,6 @@ def test_iosxr_route_maps_purged(self):
),
)
result = self.execute_module(changed=True)
print(result["commands"])

commands = [
"no route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX",
Expand Down

0 comments on commit 6f1114f

Please sign in to comment.