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

[route_maps] Enable handling of route-maps without set/match #856

Conversation

Miyoshi-Ryota
Copy link
Contributor

@Miyoshi-Ryota Miyoshi-Ryota commented May 2, 2024

SUMMARY

This commit introduces the ability to handle 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'.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

cisco.nxos.nxos_route_maps

ADDITIONAL INFORMATION

cisco.nxos.nxos_route_maps module cannot handle following task which does not have a set, a match and a description section for now.

See also unit tests.

- name: Sample Task
  cisco.nxos.nxos_route_maps:
    config:
      - route_map: rmap1
        entries:
          - sequence: 10
            action: permit
    state: merged
pytest result after editing source code.
% pytest tests/unit/modules/network/nxos/test_nxos_route_maps.py 
========================================================== test session starts ==========================================================
platform darwin -- Python 3.10.14, pytest-8.1.1, pluggy-1.4.0
ansible: 2.16.5
rootdir: /Users/me/Documents/programming/PycharmProjects/cisco.nxos
configfile: pyproject.toml
plugins: ansible-24.1.2, xdist-3.5.0
collected 21 items                                                                                                                      

tests/unit/modules/network/nxos/test_nxos_route_maps.py .....................                                                     [100%]

========================================================== 21 passed in 0.82s ===========================================================
pytest result when just adding tests and without editing source code.
% pytest tests/unit/modules/network/nxos/test_nxos_route_maps.py
========================================================== test session starts ==========================================================
platform darwin -- Python 3.10.14, pytest-8.1.1, pluggy-1.4.0
ansible: 2.16.5
rootdir: /Users/me/Documents/programming/PycharmProjects/cisco.nxos
configfile: pyproject.toml
plugins: ansible-24.1.2, xdist-3.5.0
collected 21 items                                                                                                                      

tests/unit/modules/network/nxos/test_nxos_route_maps.py ..................FFF                                                     [100%]

=============================================================== FAILURES ================================================================
_______________________________ TestNxosRouteMapsModule.test_nxos_route_maps_without_match_and_set_merged _______________________________

self = <tests.unit.modules.network.nxos.test_nxos_route_maps.TestNxosRouteMapsModule testMethod=test_nxos_route_maps_without_match_and_set_merged>

    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)

tests/unit/modules/network/nxos/test_nxos_route_maps.py:1522: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/unit/modules/network/nxos/nxos_module.py:98: in execute_module
    result = self.changed(changed)
tests/unit/modules/network/nxos/nxos_module.py:124: in changed
    self.assertEqual(result["changed"], changed, result)
E   AssertionError: False != True : {'warnings': [], 'commands': [], 'before': [{'route_map': 'test-1', 'entries': [{'sequence': 10, 'action': 'permit'}]}], 'changed': False}
_____________________________ TestNxosRouteMapsModule.test_nxos_route_maps_without_match_and_set_overridden _____________________________

self = <tests.unit.modules.network.nxos.test_nxos_route_maps.TestNxosRouteMapsModule testMethod=test_nxos_route_maps_without_match_and_set_overridden>

    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))
E       AssertionError: Items in the second set but not the first:
E       'route-map test-2 permit 10'

tests/unit/modules/network/nxos/test_nxos_route_maps.py:1552: AssertionError
______________________________ TestNxosRouteMapsModule.test_nxos_route_maps_without_match_and_set_replaced ______________________________

self = <tests.unit.modules.network.nxos.test_nxos_route_maps.TestNxosRouteMapsModule testMethod=test_nxos_route_maps_without_match_and_set_replaced>

    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))
E       AssertionError: Items in the second set but not the first:
E       'route-map test-1 permit 30'

tests/unit/modules/network/nxos/test_nxos_route_maps.py:1584: AssertionError
======================================================== short test summary info ========================================================
FAILED tests/unit/modules/network/nxos/test_nxos_route_maps.py::TestNxosRouteMapsModule::test_nxos_route_maps_without_match_and_set_merged - AssertionError: False != True : {'warnings': [], 'commands': [], 'before': [{'route_map': 'test-1', 'entries': [{'sequence': 10, 'ac...
FAILED tests/unit/modules/network/nxos/test_nxos_route_maps.py::TestNxosRouteMapsModule::test_nxos_route_maps_without_match_and_set_overridden - AssertionError: Items in the second set but not the first:
FAILED tests/unit/modules/network/nxos/test_nxos_route_maps.py::TestNxosRouteMapsModule::test_nxos_route_maps_without_match_and_set_replaced - AssertionError: Items in the second set but not the first:
===================================================== 3 failed, 18 passed in 0.86s ======================================================

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'.
@Miyoshi-Ryota Miyoshi-Ryota changed the title Enable handling of route-maps without set/match [route_maps] Enable handling of route-maps without set/match May 2, 2024
@Miyoshi-Ryota
Copy link
Contributor Author

Miyoshi-Ryota commented May 2, 2024

Please let me know if I need to do additional work for the review. CI is failing, but I think I cannot add safe to test label by me.

@Miyoshi-Ryota
Copy link
Contributor Author

Miyoshi-Ryota commented May 8, 2024

Thank you for adding the label. I will fix the ansible-lint error soon.

If I update this PR, the label may come off again. If that's the case, I'm sorry for bothering you twice.

@NilashishC
Copy link
Collaborator

@Miyoshi-Ryota this is an excellent PR! Thank you so much.

@NilashishC NilashishC merged commit 0a2659d into ansible-collections:main May 22, 2024
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants