Skip to content

Commit

Permalink
Feat: add anta_test decorator (#123)
Browse files Browse the repository at this point in the history
* Feat: add anta_test decorator

* WIP

* Refactor: Make all tests use the anta_test decorator

* CI: Add isort

* CI: Fix implicit optional for mypy

* Fix: Make linters happy again post rebase
  • Loading branch information
gmuloc committed Dec 14, 2022
1 parent cbc6091 commit 5b16412
Show file tree
Hide file tree
Showing 40 changed files with 1,548 additions and 1,652 deletions.
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ repos:
- --config=/dev/null
- --max-line-length=165

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: Check for changes when running isort on all python files

- repo: local # as per https://pylint.pycqa.org/en/latest/user_guide/installation/pre-commit-integration.html
hooks:
- id: pylint
Expand All @@ -38,7 +44,7 @@ repos:
- --rcfile=pylintrc # Link to config file

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v0.991
hooks:
- id: mypy
args:
Expand Down
18 changes: 14 additions & 4 deletions anta/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,21 @@ def wrapper(*args: List[Any], **kwargs: Dict[str, Any]) -> TestResult:
"""
device = args[0]
eapi_command = "show bgp ipv4 unicast summary vrf all"
eapi_command = "show bgp ipv6 unicast summary vrf all" if family == "ipv6" else eapi_command
eapi_command = (
"show bgp ipv6 unicast summary vrf all"
if family == "ipv6"
else eapi_command
)
eapi_command = "show bgp evpn summary" if family == "evpn" else eapi_command
eapi_command = "show bgp rt-membership summary" if family == "rtc" else eapi_command
eapi_command = (
"show bgp rt-membership summary" if family == "rtc" else eapi_command
)

result = TestResult(host=str(device.host), test=function.__name__) # type: ignore
try:
response = device.session.runCmds( # type: ignore
1, [eapi_command], "json") # type: ignore
1, [eapi_command], "json"
) # type: ignore

if "vrfs" not in response[0].keys():
result.is_skipped(
Expand All @@ -83,7 +90,10 @@ def wrapper(*args: List[Any], **kwargs: Dict[str, Any]) -> TestResult:
)
return result
bgp_vrfs = response[0]["vrfs"]
if len(bgp_vrfs) == 0 or len(response[0]["vrfs"]["default"]["peers"]) == 0:
if (
len(bgp_vrfs) == 0
or len(response[0]["vrfs"]["default"]["peers"]) == 0
):
# No VRF
result.is_skipped(
# type: ignore
Expand Down

0 comments on commit 5b16412

Please sign in to comment.