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 testcases to verifying Route Type #925

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

Conversation

geetanjalimanegslab
Copy link

@geetanjalimanegslab geetanjalimanegslab commented Nov 14, 2024

Description

This test performs the following checks for each specific ipv4 route:
        1. Verify that the specified VRF is configured.
        2. Verifies that the specified ipv4 route exists in the configuration.
        3. Verify that the provided ipv4 route is of the expected type.

    Expected Results
    ----------------
    * Success:  If all of the following conditions are met:
        - All the specified VRFs are configured.
        - All the specified ipv4 routes are found.
        - All the specified ipv4 routes are of the expected type.
    * Failure:  If any of the following occur:
        - A specified VRF is not configured.
        - A specified ipv4 routes are found.
        - Any specified ipv4 route is not of the expected type.

Fixes #884

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 Issue_884: Added testcases for verifying Route Type feat(anta): Added testcases for verifying Route Type Nov 14, 2024
@geetanjalimanegslab geetanjalimanegslab changed the title feat(anta): Added testcases for verifying Route Type feat(anta): Added testcases to verifying Route Type Nov 14, 2024
Comment on lines 513 to 515
- vrf: default
prefix: 10.10.0.1/32
route_type: eBGP
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • prefix: 10.10.0.1/32
    vrf: default
    route_type: eBGP

Copy link
Collaborator

Choose a reason for hiding this comment

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

Update all places

@@ -208,3 +208,34 @@ def validate_regex(value: str) -> str:
SnmpErrorCounter = Literal[
"inVersionErrs", "inBadCommunityNames", "inBadCommunityUses", "inParseErrs", "outTooBigErrs", "outNoSuchNameErrs", "outBadValueErrs", "outGeneralErrs"
]
# TODO: Needs to update the route types with confirmation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just for my information, how did you come up with this list of route-types?
This is good to help for the input but it may be tricky to maintain (though I suppose it is life)

Choose a reason for hiding this comment

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

Hi, @gmuloc ,
The mentioned route types are collected from the following command output.

eaf2-dc1#show ip route vrf all

VRF: default
Codes: C - connected, S - static, K - kernel, 
       O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
       E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
       N2 - OSPF NSSA external type2, B - Other BGP Routes,
       B I - iBGP, B E - eBGP, R - RIP, I L1 - IS-IS level 1,
       I L2 - IS-IS level 2, O3 - OSPFv3, A B - BGP Aggregate,
       A O - OSPF Summary, NG - Nexthop Group Static Route,
       V - VXLAN Control Service, M - Martian,
       DH - DHCP client installed default route,
       DP - Dynamic Policy Route, L - VRF Leaked,
       G  - gRIBI, RC - Route Cache Route,
       CL - CBF Leaked Route

Gateway of last resort is not set

 B E      10.10.0.1/32 [200/0] via 10.100.0.12, Ethernet1
                               via 10.100.0.14, Ethernet2
 C        10.100.0.12/31 is directly connected, Ethernet1
 C        10.100.0.14/31 is directly connected, Ethernet2
 

Vitthal shared a JSON output with me, so with that help, I verified a few route types, such as connected, iBGP, and eBGP, to validate that the other route type needs some more configuration. Hence, I added TODO over there.

