8000 feat(anta): Added the test case to verify the Graceful Restart (GR) and GR-Helper by geetanjalimanegslab · Pull Request #988 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(anta): Added the test case to verify the Graceful Restart (GR) and GR-Helper #988

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions anta/input_models/routing/isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class ISISInstance(BaseModel):
"""Configured SR data-plane for the IS-IS instance."""
segments: list[Segment] | None = None
"""List of IS-IS SR segments associated with the instance. Required field in the `VerifyISISSegmentRoutingAdjacencySegments` test."""
graceful_restart: bool = False
"""Graceful restart status."""
graceful_restart_helper: bool = True
"""Graceful restart helper status."""

def __str__(self) -> str:
"""Return a human-readable string representation of the ISISInstance for reporting."""
Expand Down
75 changes: 75 additions & 0 deletions anta/tests/routing/isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,78 @@ def _via_matches(self, via_input: TunnelPath, eos_via: dict[str, Any]) -> bool:
and (via_input.interface is None or via_input.interface == eos_via.get("interface"))
and (via_input.tunnel_id is None or via_input.tunnel_id.upper() == get_value(eos_via, "tunnelId.type", default="").upper())
)


class VerifyISISGracefulRestart(AntaTest):
"""Verifies the IS-IS graceful restart feature.

This test performs the following checks for each IS-IS instance:

1. Verifies that the specified IS-IS instance is configured on the device.
2. Verifies the statuses of the graceful restart and graceful restart helper functionalities.

Expected Results
----------------
* Success: The test will pass if all of the following conditions are met:
- The specified IS-IS instance is configured on the device.
- Expected and actual IS-IS graceful restart and graceful restart helper values match.
* Failure: The test will fail if any of the following conditions is met:
- The specified IS-IS instance is not configured on the device.
- Expected and actual IS-IS graceful restart and graceful restart helper values do not match.
* Skipped: The test will skip if IS-IS is not configured on the device.

Examples
--------
```yaml
anta.tests.routing:
isis:
- VerifyISISGracefulRestart:
instances:
- name: '1'
vrf: default
graceful_restart: True
graceful_restart_helper: False
- name: '2'
vrf: default
- name: '11'
vrf: test
graceful_restart: True
- name: '12'
vrf: test
graceful_restart_helper: False
```
"""

