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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 26 additions & 0 deletions anta/input_models/routing/isis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2023-2024 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")
vrf: str = "default"
"""VRF context. Defaults to `default` VRF."""
name: str
"""The instance name or ID to validated the instance specific isis details."""
graceful_restart: bool = True
"""Flag to check if the graceful restart is enabled for isis instance, Defaults to `True`"""
graceful_helper: bool = True
"""Flag to check if the graceful helper is enabled for isis instance, Defaults to `True`"""

def __str__(self) -> str:
"""Return a human-readable string representation of the ISISInstances for reporting."""
return f"VRF: {self.vrf} Instance: {self.name}"
88 changes: 88 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,90 @@ 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 VRF is found.
3. Verifies that the specified VRF instance is found.
4. Verifies that the IS-IS graceful restart and graceful helper are set as expected in the inputs.

Expected Results
----------------
* Success: The test will pass if graceful restart and graceful helper are set as expected for a specified VRF instance.
* Failure: The test will fail if graceful restart and graceful helper are not set as expected for a specified VRF instance.

Examples
--------
```yaml
anta.tests.routing:
isis:
- VerifyISISGracefulRestart:
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

```
"""

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

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

instances: list[ISISInstances]
"""List of ISIS 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 ISIS is not configured, test fails
if not isis_details:
self.result.is_failure("ISIS is not configured")
return

# If VRF, vrf-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 (vrf_details := get_value(isis_details, vrf)) is None:
self.result.is_failure(f"{instance} - VRF is not configured")
continue

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

if instance_details.get("gracefulRestart") != graceful_restart:
self.result.is_failure(
f"{instance} - Incorrect value for Graceful Restart - Expected: {graceful_restart}, Actual: {instance_details.get('gracefulRestart')}"
)

actual_gr_helper = instance_details.get("gracefulRestartHelper")
if actual_gr_helper != graceful_helper:
self.result.is_failure(f"{instance} - Incorrect value for Graceful Restart Helper - Expected: {graceful_helper}, Actual: {actual_gr_helper}")
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__"]
20 changes: 20 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,26 @@ anta.tests.routing.generic:
minimum: 2
maximum: 20
anta.tests.routing.isis:
- VerifyISISGracefulRestart:
# Verifies the graceful restart and helper mechanism.
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

- VerifyISISInterfaceMode:
# Verifies interface mode for IS-IS
interfaces:
Expand Down
115 changes: 115 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,120 @@
"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-vrf-not-found",
"test": VerifyISISGracefulRestart,
"eos_data": [{"vrfs": {"test": {"isisInstances": {"1": {"gracefulRestart": True, "gracefulRestartHelper": True}}}}}],
"inputs": {"instances": [{"vrf": "default", "name": "1", "graceful_restart": True, "graceful_helper": True}]},
"expected": {"result": "failure", "messages": ["VRF: default Instance: 1 - VRF 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": ["VRF: default Instance: 1 - 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": [
"VRF: default Instance: 1 - Incorrect value for Graceful Restart - Expected: True, Actual: False",
"VRF: test Instance: 1 - Incorrect value for Graceful Restart - Expected: True, Actual: False",
],
},
},
{
"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": [
"VRF: default Instance: 1 - Incorrect value for Graceful Restart Helper - Expected: True, Actual: False",
"VRF: test Instance: 1 - Incorrect value for Graceful Restart Helper - Expected: True, Actual: False",
],
},
},
]


Expand Down
Loading