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.tests): Adding the test case to verify BGP ECMP paths #507

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

Conversation

MaheshGSLAB
Copy link
Collaborator

@MaheshGSLAB MaheshGSLAB commented Jan 2, 2024

Description

Adding the test case to verify BGP ECMP path install

Test catalog:

anta.tests.routing:
  bgp:
      - VerifyBGPEcmpPath:
          bgp_routes:
            - route: 192.0.254.5/32
              vrf: default
            - route: 192.0.254.3/32
              vrf: default
  1. Testcase pass if route is contributed into ECMP and at least one path is ECMP head in specified vrf.

                                                                          All tests results                                                                           
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Device    ┃ Test Name         ┃ Test Status ┃ Message(s) ┃ Test description                                                                        ┃ Test category ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ s1-spine1 │ VerifyBGPEcmpPath │ success     │            │ Verifies the installation of BGP Equal-Cost Multipath (ECMP) path in the specified VRF. │ routing, bgp  │
└───────────┴───────────────────┴─────────────┴────────────┴─────────────────────────────────────────────────────────────────────────────────────────┴───────────────┘
  1. Testcase fail if route is not found in the specified vrf.
                                                                                         All tests results                                                                                           
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Device    ┃ Test Name         ┃ Test Status ┃ Message(s)                                                        ┃ Test description                                                 ┃ Test category ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ s1-spine1 │ VerifyBGPEcmpPath │ failure     │ Following BGP routes are not configured, not contributed in ecmp, │ Verifies the installation of BGP Equal-Cost Multipath (ECMP)     │ routing, bgp  │
│           │                   │             │ or ecmp head is not found:                                        │ path in the specified VRF.                                       │               │
│           │                   │             │ {'192.0.254.5/32': {'MGMT': 'Not configured'}}                    │                                                                  │               │
└───────────┴───────────────────┴─────────────┴───────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────┴───────────────┘
  1. Testcase fail if route is not contributed in ECMP or ECMP head is not found in the specified vrf.
                                                                                         All tests results                                                                                           
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Device    ┃ Test Name         ┃ Test Status ┃ Message(s)                                                        ┃ Test description                                                 ┃ Test category ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ s1-spine1 │ VerifyBGPEcmpPath │ failure     │ Following BGP routes are not configured, not contributed in ecmp, │ Verifies the installation of BGP Equal-Cost Multipath (ECMP)     │ routing, bgp  │
│           │                   │             │ or ecmp head is not found:                                        │ path in the specified VRF.                                       │               │
│           │                   │             │ {'192.0.255.5/32': {'default': 'ECMP path is not installed'}}     │                                                                  │               │
└───────────┴───────────────────┴─────────────┴───────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────┴───────────────┘

Fixes #505

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)

@MaheshGSLAB MaheshGSLAB self-assigned this Jan 2, 2024
@MaheshGSLAB MaheshGSLAB marked this pull request as ready for review January 2, 2024 09:07
@MaheshGSLAB MaheshGSLAB changed the title feat: Adding the test case to verify BGP ECMP path install feat(anta.tests)!: Adding the test case to verify BGP ECMP path install Jan 4, 2024
@gmuloc gmuloc changed the title feat(anta.tests)!: Adding the test case to verify BGP ECMP path install feat(anta.tests): Adding the test case to verify BGP ECMP path install Jan 5, 2024
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
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
Copy link
Contributor

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

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 hold on this one. The logic is pretty complex, we might have to split it in 2 test cases.

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
@MaheshGSLAB MaheshGSLAB changed the title feat(anta.tests): Adding the test case to verify BGP ECMP path install feat(anta.tests): Adding the test case to verify BGP ECMP path install(On Hold) Feb 1, 2024
@MaheshGSLAB MaheshGSLAB marked this pull request as draft February 23, 2024 11:29
@carl-baillargeon carl-baillargeon added this to the v1.1.0 milestone Apr 22, 2024
@gmuloc gmuloc modified the milestones: v1.1.0, v1.2.0 Oct 11, 2024
@carl-baillargeon carl-baillargeon modified the milestones: v1.2.0, v1.3.0 Nov 25, 2024
Copy link
Contributor

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

@carl-baillargeon carl-baillargeon changed the title feat(anta.tests): Adding the test case to verify BGP ECMP path install(On Hold) feat(anta.tests): Adding the test case to verify BGP ECMP paths Jan 22, 2025
Copy link

codspeed-hq bot commented Jan 22, 2025

CodSpeed Performance Report

Merging #507 will not alter performance

Comparing MaheshGSLAB:issue-505 (667403d) with main (9c7a81c)

Summary

✅ 22 untouched benchmarks

anta/tests/routing/bgp.py Outdated Show resolved Hide resolved
anta/tests/routing/bgp.py Outdated Show resolved Hide resolved
tests/units/input_models/routing/test_bgp.py Outdated Show resolved Hide resolved
@vitthalmagadum vitthalmagadum marked this pull request as ready for review January 30, 2025 11:35
self.result.is_failure(f"{route} - prefix not found in BGP table")
continue

route_paths = bgp_route_entry["bgpRoutePaths"]
Copy link
Contributor

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.

Suggested change
route_paths = bgp_route_entry["bgpRoutePaths"]
route_paths = iter(bgp_route_entry["bgpRoutePaths"])

Comment on lines +1767 to +1771
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
Copy link
Contributor

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.

Suggested change
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

self.result.is_failure(f"{route} - valid and active ECMP head not found")
continue

bgp_nexthops = [head.get("nextHop")]
Copy link
Contributor

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.

Suggested change
bgp_nexthops = [head.get("nextHop")]
bgp_nexthops = {head["nextHop"]}

continue

bgp_nexthops = [head.get("nextHop")]
route_paths.remove(head)
Copy link
Contributor

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.


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"])])
Copy link
Contributor

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().

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]
Copy link
Contributor

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.

Comment on lines +1787 to +1790
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))}")
Copy link
Contributor

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.

Comment on lines +5130 to +5136
"nextHop": "",
"routeType": {
"valid": True,
"active": False,
"ecmpHead": False,
"ecmp": True,
"ecmpContributor": True,
Copy link
Contributor

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?

Comment on lines +5140 to +5146
"nextHop": "",
"routeType": {
"valid": True,
"active": False,
"ecmpHead": False,
"ecmp": True,
"ecmpContributor": True,
Copy link
Contributor

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"}]},
Copy link
Contributor

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.

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.

Add the test case to verify the BGP ECMP path install
5 participants