-
Notifications
You must be signed in to change notification settings - Fork 31
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 paths #507
base: main
Are you sure you want to change the base?
Conversation
95d7613
to
dcd5b0d
Compare
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.
dcd5b0d
to
3c4b595
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
CodSpeed Performance ReportMerging #507 will not alter performanceComparing Summary
|
anta/tests/routing/bgp.py
Outdated
self.result.is_failure(f"{route} - prefix not found in BGP table") | ||
continue | ||
|
||
route_paths = bgp_route_entry["bgpRoutePaths"] |
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.
It's better to create an iterator from the start and work with it. That way, you don't need to create a generator expression on line 1767 and remove the head on line 1774.
route_paths = bgp_route_entry["bgpRoutePaths"] | |
route_paths = iter(bgp_route_entry["bgpRoutePaths"]) |
anta/tests/routing/bgp.py
Outdated
head = next((path for path in route_paths if all(path.get("routeType", {}).get(key, False) for key in ["valid", "active", "ecmpHead"])), None) | ||
# Verify if the active ECMP head exists in routepath. | ||
if not head: | ||
self.result.is_failure(f"{route} - valid and active ECMP head not found") | ||
continue |
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.
routeType
and valid
, active
, ecmpHead
will always be there so we can safely access them not using get()
. I will show you how we can find the CLI models for EOS this week.
head = next((path for path in route_paths if all(path.get("routeType", {}).get(key, False) for key in ["valid", "active", "ecmpHead"])), None) | |
# Verify if the active ECMP head exists in routepath. | |
if not head: | |
self.result.is_failure(f"{route} - valid and active ECMP head not found") | |
continue | |
head = next(route_paths, None) | |
# Verify if the active ECMP head exists. | |
if head is None or not all(head[key] for key in ["valid", "active", "ecmpHead"]): | |
self.result.is_failure(f"{route} - valid and active ECMP head not found") | |
continue |
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.
For the head, let's check for valid
+ active
+ ecmpHead
+ ecmp
+ ecmpContributor
just to make sure.
anta/tests/routing/bgp.py
Outdated
self.result.is_failure(f"{route} - valid and active ECMP head not found") | ||
continue | ||
|
||
bgp_nexthops = [head.get("nextHop")] |
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, we can safely assume that any route marked as valid
+ active
+ ecmpHead
will have a nextHop
value.
bgp_nexthops = [head.get("nextHop")] | |
bgp_nexthops = {head["nextHop"]} |
anta/tests/routing/bgp.py
Outdated
continue | ||
|
||
bgp_nexthops = [head.get("nextHop")] | ||
route_paths.remove(head) |
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.
Not needed if we use the same iterator.
anta/tests/routing/bgp.py
Outdated
|
||
bgp_nexthops = [head.get("nextHop")] | ||
route_paths.remove(head) | ||
bgp_nexthops.extend([path.get("nextHop") for path in route_paths if all(path.get("routeType")[key] for key in ["valid", "ecmp", "ecmpContributor"])]) |
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.
Same as above, no need to use get()
.
anta/tests/routing/bgp.py
Outdated
bgp_nexthops = [head.get("nextHop")] | ||
route_paths.remove(head) | ||
bgp_nexthops.extend([path.get("nextHop") for path in route_paths if all(path.get("routeType")[key] for key in ["valid", "ecmp", "ecmpContributor"])]) | ||
bgp_nexthops = ["linked-locally" if nexthop == "" else nexthop for nexthop in bgp_nexthops] |
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.
Where does linked-locally
come from? I don't think it's required since we can also safely assume that any route marked as valid
+ ecmp
+ ecmpContributor
will have a nextHop
value.
anta/tests/routing/bgp.py
Outdated
rib_nexthops = [via.get("nexthopAddr", "linked-locally") for via in route_entry["vias"] if route_entry["routeType"] in {"iBGP", "eBGP"}] | ||
# Verify BGP and RIB nexthops are same. | ||
if sorted(bgp_nexthops) != sorted(rib_nexthops): | ||
self.result.is_failure(f"{route} - nexthops mismatch - BGP: {', '.join(sorted(bgp_nexthops))}, RIB: {', '.join(sorted(rib_nexthops))}") |
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.
We should use sets to do the comparison and sort them in the failure message.
"nextHop": "", | ||
"routeType": { | ||
"valid": True, | ||
"active": False, | ||
"ecmpHead": False, | ||
"ecmp": True, | ||
"ecmpContributor": True, |
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.
Where you able to reproduce this on EOS?
"nextHop": "", | ||
"routeType": { | ||
"valid": True, | ||
"active": False, | ||
"ecmpHead": False, | ||
"ecmp": True, | ||
"ecmpContributor": True, |
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.
Same as above.
"allRoutesProgrammedKernel": True, | ||
"defaultRouteState": "notSet", | ||
"routes": { | ||
"10.111.112.0/24": {"routeAction": "forward", "vias": [{"interface": "Vlan112"}]}, |
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.
Doesn't really matter for this but routeType
is missing.
anta/tests/routing/bgp.py
Outdated
categories: ClassVar[list[str]] = ["bgp"] | ||
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [ | ||
AntaCommand(command="show ip bgp vrf all", revision=3), | ||
AntaCommand(command="show ip route vrf all", revision=4), |
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.
AntaCommand(command="show ip route vrf all", revision=4), | |
AntaCommand(command="show ip route vrf all bgp", revision=4), |
anta/tests/routing/bgp.py
Outdated
1. Route exists in BGP table. | ||
2. First path is a valid and active ECMP head. | ||
3. Correct number of valid ECMP contributors follow the head path. | ||
4. Route is installed in RIB with matching next-hops. |
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.
4. Route is installed in RIB with matching next-hops. | |
4. Route is installed in RIB with same amount of next-hops. |
anta/tests/routing/bgp.py
Outdated
- A valid and active ECMP head is not found. | ||
- ECMP contributors count does not match the expected value. | ||
- Route is not installed in RIB table. | ||
- BGP and RIB nexthops do not match. |
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.
- BGP and RIB nexthops do not match. | |
- BGP and RIB nexthops count do not match. |
Quality Gate passedIssues Measures |
Description
Adding the test case to verify BGP ECMP path install
Test catalog:
Fixes #505
Checklist:
pre-commit run
)tox -e testenv
)