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 6 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions anta/input_models/routing/isis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2023-2025 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Module containing input models for ISIS tests."""

from __future__ import annotations

from pydantic import BaseModel, ConfigDict


class ISISInstances(BaseModel):
"""Model for a list of ISIS instance entries."""

model_config = ConfigDict(extra="forbid")
name: str
"""The instance name to validated the instance specific isis details."""
vrf: str = "default"
"""VRF context. Defaults to `default` VRF."""
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 ISISInstances for reporting."""
return f"Instance: {self.name} VRF: {self.vrf}"
87 changes: 87 additions & 0 deletions anta/tests/routing/isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pydantic import BaseModel

from anta.custom_types import Interface
from anta.input_models.routing.isis import ISISInstances
from anta.models import AntaCommand, AntaTemplate, AntaTest
from anta.tools import get_value

Expand Down Expand Up @@ -728,3 +729,89 @@ def _check_tunnel_id(self, via_input: VerifyISISSegmentRoutingTunnels.Input.Entr
for eos_via in eos_entry["vias"]
)
return True


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: '1'
vrf: test
graceful_restart: True
graceful_helper: True
- name: '2'
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[ISISInstances]
"""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")
15 changes: 15 additions & 0 deletions docs/api/tests.routing.isis.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ anta_title: ANTA catalog for IS-IS tests
~ that can be found in the LICENSE file.
-->

# Test

::: anta.tests.routing.isis

options:
Expand All @@ -20,3 +22,16 @@ anta_title: ANTA catalog for IS-IS tests
- "!test"
- "!render"
- "!^_[^_]"

# Input models

::: anta.input_models.routing.isis

options:
show_root_heading: false
show_root_toc_entry: false
show_bases: false
merge_init_into_class: false
anta_hide_test_module_description: true
show_labels: true
filters: ["!^__str__"]
19 changes: 19 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,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: '1'
vrf: test
graceful_restart: True
graceful_helper: True
- name: '2'
vrf: test
graceful_restart: True
graceful_helper: True
- VerifyISISInterfaceMode:
# Verifies interface mode for IS-IS
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 @@ -1840,6 +1841,107 @@
"messages": ["Tunnel to 1.0.0.111/32 is incorrect: incorrect tunnel ID"],
},
},
{
"name": "success",
"test": VerifyISISGracefulRestart,
"eos_data": [
{
"vrfs": {
"default": {
"isisInstances": {
"1": {"gracefulRestart": True, "gracefulRestartHelper": True},
"2": {"gracefulRestart": True, "gracefulRestartHelper": True},
}
},
"test": {
"isisInstances": {
"1": {"gracefulRestart": True, "gracefulRestartHelper": True},
"2": {"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": "1", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "2", "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": {
"1": {"gracefulRestart": False, "gracefulRestartHelper": True},
"2": {"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": "1", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "2", "graceful_restart": True, "graceful_helper": True},
]
},
"expected": {
"result": "failure",
"messages": ["Instance: 1 VRF: default - Graceful Restart disabled", "Instance: 1 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": {"1": {"gracefulRestart": True, "gracefulRestartHelper": False}}},
}
}
],
"inputs": {
"instances": [
{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True},
{"vrf": "test", "name": "1", "graceful_restart": True, "graceful_helper": True},
]
},
"expected": {
"result": "failure",
"messages": ["Instance: 1 VRF: default - Graceful Restart Helper disabled", "Instance: 1 VRF: test - Graceful Restart Helper disabled"],
},
},
]


Expand Down
Loading