From 0a2659d09bcb7ed07134972ef336ca08e22b3307 Mon Sep 17 00:00:00 2001 From: mr-csce Date: Wed, 22 May 2024 14:41:10 +0900 Subject: [PATCH] [route_maps] Enable handling of route-maps without set/match (#856) * Enable handling of route-maps without set/match This commit introduces the ability to handle simple route-maps that do not contain set or match statements. Specifically, it allows for the creation and management of purely basic route-map entries like 'route-map test-1 permit 10'. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add changelogs * Fix ansible-lint error --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nilashish Chakraborty --- changelogs/fragments/route_maps.yaml | 4 + .../nxos/config/route_maps/route_maps.py | 1 + .../network/nxos/test_nxos_route_maps.py | 89 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 changelogs/fragments/route_maps.yaml diff --git a/changelogs/fragments/route_maps.yaml b/changelogs/fragments/route_maps.yaml new file mode 100644 index 000000000..b02073095 --- /dev/null +++ b/changelogs/fragments/route_maps.yaml @@ -0,0 +1,4 @@ +--- +minor_changes: + - "route_maps - support simple route-maps that do not contain set or match statements. + it allows for the creation and management of purely basic route-map entries like 'route-map test-1 permit 10'." diff --git a/plugins/module_utils/network/nxos/config/route_maps/route_maps.py b/plugins/module_utils/network/nxos/config/route_maps/route_maps.py index fa7d57b1b..77f8f02be 100644 --- a/plugins/module_utils/network/nxos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/nxos/config/route_maps/route_maps.py @@ -47,6 +47,7 @@ def __init__(self, module): tmplt=Route_mapsTemplate(), ) self.linear_parsers = [ + "route_map", "description", "continue_sequence", "set.as_path.prepend.last_as", diff --git a/tests/unit/modules/network/nxos/test_nxos_route_maps.py b/tests/unit/modules/network/nxos/test_nxos_route_maps.py index d247c02b4..45a64775e 100644 --- a/tests/unit/modules/network/nxos/test_nxos_route_maps.py +++ b/tests/unit/modules/network/nxos/test_nxos_route_maps.py @@ -1493,3 +1493,92 @@ def test_nxos_route_maps_extcomm_rt(self): ] result = self.execute_module(changed=True) self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_route_maps_without_match_and_set_merged(self): + self.get_config.return_value = dedent( + """\ + route-map test-1 permit 10 + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="test-1", + entries=[ + dict( + action="permit", + sequence=20, + ), + ], + ), + ], + state="merged", + ), + ) + commands = [ + "route-map test-1 permit 20", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_route_maps_without_match_and_set_overridden(self): + self.get_config.return_value = dedent( + """\ + route-map test-1 permit 10 + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="test-2", + entries=[ + dict( + action="permit", + sequence=10, + ), + ], + ), + ], + state="overridden", + ), + ) + commands = [ + "no route-map test-1 permit 10", + "route-map test-2 permit 10", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands)) + + def test_nxos_route_maps_without_match_and_set_replaced(self): + self.get_config.return_value = dedent( + """\ + route-map test-1 permit 10 + route-map test-1 permit 20 + route-map test-2 permit 10 + """, + ) + set_module_args( + dict( + config=[ + dict( + route_map="test-1", + entries=[ + dict( + action="permit", + sequence=30, + ), + ], + ), + ], + state="replaced", + ), + ) + commands = [ + "no route-map test-1 permit 10", + "no route-map test-1 permit 20", + "route-map test-1 permit 30", + ] + result = self.execute_module(changed=True) + self.assertEqual(set(result["commands"]), set(commands))