8000 doc(anta.tests): update examples folder by mtache · Pull Request #215 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

doc(anta.tests): update examples folder #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions anta/tests/field_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VerifyFieldNotice44Resolution(AntaTest):
commands = [AntaTestCommand(command="show version detail")]

# TODO maybe implement ONLY ON PLATFORMS instead
@skip_on_platforms(["cEOSLab"])
@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self) -> None: # type: ignore[override]
"""Run VerifyFieldNotice44Resolution validation"""
Expand Down Expand Up @@ -116,7 +116,7 @@ class VerifyFieldNotice72Resolution(AntaTest):
commands = [AntaTestCommand(command="show version detail")]

# TODO maybe implement ONLY ON PLATFORMS instead
@skip_on_platforms(["cEOSLab"])
@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self) -> None: # type: ignore[override]
"""Run VerifyFieldNotice72Resolution validation"""
Expand Down
26 changes: 21 additions & 5 deletions anta/tests/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ class VerifyTransceiversManufacturers(AntaTest):
@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self, manufacturers: Optional[List[str]] = None) -> None:
"""Run VerifyTransceiversManufacturers validation"""
"""
Run VerifyTransceiversManufacturers validation

Args:
manufacturers: List of allowed transceivers manufacturers.
"""
if not manufacturers:
self.result.is_skipped(f"{self.__class__.name} was not run as no manufacturers were given")
else:
Expand Down Expand Up @@ -129,7 +134,12 @@ class VerifyEnvironmentCooling(AntaTest):
@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self, accepted_states: Optio 8000 nal[List[str]] = None) -> None:
"""Run VerifyEnvironmentCooling validation"""
"""
Run VerifyEnvironmentCooling validation

Args:
accepted_states: Accepted states list for fan status
"""
if accepted_states is None:
accepted_states = ["ok"]

Expand All @@ -153,20 +163,25 @@ def test(self, accepted_states: Optional[List[str]] = None) -> None:

class VerifyEnvironmentPower(AntaTest):
"""
Verifies the power supplied status is in the accepted states list
Verifies the power supplies status is in the accepted states list

The default accepted states list is ['ok']
"""

name = "VerifyEnvironmentPower"
description = "Verifies the power supplied status is OK"
description = "Verifies the power supplies status is OK"
categories = ["hardware"]
commands = [AntaTestCommand(command="show system environment power", ofmt="json")]

@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self, accepted_states: Optional[List[str]] = None) -> None:
"""Run VerifyEnvironmentPower validation"""
"""
Run VerifyEnvironmentPower validation

Args:
accepted_states: Accepted states list for power supplies
"""
if accepted_states is None:
accepted_states = ["ok"]
command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[0].output)
Expand All @@ -191,6 +206,7 @@ class VerifyAdverseDrops(AntaTest):
categories = ["hardware"]
commands = [AntaTestCommand(command="show hardware counter drop", ofmt="json")]

@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self) -> None:
&quo 8000 t;""Run VerifyAdverseDrops validation"""
Expand Down
22 changes: 16 additions & 6 deletions anta/tests/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test functions related to the device interfaces
"""
import re
from typing import Any, Dict, List, cast
from typing import Any, Dict, List, Optional, cast

from anta.decorators import skip_on_platforms
from anta.models import AntaTest, AntaTestCommand
Expand Down Expand Up @@ -131,8 +131,13 @@ class VerifyInterfacesStatus(AntaTest):
commands = [AntaTestCommand(command="show interfaces description")]

@AntaTest.anta_test
def test(self, minimum: int = -1) -> None: # type: ignore[override]
"""Run VerifyInterfacesStatus validation"""
def test(self, minimum: Optional[int] = None) -> None:
"""
Run VerifyInterfacesStatus validation

Args:
minimum: Expected minimum number of Ethernet interfaces up/up.
"""

if minimum is None or minimum < 0:
self.result.is_skipped(f"VerifyInterfacesStatus was not run as an invalid minimum value was given {minimum}.")
Expand Down Expand Up @@ -255,10 +260,15 @@ class VerifyLoopbackCount(AntaTest):
commands = [AntaTestCommand(command="show ip interface brief")]

@AntaTest.anta_test
def test(self, number: int = -1) -> None:
"""Run VerifyLoopbackCount validation"""
def test(self, number: Optional[int] = None) -> None:
"""
Run VerifyLoopbackCount validation

Args:
number: Number of loopback interfaces expected to be present.
"""

