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

feat(anta): Added testcase to verify the BGP Redistributed Routes #993

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

geetanjalimanegslab
Copy link
Collaborator

@geetanjalimanegslab geetanjalimanegslab commented Jan 7, 2025

Description

Added testcase to verify the BGP Redistributed Routes

  This test performs the following checks for each specified route:

  1. Ensures that the expected address-family is configured on the device.
  2. Confirms that the redistributed route protocol and route map match the expected values for a route.
     
 Expected Results
----------------
* Success: If all of the following conditions are met:
    - The expected address-family is configured on the device.
    - The redistributed route protocol and route map align with the expected values for the route.
* Failure: If any of the following occur:
    - The expected address-family is not configured on device.
    - The redistributed route protocol or route map does not match the expected value for a route.

Fixes #1009

Note - Added pylint disable for number of line check (C0302) with TODO.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

@geetanjalimanegslab geetanjalimanegslab changed the title Added testcase to verify the BGP Redistributed Routes feat(anta):Added testcase to verify the BGP Redistributed Routes Jan 7, 2025
@geetanjalimanegslab geetanjalimanegslab changed the title feat(anta):Added testcase to verify the BGP Redistributed Routes feat(anta): Added testcase to verify the BGP Redistributed Routes Jan 7, 2025
Copy link

codspeed-hq bot commented Jan 7, 2025

CodSpeed Performance Report

Merging #993 will not alter performance

Comparing geetanjalimanegslab:test_bgp_redistributed_routes (b4e2ba6) with main (164b736)

Summary

✅ 22 untouched benchmarks

anta/custom_types.py Outdated Show resolved Hide resolved
"""
Can be enabled in the `VerifyBGPPeerCount` tests."""
redistributed_route_protocol: Redistributed_Protocol | None = None
"""Specify redistributed route protocol."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Specify redistributed route protocol."""
"""Specify redistributed route protocol. Required field in the `VerifyBGPRedistributedRoutes` test."""

Also add validator in test case.

anta/input_models/routing/bgp.py Outdated Show resolved Hide resolved
anta/input_models/routing/bgp.py Show resolved Hide resolved
anta/tests/routing/bgp.py Outdated Show resolved Hide resolved
anta/tests/routing/bgp.py Outdated Show resolved Hide resolved
anta/tests/routing/bgp.py Outdated Show resolved Hide resolved
@vitthalmagadum vitthalmagadum marked this pull request as ready for review January 14, 2025 08:55
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@geetanjalimanegslab geetanjalimanegslab force-pushed the test_bgp_redistributed_routes branch from 16ed8ec to 145dae6 Compare January 15, 2025 07:15
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link
Contributor

@carl-baillargeon carl-baillargeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the test with the suggested input models.

