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 path install(On Hold) #507

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MaheshGSLAB
Copy link
Contributor

@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
@@ -447,3 +447,62 @@ def test(self) -> None:

if failures:
self.result.is_failure(f"Failures: {list(failures.values())}")


class VerifyBGPEcmpPath(AntaTest):
Copy link
Contributor

@carl-baillargeon carl-baillargeon Jan 6, 2024

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

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

@carl-baillargeon carl-baillargeon Jan 6, 2024

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.

Input parameters for the test.
"""

bgp_routes: List[BgpPeers]
Copy link
Contributor

Choose a reason for hiding this comment

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

prefixes: List[BgpPrefixes]

This class defines the details of a BGP route.
"""

route: str
Copy link
Contributor

Choose a reason for hiding this comment

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

prefix: IPv4Network

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="..")):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is separator=".." required here?

Copy link
Contributor Author

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

Comment on lines 497 to 503
# 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
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, 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.

Copy link
Contributor Author

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

# 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
Copy link
Contributor Author

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

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.

"""IPv4 BGP prefix"""
vrf: str = "default"
"""Optional VRF for BGP peer. If not provided, it defaults to `default`."""
ecmp_count: int
Copy link
Contributor

Choose a reason for hiding this comment

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

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

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

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

@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
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
3 participants