Skip to content

Commit

Permalink
Feat: Make name and description optional for AntaTests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Sep 30, 2024
1 parent 74b1ff2 commit 928a231
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 9 additions & 1 deletion anta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,19 @@ def save_commands_data(self, eos_data: list[dict[str, Any] | str]) -> None:

def __init_subclass__(cls) -> None:
"""Verify that the mandatory class attributes are defined."""
mandatory_attributes = ["name", "description", "categories", "commands"]
mandatory_attributes = ["categories", "commands"]
for attr in mandatory_attributes:
if not hasattr(cls, attr):
msg = f"Class {cls.__module__}.{cls.__name__} is missing required class attribute {attr}"
raise NotImplementedError(msg)
# default_attributes = ["name", "description"]
if not hasattr(cls, "name"):
cls.name = cls.__name__
if not hasattr(cls, "description"):
if not cls.test.__doc__:
# No doctsring - raise
raise Exception("TODO")
cls.description = cls.test.__doc__.split(sep="\n")[0]

@property
def module(self) -> str:
Expand Down
4 changes: 0 additions & 4 deletions anta/tests/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class VerifyTacacsSourceIntf(AntaTest):
```
"""

name = "VerifyTacacsSourceIntf"
description = "Verifies TACACS source-interface for a specified VRF."
categories: ClassVar[list[str]] = ["aaa"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show tacacs", revision=1)]

Expand Down Expand Up @@ -81,8 +79,6 @@ class VerifyTacacsServers(AntaTest):
```
"""

name = "VerifyTacacsServers"
description = "Verifies TACACS servers are configured for a specified VRF."
categories: ClassVar[list[str]] = ["aaa"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show tacacs", revision=1)]

Expand Down

0 comments on commit 928a231

Please sign in to comment.