if number is None or number < 0:
if number is None:
self.result.is_skipped("VerifyLoopbackCount was not run as no number value was given.")
return

Expand Down
19 changes: 15 additions & 4 deletions anta/tests/multicast.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ class VerifyIGMPSnoopingVlans(AntaTest):
commands = [AntaTestCommand(command="show ip igmp snooping")]

@AntaTest.anta_test
def test(self, vlans: Optional[List[str]] = None, configuration: str = "") -> None:
"""Run VerifyIGMPSnoopingVlans validation"""
def test(self, vlans: Optional[List[str]] = None, configuration: Optional[str] = None) -> None:
"""
Run VerifyIGMPSnoopingVlans validation

Args:
vlans: List of VLANs.
configuration: Expected IGMP configuration (enabled or disabled) for these VLANs.
"""

if not vlans or not configuration:
self.result.is_skipped("VerifyIGMPSnoopingVlans was not run as no vlans or configuration was given")
Expand Down Expand Up @@ -62,8 +68,13 @@ class VerifyIGMPSnoopingGlobal(AntaTest):
commands = [AntaTestCommand(command="show ip igmp snooping")]

@AntaTest.anta_test
def test(self, configuration: str = "") -> None:
"""Run VerifyIGMPSnoopingGlobal validation"""
def test(self, configuration: Optional[str] = None) -> None:
"""
Run VerifyIGMPSnoopingGlobal validation

Args:
configuration: Expected global IGMP configuration (enabled or disabled).
"""

if not configuration:
self.result.is_skipped("VerifyIGMPSnoopingGlobal was not run as no configuration was given")
Expand Down
18 changes: 15 additions & 3 deletions anta/tests/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test functions related to ASIC profiles
"""
import logging
from typing import Any, Dict, cast
from typing import Any, Dict, Optional, cast

from anta.decorators import skip_on_platforms
from anta.models import AntaTest, AntaTestCommand
Expand All @@ -22,7 +22,13 @@ class VerifyUnifiedForwardingTableMode(AntaTest):

@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self, mode: Any = None) -> None:
def test(self, mode: Optional[str] = None) -> None:
"""
Run VerifyUnifiedForwardingTableMode validation

Args:
mode: Expected UFT mode.
"""
if not mode:
self.result.is_skipped("verify_unified_forwarding_table_mode was not run as no mode was given")
return
Expand All @@ -46,7 +52,13 @@ class VerifyTcamProfile(AntaTest):

@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self, profile: Any = None) -> None:
def test(self, profile: Optional[str] = None) -> None:
"""
Run VerifyTcamProfile validation

Args:
profile: Expected TCAM profile.
"""
if not profile:
self.result.is_skipped("verify_tcam_profile was not run as no profile was given")
return
Expand Down
22 changes: 19 additions & 3 deletions anta/tests/routing/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ class VerifyBGPIPv4UnicastCount(AntaTest):
@check_bgp_family_enable("ipv4")
@AntaTest.anta_test
def test(self, number: Optional[int] = None) -> None:
"""Run VerifyBGPIPv4UnicastCount validation"""
"""
Run VerifyBGPIPv4UnicastCount validation

Args:
number: The expected number of BGP IPv4 unicast neighbors.
vrf: VRF to verify (template parameter)
"""

if not number:
self.result.is_skipped("VerifyBGPIPv4UnicastCount could not run because number was not supplied")
Expand Down Expand Up @@ -193,7 +199,12 @@ class VerifyBGPEVPNCount(AntaTest):
@check_bgp_family_enable("evpn")
@AntaTest.anta_test
def test(self, number: Optional[int] = None) -> None:
"""Run VerifyBGPEVPNCount validation"""
"""
Run VerifyBGPEVPNCount validation

Args:
number: The expected number of BGP EVPN neighbors in the default VRF.
"""
if not number:
self.result.is_skipped("VerifyBGPEVPNCount could not run because number was not supplied.")
return
Expand Down Expand Up @@ -264,7 +275,12 @@ class VerifyBGPRTCCount(AntaTest):
@check_bgp_family_enable("rtc")
@AntaTest.anta_test
def test(self, number: Optional[int] = None) -> None:
"""Run VerifyBGPRTCCount validation"""
"""
Run VerifyBGPRTCCount validation