@@ -263,3 +263,4 @@ def validate_regex(value: str) -> str:
SnmpHashingAlgorithm = Literal["MD5", "SHA", "SHA-224", "SHA-256", "SHA-384", "SHA-512"]
SnmpEncryptionAlgorithm = Literal["AES-128", "AES-192", "AES-256", "DES"]
DynamicVlanSource = Literal["dmf", "dot1x", "dynvtep", "evpn", "mlag", "mlagsync", "mvpn", "swfwd", "vccbfd"]
RedistributedProtocol = Literal["AttachedHost", "Bgp", "Connected", "Dynamic", "IS-IS", "OSPF Internal", "OSPFv3 Internal", "RIP", "Static", "User"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add OSPF External, OSPF Nssa-External, same for OSPFv3. We can also redistribute specific IS-IS levels; level-1, level-2, level-1-2 so please double check the options.

@@ -1685,3 +1688,89 @@ def test(self) -> None:

if (actual_origin := get_value(route_path, "routeType.origin")) != origin:
self.result.is_failure(f"{route} {path} - Origin mismatch - Actual: {actual_origin}")


class VerifyBGPRedistributedRoutes(AntaTest):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this test VerifyBGPRedistribution instead since we are not checking anything related to redistributed routes.

Comment on lines 75 to 79
Can be enabled in the `VerifyBGPPeerCount` tests."""
redistributed_route_protocol: RedistributedProtocol | None = None
"""Specify redistributed route protocol. Required field in the `VerifyBGPRedistributedRoutes` test."""
route_map: str | None = None
"""Specify redistributed route protocol route map. Required field in the `VerifyBGPRedistributedRoutes` test."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use separate models for the show bgp instance related tests. Something like this:

class RedistributedRoute(BaseModel):
    proto: RedistributedProtocol  # Custom type that you already created
    include_leaked: bool | None = None  # We should also check this for protocols that it applies
    route_map: str | None = None  # This is optional, we can redistribute without a route-map
class AfiSafiConfig(BaseModel):
    name: Literal["v4u", "v4m"]  # Here we should also support other formats like `IPv4 Unicast` or `ipv4Unicast`
    redistributed_routes: list[RedistributedRoute]
class BgpVrf(BaseModel):
    name: str = "default"
    address_families: list[AfiSafiConfig]
    # With this structure we can easily add more fields in the future for other tests.
    # router_id: str
    # local_as: int

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually AddressFamilyConfig might be more appropriate versus AfiSafiConfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @carl-baillargeon.
Thank you for providing the input model. I've implemented the test case based on that. Here's the current input model:

- VerifyBGPRedistribution:
    vrfs:
       - vrf: default
          address_families:
            - afi_safi: ipv4Unicast
               redistributed_routes:
                 - proto: Connected
                     include_leaked: True
                     route_map: RM-CONN-2-BGP
                  - proto: Static
                     include_leaked: True
                     route_map: RM-CONN-2-BGP
            - afi_safi: IPv6 Unicast
               redistributed_routes:
                 - proto: Dynamic
                    route_map: RM-CONN-2-BGP
                 - proto: Static
                    include_leaked: True
                    route_map: RM-CONN-2-BGP

However, I'm encountering an issue with Cognitive Complexity. To resolve this, I've proposed an alternative input model approach:

- VerifyBGPRedistribution:
     address_families:
        - afi_safi: ipv4Unicast
           vrf: default
            redistributed_routes:
              - proto: Connected
                 include_leaked: True
                 route_map: RM-CONN-2-BGP
               - proto: Static
                  include_leaked: True
                   route_map: RM-CONN-2-BGP
        - afi_safi: IPv4 Unicast
           vrf: test
            redistributed_routes:
              - proto: Dynamic
                 route_map: RM-CONN-2-BGP
               - proto: Static
                  include_leaked: True
                  route_map: RM-CONN-2-BGP  
         - afi_safi: IPv4Unicast
            vrf: mgmt
            redistributed_routes:
               - proto: Dynamic
                  route_map: RM-CONN-2-BGP
                - proto: Static
                   include_leaked: True
                   route_map: RM-CONN-2-BGP

Key Reasons for the Proposed Change

  • It aligns with the structure already used in other BGP tests, ensuring consistency.
  • It eliminates unnecessary looping and conditional logic.
  • It reduces code complexity, making the test case easier to maintain.

As discussed with @gmuloc we will revisit this once Carl returns and then finalize the approach, In the meantime, I’m putting this on hold.

Thanks,
Geetanjali

Comment on lines 1741 to 1743
if address_family.afi not in ["ipv4", "ipv6"] or address_family.safi not in ["unicast", "multicast"]:
msg = f"{address_family}; redistributed route protocol is not supported for address family `{address_family.eos_key}`"
raise ValueError(msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could go in the AfiSafiConfig model directly.

Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

@gmuloc gmuloc added the on-hold Waiting for additional elements label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-hold Waiting for additional elements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add testcase to verify the BGP Redistributed Routes
4 participants