Skip to content

Commit

Permalink
multiple local-preference supported now and also added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AAYUSH2091 committed Oct 28, 2024
1 parent fbdde44 commit 29bd8ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ class Route_mapsArgs(object): # pylint: disable=R0903
},
},
"local_preference": {
"type": "str",
},
"type": "list",
"elements":"str"
},
"attribute_set": {"type": "str"},
"c_multicast_routing": {
"type": "dict",
Expand Down
28 changes: 15 additions & 13 deletions plugins/module_utils/network/iosxr/rm_templates/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,24 @@ def __init__(self, lines=None, module=None):
},
},
{
"name": "set.local_preference",
"getval": re.compile(
r"""
\s*set\s+local[-]?preference
\s+(?P<local_preference>[\*\+\-]?\d+) # Capture value with optional *, +, or - prefix
\s*$""",re.VERBOSE,
),
"setval": "set local-preference {{ local_preference }}",
"result": {
"name": "set.local_preference",
"getval": re.compile(
r"""
\s*set\slocal-preference
(\s(?P<local_preference>.+))
$""", re.VERBOSE,
),
"setval": "set local-preference {{ set.local_preference }}",
"result": {
"policies": {
"set": {
"local_preference": "{{ local_preference }}",
},
},
"local_preference": [
"{{ local_preference }}"
]
}
}
}
},
},
{
"name": "set.aigp_metric",
"getval": re.compile(
Expand Down
54 changes: 32 additions & 22 deletions tests/unit/modules/network/iosxr/test_iosxr_route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,26 +1278,36 @@ def test_iosxr_route_maps_parsed(self):
self.assertEqual(parsed_list, result["parsed"])



def test_aayush_iosxr_route_maps_parsed(self):
set_module_args(
dict(
running_config=dedent(
"""\
route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX
set ospf-metric 232
set local-preference 100
prepend as-path most-recent 22
""",
),
state="parsed",
def test_iosxr_route_maps_parsed_local_pref_variants(self):
set_module_args(
dict(
running_config=dedent(
"""\
route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX
set ospf-metric 232
set local-preference +100
set local-preference -100
set local-preference *700
set local-preference -800
set local-preference +600
""",
),
)
result = self.execute_module(changed=False)
parsed_list = [
{
"name": "APPLY_TEST_ROUTE_POLICY_COMPLEX",
"global": {"set": {"ospf_metric": 232,"local_preference":"100"}},
},
]
self.assertEqual(parsed_list, result["parsed"])
state="parsed",
),
)
result = self.execute_module(changed=False)
parsed_list = [
{
"name": "APPLY_TEST_ROUTE_POLICY_COMPLEX",
"global": {
"set": {
"ospf_metric":232,
"local_preference": ["+100","-100","*700","-800","+600"],
},
}
}
]
res=sorted(result["parsed"][0]["global"]["set"].pop("local_preference"))
parsd_lst=sorted(parsed_list[0]["global"]["set"].pop("local_preference"))

self.assertEqual(parsd_lst, res)

0 comments on commit 29bd8ed

Please sign in to comment.