diff --git a/anta/input_models/routing/isis.py b/anta/input_models/routing/isis.py index 02fb7dba5..91cb6af4c 100644 --- a/anta/input_models/routing/isis.py +++ b/anta/input_models/routing/isis.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Arista Networks, Inc. +# 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.""" @@ -12,10 +12,10 @@ 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.""" + vrf: str = "default" + """VRF context. Defaults to `default` VRF.""" graceful_restart: bool = True """Specifies the Graceful Restart, Options: @@ -29,4 +29,4 @@ class ISISInstances(BaseModel): def __str__(self) -> str: """Return a human-readable string representation of the ISISInstances for reporting.""" - return f"VRF: {self.vrf} Instance: {self.name}" + return f"Instance: {self.name} VRF: {self.vrf}" diff --git a/anta/tests/routing/isis.py b/anta/tests/routing/isis.py index fa4374626..cbb2706ef 100644 --- a/anta/tests/routing/isis.py +++ b/anta/tests/routing/isis.py @@ -732,26 +732,23 @@ def _check_tunnel_id(self, via_input: VerifyISISSegmentRoutingTunnels.Input.Entr class VerifyISISGracefulRestart(AntaTest): - """Verifies the graceful restart and helper mechanism. + """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 configured. - 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. + 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: - - ISIS is configured on the device. - - Specified VRF is configured. - - Specified VRF instance is found + - 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: - - ISIS is not configured on the device. - - Specified VRF is not configured. - - Specified VRF instance is not found. + - 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 @@ -777,12 +774,11 @@ class VerifyISISGracefulRestart(AntaTest): 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)] + commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show isis summary vrf all")] class Input(AntaTest.Input): """Input model for the VerifyISISGracefulRestart test.""" @@ -797,22 +793,19 @@ def test(self) -> None: command_output = self.instance_commands[0].json_output isis_details = command_output.get("vrfs") - # If ISIS is not configured, test fails + # 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. + # If ISIS-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: + if (instance_details := get_value(isis_details, f"{vrf}.isisInstances.{instance_name}")) is None: self.result.is_failure(f"{instance} - Not found") continue diff --git a/examples/tests.yaml b/examples/tests.yaml index 440456bbe..6b3be4985 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -542,7 +542,7 @@ anta.tests.routing.generic: maximum: 20 anta.tests.routing.isis: - VerifyISISGracefulRestart: - # Verifies the graceful restart and helper mechanism. + # Verifies the graceful restart and helper mechanism. instances: - vrf: default name: '1' @@ -560,7 +560,6 @@ anta.tests.routing.isis: name: '2' graceful_restart: True graceful_helper: True - - VerifyISISInterfaceMode: # Verifies interface mode for IS-IS interfaces: diff --git a/tests/units/anta_tests/routing/test_isis.py b/tests/units/anta_tests/routing/test_isis.py index 06740a42f..d27e075c2 100644 --- a/tests/units/anta_tests/routing/test_isis.py +++ b/tests/units/anta_tests/routing/test_isis.py @@ -1879,19 +1879,12 @@ "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"]}, + "expected": {"result": "failure", "messages": ["Instance: 1 VRF: default - Not found"]}, }, { "name": "failure-graceful-restart-disabled", @@ -1924,10 +1917,7 @@ }, "expected": { "result": "failure", - "messages": [ - "VRF: default Instance: 1 - Graceful Restart disabled", - "VRF: test Instance: 1 - Graceful Restart disabled", - ], + "messages": ["Instance: 1 VRF: default - Graceful Restart disabled", "Instance: 1 VRF: test - Graceful Restart disabled"], }, }, { @@ -1949,7 +1939,7 @@ }, "expected": { "result": "failure", - "messages": ["VRF: default Instance: 1 - Graceful Restart Helper disabled", "VRF: test Instance: 1 - Graceful Restart Helper disabled"], + "messages": ["Instance: 1 VRF: default - Graceful Restart Helper disabled", "Instance: 1 VRF: test - Graceful Restart Helper disabled"], }, }, ]