Args:
number: The expected number of BGP RTC neighbors (default VRF).
"""
if not number:
self.result.is_skipped("VerifyBGPRTCCount could not run because number was not supplied")
return
Expand Down
12 changes: 9 additions & 3 deletions anta/tests/software.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class VerifyEOSVersion(AntaTest):

@AntaTest.anta_test
def test(self, versions: Optional[List[str]] = None) -> None:
"""Run VerifyEOSVersion validation
versions (list): List of allowed EOS versions."""
"""
Run VerifyEOSVersion validation

Args:
versions: List of allowed EOS versions.
"""
if not versions:
self.result.is_skipped("VerifyEOSVersion was not run as no versions were given")
return
Expand All @@ -49,7 +53,9 @@ class VerifyTerminAttrVersion(AntaTest):
def test(self, versions: Optional[List[str]] = None) -> None:
"""
Run VerifyTerminAttrVersion validation
versions (list): List of allowed TerminAttr versions.

Args:
versions: List of allowed TerminAttr versions.
"""

if not versions:
Expand Down
10 changes: 6 additions & 4 deletions anta/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import logging
from typing import Any, Dict, List, cast
from typing import Any, Dict, List, Optional, cast

from anta.models import AntaTest, AntaTestCommand

Expand All @@ -22,16 +22,18 @@ class VerifyUptime(AntaTest):
commands = [AntaTestCommand(command="show uptime")]

@AntaTest.anta_test
def test(self, minimum: int = -1) -> None:
def test(self, minimum: Optional[int] = None) -> None:
"""
Run VerifyUptime validation
minimum (int): Minimum uptime in seconds.

Args:
minimum: Minimum uptime in seconds.
"""

command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[0].output)

if not (isinstance(minimum, (int, float))) or minimum < 0:
self.result.is_skipped("VerifyUptime was not run as no minimum uptime was given")
self.result.is_skipped("VerifyUptime was not run as incorrect minimum uptime was given")
return

if cast(float, command_output["upTime"]) > minimum:
Expand Down
15 changes: 7 additions & 8 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# inventory.yml file
## Device Inventory

The file [inventory.yml](inventory.yml) is a devices inventory file.
The file [inventory.yaml](inventory.yaml) is an example of [device inventory](https://www.anta.ninja/usage-inventory-catalog/#create-an-inventory-file).

# eos-commands.yaml file
## Test Catalog

The file [eos-commands.yaml](eos-commands.yaml) is a YAML file used to indicated the list of commands output we would like to collect from devices in text or json format.
The file [tests.yaml](tests.yaml) is an example of a [test catalog](https://www.anta.ninja/usage-inventory-catalog/#test-catalog).
This file should contain all the tests implemented in [anta.tests](../anta/tests) with arbitrary parameters.

# tests file
## eos-commands.yaml file

The file [tests_all.yaml](tests_all.yaml) and [tests_subset.yaml](tests_subset.yaml) are YAML file used to indicated the tests we would like to run.
They are also used to indicated the parameters used by the tests.
The tests are defined in the directory [ANTA](../anta/).
The file [eos-commands.yaml](eos-commands.yaml) is an example of input given with the `--commands-list` option to the [anta exec snapshot](https://www.anta.ninja/cli/exec/#collect-a-set-of-commands) command.
28 changes: 28 additions & 0 deletions examples/inventory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
anta_inventory:
hosts:
- name: spine1
host: clab-evpn-vxlan-fabric-spine1
tags: ['clab', 'spine']
- name: spine2
host: clab-evpn-vxlan-fabric-spine2
tags: ['clab', 'spine']
- name: leaf1
host: clab-evpn-vxlan-fabric-leaf1
tags: ['clab', 'leaf']
- name: leaf2
host: clab-evpn-vxlan-fabric-leaf2
tags: ['clab', 'leaf']
- name: leaf3
host: clab-evpn-vxlan-fabric-leaf3
tags: ['clab', 'leaf']
- name: leaf4
host: clab-evpn-vxlan-fabric-leaf4
tags: ['clab', 'leaf']
networks:
- network: 192.168.110.0/24
ranges:
- start: 10.0.0.9
end: 10.0.0.11
- start: 10.0.0.100
end: 10.0.0.101
22 changes: 0 additions & 22 deletions examples/inventory.yml

This file was deleted.

Loading
0