-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
feat(anta): Added testcases to verifying Route Type #925
Conversation
for more information, see https://pre-commit.ci
examples/tests.yaml
Outdated
- vrf: default | ||
prefix: 10.10.0.1/32 | ||
route_type: eBGP |
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: 10.10.0.1/32
vrf: default
route_type: eBGP
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.
Update all places
for more information, see https://pre-commit.ci
@@ -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. |
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.
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)
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.
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.
anta/tests/routing/generic.py
Outdated
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [ | ||
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.
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
anta/tests/routing/generic.py
Outdated
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. """ |
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.
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)
anta/custom_types.py
Outdated
@@ -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[ |
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 = Literal[ | |
IPv4RouteType = Literal[ |
anta/input_models/routing/generic.py
Outdated
from anta.custom_types import RouteType | ||
|
||
|
||
class Routes(BaseModel): |
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.
class Routes(BaseModel): | |
class IPv4Routes(BaseModel): |
anta/tests/routing/generic.py
Outdated
@@ -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): |
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.
class VerifyRouteType(AntaTest): | |
class VerifyIPv4RouteType(AntaTest): |
anta/tests/routing/generic.py
Outdated
|
||
routes_entries: list[Routes] | ||
"""List of route entries""" | ||
Routes: ClassVar[type[Routes]] = Routes |
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.
Routes: ClassVar[type[Routes]] = Routes |
anta/tests/routing/generic.py
Outdated
"""Main test function for VerifyRouteType.""" | ||
self.result.is_success() | ||
|
||
# Collecting the 'show ip route vrf all' command output. |
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.
# Collecting the 'show ip route vrf all' command output. |
anta/tests/routing/generic.py
Outdated
output = self.instance_commands[0].json_output | ||
|
||
# Iterating over the all routes entries mentioned in the inputs. | ||
for entries in self.inputs.routes_entries: |
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 entries in self.inputs.routes_entries: | |
for entry in self.inputs.routes_entries: |
anta/tests/routing/generic.py
Outdated
continue | ||
|
||
# Verifying that the expected route is present or not on the device | ||
if (route_data := get_value(routes_details, prefix, separator="..")) is None: |
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.
if (route_data := get_value(routes_details, prefix, separator="..")) is None: | |
if (route_data := routes_details.get(prefix)) is None: |
anta/tests/routing/generic.py
Outdated
|
||
# 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}") |
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.
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}") |
anta/tests/routing/generic.py
Outdated
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: |
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.
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")): |
{"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"}, |
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.
{"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"}, |
"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"]}, |
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.
remvoe this test, we don't test pydantic verification in tests
…ses as verifyipv4routetype
CodSpeed Performance ReportMerging #925 will not alter performanceComparing Summary
|
Quality Gate passedIssues Measures |
Description
Fixes #884
Checklist:
pre-commit run
)tox -e testenv
)