-
Notifications
You must be signed in to change notification settings - Fork 25
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.tests): Adding the test case to verify BGP ECMP path install(On Hold) #507
base: main
Are you sure you want to change the base?
Conversation
anta/tests/routing/bgp.py
Outdated
@@ -447,3 +447,62 @@ def test(self) -> None: | |||
|
|||
if failures: | |||
self.result.is_failure(f"Failures: {list(failures.values())}") | |||
|
|||
|
|||
class VerifyBGPEcmpPath(AntaTest): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call the test VerifyBGPIPv4Prefixes
anta/tests/routing/bgp.py
Outdated
name = "VerifyBGPEcmpPath" | ||
description = "Verifies the installation of BGP Equal-Cost Multipath (ECMP) path in the specified VRF." | ||
categories = ["routing", "bgp"] | ||
commands = [AntaCommand(command="show ip bgp")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the BGP table can get pretty large, let's filter down per prefix and use AntaTemplate
.
1- show bgp ipv4 unicast {prefix] vrf {vrf}
2- show ip route vrf {vrf} {prefix}
We can first check the BGP table for the prefix, save the ECMP paths and check the RIB if they are present.
This test would only work with IPv4 unicast so we need to specify it in the docstring.
anta/tests/routing/bgp.py
Outdated
Input parameters for the test. | ||
""" | ||
|
||
bgp_routes: List[BgpPeers] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefixes: List[BgpPrefixes]
anta/tests/routing/bgp.py
Outdated
This class defines the details of a BGP route. | ||
""" | ||
|
||
route: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefix: IPv4Network
anta/tests/routing/bgp.py
Outdated
vrf = bgp_route.vrf | ||
|
||
# Verify if BGP route exist | ||
if not (bgp_output := get_value(self.instance_commands[0].json_output, f"vrfs..{vrf}..bgpRouteEntries..{route}", separator="..")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is separator=".."
required here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes due to . in prefix
anta/tests/routing/bgp.py
Outdated
# Verify BGP route's ecmp head and contribution | ||
bgp_paths = bgp_output.get("bgpRoutePaths", []) | ||
failures[route] = {vrf: "ECMP path is not installed"} | ||
for path in bgp_paths: | ||
if path.get("routeType", {}).get("ecmpHead") and path.get("routeType", {}).get("ecmpContributor"): | ||
failures.pop(route) | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In BGP, only 1 path can be valid, active and ECMP head so I would loop over bgpRoutePaths
and check the valid
, active
, ecmpHead
, ecmp
, ecmpContributor
keys. If they are all true, that means we have ECMP so we should check the other paths. The other paths should be valid
, ecmp
and ecmpContributor
but NOT active
and ecmpHead
.
We can then save the nextHop
into a list or a set and confirm that the RIB has all paths installed for the input prefixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per discussion add ecmp_count as user input to validate both command outputs should have an equal number of routes as ecmp_count
95d7613
to
dcd5b0d
Compare
# Check for mismatch | ||
if paths_info["ip_paths"] != paths_info["bgp_paths"]: | ||
# Create nested dictionary structure for failures | ||
failures.setdefault(prefix, {}).setdefault(vrf, {})["mismatched_paths"] = paths_info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to make the changes for updating setdefault with deep_update method
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please hold on this one. The logic is pretty complex, we might have to split it in 2 test cases.
"""IPv4 BGP prefix""" | ||
vrf: str = "default" | ||
"""Optional VRF for BGP peer. If not provided, it defaults to `default`.""" | ||
ecmp_count: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ecmp_count: int | |
ecmp_count: int = Field(ge=1, le=128) |
|
||
# If paths do not exist, mark as not configured | ||
if not paths: | ||
failures.setdefault(prefix, {}).setdefault(vrf, {}).setdefault("unicast" if is_unicast else "rib", "Not configured") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a cleaner way of doing this?
ecmp_count = command.params["ecmp_count"] | ||
|
||
# Determine if the command is for unicast | ||
is_unicast = "unicast" in command.command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matching on is_unicast
can be misleading since we can have other SAFI like multicast
Description
Adding the test case to verify BGP ECMP path install
Test catalog:
Fixes #505
Checklist:
pre-commit run
)tox -e testenv
)