categories: ClassVar[list[str]] = ["isis"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show isis graceful-restart vrf all", revision=1)]

class Input(AntaTest.Input):
"""Input model for the VerifyISISGracefulRestart test."""

instances: list[ISISInstance]
"""List of IS-IS instance entries."""

@AntaTest.anta_test
def test(self) -> None:
"""Main test function for VerifyISISGracefulRestart."""
self.result.is_success()

# Verify if IS-IS is configured
if not (command_output := self.instance_commands[0].json_output["vrfs"]):
self.result.is_skipped("IS-IS not configured")
return

# If IS-IS instance is not found or GR and GR helpers are not matching with the expected values, test fails.
for instance in self.inputs.instances:
graceful_restart = "enabled" if instance.graceful_restart else "disabled"
graceful_restart_helper = "enabled" if instance.graceful_restart_helper else "disabled"

if (instance_details := get_value(command_output, f"{instance.vrf}..isisInstances..{instance.name}", separator="..")) is None:
self.result.is_failure(f"{instance} - Not configured")
continue

if (act_state := instance_details.get("gracefulRestart")) != graceful_restart:
self.result.is_failure(f"{instance} - Incorrect graceful restart state - Expected: {graceful_restart} Actual: {act_state}")

if (act_helper_state := instance_details.get("gracefulRestartHelper")) != graceful_restart_helper:
self.result.is_failure(f"{instance} - Incorrect graceful restart helper state - Expected: {graceful_restart_helper} Actual: {act_helper_state}")
15 changes: 15 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,21 @@ anta.tests.routing.generic:
minimum: 2
maximum: 20
anta.tests.routing.isis:
- VerifyISISGracefulRestart:
# Verifies the IS-IS graceful restart feature.
instances:
- name: '1'
vrf: default
graceful_restart: True
graceful_restart_helper: False
- name: '2'
vrf: default
- name: '11'
vrf: test
graceful_restart: True
- name: '12'
vrf: test
graceful_restart_helper: False
- VerifyISISInterfaceMode:
# Verifies IS-IS interfaces are running in the correct mode.
interfaces:
Expand Down
146 changes: 146 additions & 0 deletions tests/units/anta_tests/routing/test_isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest

from anta.tests.routing.isis import (
VerifyISISGracefulRestart,
VerifyISISInterfaceMode,
VerifyISISNeighborCount,
VerifyISISNeighborState,
Expand Down Expand Up @@ -2297,4 +2298,149 @@
"messages": ["IS-IS-SR not configured"],
},
},
{
"name": "success",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {
"isisInstances": {
"1": {
"gracefulRestart": "enabled",
"gracefulRestartHelper": "enabled",
},
"2": {
"gracefulRestart": "enabled",
"gracefulRestartHelper": "disabled",
},
}
},
"test": {
"isisInstances": {
"11": {
"gracefulRestart": "disabled",
"gracefulRestartHelper": "enabled",
},
"12": {
"gracefulRestart": "enabled",
"gracefulRestartHelper": "disabled",
},
}
},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1", "graceful_restart": True},
{"vrf": "default", "name": "2", "graceful_restart": True, "graceful_restart_helper": False},
{"vrf": "test", "name": "11"},
{"vrf": "test", "name": "12", "graceful_restart": True, "graceful_restart_helper": False},
]
},
"expected": {"result": "success"},
},
{
"name": "failure-isis-not-configured",
"test": VerifyISISGracefulRestart,
"eos_data": [{"vrfs": {}}],
"inputs": {"instances": [{"vrf": "default", "name": "1", "graceful_restart": True}]},
"expected": {"result": "skipped", "messages": ["IS-IS not configured"]},
},
{
"name": "failure-isis-instance-not-found",
"test": VerifyISISGracefulRestart,
"eos_data": [{"vrfs": {"default": {"isisInstances": {"2": {"gracefulRestart": "enabled", "gracefulRestartHelper": "enabled"}}}}}],
"inputs": {"instances": [{"vrf": "default", "name": "1", "graceful_restart": True}]},
"expected": {"result": "failure", "messages": ["Instance: 1 VRF: default - Not configured"]},
},
{
"name": "failure-graceful-restart-disabled",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {
"isisInstances": {
"1": {
"gracefulRestart": "disabled",
"gracefulRestartHelper": "enabled",
},
"2": {
"gracefulRestart": "enabled",
"gracefulRestartHelper": "enabled",
},
}
},
"test": {
"isisInstances": {
"11": {
"gracefulRestart": "enabled",
"gracefulRestartHelper": "enabled",
},
"12": {
"gracefulRestart": "enabled",
"gracefulRestartHelper": "disabled",
},
}
},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1", "graceful_restart": True},
{"vrf": "default", "name": "2", "graceful_restart": True},
{"vrf": "test", "name": "11"},
{"vrf": "test", "name": "12", "graceful_restart": True, "graceful_restart_helper": False},
]
},
"expected": {
"result": "failure",
"messages": [
"Instance: 1 VRF: default - Incorrect graceful restart state - Expected: enabled Actual: disabled",
"Instance: 11 VRF: test - Incorrect graceful restart state - Expected: disabled Actual: enabled",
],
},
},
{
"name": "failure-graceful-restart-helper-disabled",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {
"isisInstances": {
"1": {
"gracefulRestart": "disabled",
"gracefulRestartHelper": "disabled",
}
}
},
"test": {
"isisInstances": {
"11": {
"gracefulRestart": "disabled",
"gracefulRestartHelper": "enabled",
}
}
},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1"},
{"vrf": "test", "name": "11", "graceful_restart_helper": False},
]
},
"expected": {
"result": "failure",
"messages": [
"Instance: 1 VRF: default - Incorrect graceful restart helper state - Expected: enabled Actual: disabled",
"Instance: 11 VRF: test - Incorrect graceful restart helper state - Expected: disabled Actual: enabled",
],
},
},
]
0