Comment on lines 221 to 223
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [
AntaCommand(command="show ip route vrf all", revision=4),
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would expect this can be one line with out ruff config - maybe you need to check your IDE for the settings (you need to remove the , after revision=4) to let ruff do its magic

Comment on lines 230 to 238
class Routes(BaseModel):
"""Model for a list of route entries."""

vrf: str = "default"
""" VRF context. Defaults to `default` VRF."""
prefix: IPv4Network
""" IPV4network to validate the rout type. """
route_type: RouteType
""" List of Route type to validate the valid rout type. """
Copy link
Collaborator

Choose a reason for hiding this comment

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

so there is an effort now to move the nested base models to input_models - if you can move this to the relevant files that would be great (otherwise you have done exactly what we used to do so that was perfect)

@@ -208,3 +208,34 @@ def validate_regex(value: str) -> str:
SnmpErrorCounter = Literal[
"inVersionErrs", "inBadCommunityNames", "inBadCommunityUses", "inParseErrs", "outTooBigErrs", "outNoSuchNameErrs", "outBadValueErrs", "outGeneralErrs"
]
# TODO: Needs to update the route types with confirmation.

RouteType = Literal[
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
RouteType = Literal[
IPv4RouteType = Literal[

from anta.custom_types import RouteType


class Routes(BaseModel):
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
class Routes(BaseModel):
class IPv4Routes(BaseModel):

@@ -181,3 +183,77 @@ def test(self) -> None:
self.result.is_success()
else:
self.result.is_failure(f"The following route(s) are missing from the routing table of VRF {self.inputs.vrf}: {missing_routes}")


class VerifyRouteType(AntaTest):
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
class VerifyRouteType(AntaTest):
class VerifyIPv4RouteType(AntaTest):


routes_entries: list[Routes]
"""List of route entries"""
Routes: ClassVar[type[Routes]] = Routes
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
Routes: ClassVar[type[Routes]] = Routes

"""Main test function for VerifyRouteType."""
self.result.is_success()

# Collecting the 'show ip route vrf all' command output.
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
# Collecting the 'show ip route vrf all' command output.

output = self.instance_commands[0].json_output

# Iterating over the all routes entries mentioned in the inputs.
for entries in self.inputs.routes_entries:
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
for entries in self.inputs.routes_entries:
for entry in self.inputs.routes_entries:

continue

# Verifying that the expected route is present or not on the device
if (route_data := get_value(routes_details, prefix, separator="..")) is None:
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
if (route_data := get_value(routes_details, prefix, separator="..")) is None:
if (route_data := routes_details.get(prefix)) is None:


# Verifying that the expected route-type and the actual routes are the same.
if expected_route_type != actual_route_type:
self.result.is_failure(f"{entries}- Incorrect route type; Expected: {expected_route_type} Actual: {actual_route_type}")
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
self.result.is_failure(f"{entries}- Incorrect route type; Expected: {expected_route_type} Actual: {actual_route_type}")
self.result.is_failure(f"{entries} - Incorrect route type, Expected: {expected_route_type} Actual: {actual_route_type}")

Comment on lines 255 to 258
actual_route_type = route_data.get("routeType")

# Verifying that the expected route-type and the actual routes are the same.
if expected_route_type != actual_route_type:
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
actual_route_type = route_data.get("routeType")
# Verifying that the expected route-type and the actual routes are the same.
if expected_route_type != actual_route_type:
# Verifying that the expected route-type and the actual routes are the same.
if expected_route_type != ( actual_route_type := route_data.get("routeType")):

Comment on lines 558 to 561
{"vrf": "default", "prefix": "10.100.0.12/31", "route_type": "connected"},
{"vrf": "default", "prefix": "10.100.0.14/31", "route_type": "connected"},
{"vrf": "default", "prefix": "10.100.0.128/31", "route_type": "eBGP"},
{"vrf": "default", "prefix": "10.100.1.5/32", "route_type": "iBGP"},
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
{"vrf": "default", "prefix": "10.100.0.12/31", "route_type": "connected"},
{"vrf": "default", "prefix": "10.100.0.14/31", "route_type": "connected"},
{"vrf": "default", "prefix": "10.100.0.128/31", "route_type": "eBGP"},
{"vrf": "default", "prefix": "10.100.1.5/32", "route_type": "iBGP"},

Comment on lines 643 to 652
"inputs": {
"routes_entries": [
{"vrf": "default", "prefix": "1022.10.0.1/32", "route_type": "eBGP"},
{"vrf": "default", "prefix": "2001:db8:3333:4444:5555:6666:7777:8888:", "route_type": "connected"},
{"vrf": "default", "prefix": "10.100.0.14/31", "route_type": "connected"},
{"vrf": "default", "prefix": "10.100.0.128/31", "route_type": "eBGP"},
{"vrf": "default", "prefix": "10.100.1.5/32", "route_type": "iBGP"},
]
},
"expected": {"result": "error", "messages": ["Input is not a valid IPv4 network"]},
Copy link
Collaborator

Choose a reason for hiding this comment

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

remvoe this test, we don't test pydantic verification in tests

Copy link

codspeed-hq bot commented Nov 24, 2024

CodSpeed Performance Report

Merging #925 will not alter performance

Comparing geetanjalimanegslab:issue_884 (b37059f) with main (2de0f5a)

Summary

✅ 8 untouched benchmarks

Copy link

sonarcloud bot commented Nov 26, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the test case to verify the route type(routes learned via)
3 participants