diff --git a/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py b/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py index 10d82e83..b1512c25 100644 --- a/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py @@ -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", diff --git a/plugins/module_utils/network/iosxr/rm_templates/route_maps.py b/plugins/module_utils/network/iosxr/rm_templates/route_maps.py index f7c4bef6..a9d45e59 100644 --- a/plugins/module_utils/network/iosxr/rm_templates/route_maps.py +++ b/plugins/module_utils/network/iosxr/rm_templates/route_maps.py @@ -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[\*\+\-]?\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.+)) + $""", 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( diff --git a/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py b/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py index de9051ac..78249835 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py @@ -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) \ No newline at end of file