Skip to content

Commit

Permalink
feat(anta): Issue_882-Added the test case to verify the Graceful Rest…
Browse files Browse the repository at this point in the history
…art (GR) and GR-Helper
  • Loading branch information
Geetanjali Mane authored and Geetanjali Mane committed Dec 26, 2024
1 parent e12197b commit ae862e3
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 0 deletions.
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}"
91 changes: 91 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,93 @@ 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')}"
)

if instance_details.get("gracefulRestartHelper") != graceful_helper:
self.result.is_failure(
f"{instance} - Incorrect value for Graceful Restart Helper - Expected: {graceful_helper}, Actual: {instance_details.get('gracefulRestartHelper')
}"
)
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

0 comments on commit ae862e3

Please sign in to comment.