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 the test case to verify the Graceful Restart (GR) and GR-Helper #988

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions anta/input_models/routing/isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ 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 = True
"""Specifies the Graceful Restart,
Options:
- True: Default mode, refer as graceful restart is enabled.
- False: Refer as graceful restart is disabled."""
graceful_helper: bool = True
"""Specifies the Graceful Restart Helper,
Options:
- True: Default mode, refer as graceful restart helper is enabled.
- False: Refer as graceful restart helper is disabled."""

def __str__(self) -> str:
"""Return a human-readable string representation of the ISISInstance for reporting."""
Expand Down
86 changes: 86 additions & 0 deletions anta/tests/routing/isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,89 @@ def _via_matches(self, via_input: VerifyISISSegmentRoutingTunnels.Input.Entry.Vi
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 graceful restart and helper mechanism.

This test performs the following checks:

1. Verifies that the ISIS is configured.
2. Verifies that the specified ISIS instance is found on the device.
4. Verifies that the expected and actual IS-IS graceful restart and graceful helper values are matched.

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

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

categories: ClassVar[list[str]] = ["isis"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show isis summary vrf all", revision=2)]

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()
command_output = self.instance_commands[0].json_output
isis_details = command_output.get("vrfs")

# If IS-IS is not configured, test fails.
if not isis_details:
self.result.is_failure("ISIS 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:
vrf = instance.vrf
instance_name = str(instance.name)
graceful_restart = instance.graceful_restart
graceful_helper = instance.graceful_helper

if (instance_details := get_value(isis_details, f"{vrf}.isisInstances.{instance_name}")) is None:
self.result.is_failure(f"{instance} - Not found")
continue

if instance_details.get("gracefulRestart") != graceful_restart:
vitthalmagadum marked this conversation as resolved.
Show resolved Hide resolved
self.result.is_failure(f"{instance} - Graceful Restart disabled")

actual_gr_helper = instance_details.get("gracefulRestartHelper")
if actual_gr_helper != graceful_helper:
self.result.is_failure(f"{instance} - Graceful Restart Helper disabled")
19 changes: 19 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,25 @@ anta.tests.routing.generic:
minimum: 2
maximum: 20
anta.tests.routing.isis:
- VerifyISISGracefulRestart:
# Verifies the graceful restart and helper mechanism.
instances:
- name: '1'
vrf: default
graceful_restart: True
graceful_helper: True
- name: '2'
vrf: default
graceful_restart: True
graceful_helper: True
- name: '11'
vrf: test
graceful_restart: True
graceful_helper: True
- name: '12'
vrf: test
graceful_restart: True
graceful_helper: True
- VerifyISISInterfaceMode:
# Verifies IS-IS interfaces are running in the correct mode.
interfaces:
Expand Down
102 changes: 102 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,105 @@
"messages": ["IS-IS-SR is not running on device."],
},
},
{
"name": "success",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {
"isisInstances": {
"1": {"gracefulRestart": True, "gracefulRestartHelper": True},
"2": {"gracefulRestart": True, "gracefulRestartHelper": True},
}
},
"test": {
"isisInstances": {
"11": {"gracefulRestart": True, "gracefulRestartHelper": True},
"12": {"gracefulRestart": True, "gracefulRestartHelper": True},
}
},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True},
{"vrf": "default", "name": "2", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "11", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "12", "graceful_restart": True, "graceful_helper": True},
]
},
"expected": {"result": "success"},
},
{
"name": "failure-isis-not-configured",
"test": VerifyISISGracefulRestart,
"eos_data": [{"vrfs": {}}],
"inputs": {"instances": [{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True}]},
"expected": {"result": "failure", "messages": ["ISIS is not configured"]},
},
{
"name": "failure-isis-instance-not-found",
"test": VerifyISISGracefulRestart,
"eos_data": [{"vrfs": {"default": {"isisInstances": {"2": {"gracefulRestart": True, "gracefulRestartHelper": True}}}}}],
"inputs": {"instances": [{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True}]},
"expected": {"result": "failure", "messages": ["Instance: 1 VRF: default - Not found"]},
},
{
"name": "failure-graceful-restart-disabled",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {
"isisInstances": {
"1": {"gracefulRestart": False, "gracefulRestartHelper": True},
"2": {"gracefulRestart": True, "gracefulRestartHelper": True},
}
},
"test": {
"isisInstances": {
"11": {"gracefulRestart": False, "gracefulRestartHelper": True},
"12": {"gracefulRestart": True, "gracefulRestartHelper": True},
}
},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True},
{"vrf": "default", "name": "2", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "11", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "12", "graceful_restart": True, "graceful_helper": True},
]
},
"expected": {
"result": "failure",
"messages": ["Instance: 1 VRF: default - Graceful Restart disabled", "Instance: 11 VRF: test - Graceful Restart disabled"],
},
},
{
"name": "failure-graceful-restart-helper-disabled",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {"isisInstances": {"1": {"gracefulRestart": True, "gracefulRestartHelper": False}}},
"test": {"isisInstances": {"11": {"gracefulRestart": True, "gracefulRestartHelper": False}}},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "11", "graceful_restart": True, "graceful_helper": True},
]
},
"expected": {
"result": "failure",
"messages": ["Instance: 1 VRF: default - Graceful Restart Helper disabled", "Instance: 11 VRF: test - Graceful Restart Helper disabled"],
},
},
]
Loading