Skip to content

Commit

Permalink
Issue_882: Updated docstrings and removed VRF check
Browse files Browse the repository at this point in the history
  • Loading branch information
Geetanjali Mane authored and Geetanjali Mane committed Jan 3, 2025
1 parent c2134a0 commit 43516d8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
8 changes: 4 additions & 4 deletions anta/input_models/routing/isis.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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:
Expand All @@ -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}"
29 changes: 11 additions & 18 deletions anta/tests/routing/isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand All @@ -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

Expand Down
3 changes: 1 addition & 2 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -560,7 +560,6 @@ anta.tests.routing.isis:
name: '2'
graceful_restart: True
graceful_helper: True

- VerifyISISInterfaceMode:
# Verifies interface mode for IS-IS
interfaces:
Expand Down
16 changes: 3 additions & 13 deletions tests/units/anta_tests/routing/test_isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"],
},
},
{
Expand All @@ -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"],
},
},
]
Expand Down

0 comments on commit 43516d8

Please sign in to comment.