Adding upstream version 1.1.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
f13b7abbd8
commit
77504588ab
196 changed files with 10121 additions and 3780 deletions
|
@ -1,12 +1,52 @@
|
|||
# ANTA Example files
|
||||
|
||||
This section provides some examples about how to use ANTA as listed in [the documentation](https://anta.arista.com).
|
||||
|
||||
## Device Inventory
|
||||
|
||||
- Filename: [`inventory.yaml`](./inventory.yaml)
|
||||
|
||||
The file [inventory.yaml](inventory.yaml) is an example of [device inventory](https://anta.arista.com/stable/usage-inventory-catalog/#create-an-inventory-file).
|
||||
|
||||
## Test Catalog
|
||||
|
||||
- Filename: [`tests.yaml`](./tests.yaml)
|
||||
|
||||
The file [tests.yaml](tests.yaml) is an example of a [test catalog](https://anta.arista.com/stable/usage-inventory-catalog/#test-catalog).
|
||||
This file should contain all the tests implemented in [anta.tests](../anta/tests) with arbitrary parameters.
|
||||
|
||||
## eos-commands.yaml file
|
||||
## Commands to get from snapshot
|
||||
|
||||
- Filename: [`eos-commands.yaml file`](./eos-commands.yaml)
|
||||
|
||||
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://anta.arista.com/stable/cli/exec/#collect-a-set-of-commands) command.
|
||||
|
||||
## ANTA runner in Python
|
||||
|
||||
- Filename: [`anta_runner.py`](./anta_runner.py)
|
||||
|
||||
The file is an example demonstrating how to run ANTA using a Python script.
|
||||
|
||||
## ANTA template for results rendering
|
||||
|
||||
- Filename: [`template.j2`](./template.j2)
|
||||
|
||||
This file is a simple Jinja2 file to customize ANTA CLI output as documented in [cli documentation](https://anta.arista.com/stable/cli/nrfu/#performing-nrfu-with-custom-reports).
|
||||
|
||||
## Merge multiple catalogs
|
||||
|
||||
- Filename: [`merge_catalogs.py`](./merge_catalogs.py)
|
||||
|
||||
This file is an example demonstrating how to merge multiple catalogs into a single catalog and save it to a file, as documented in [usage test catalog](https://anta.arista.com/stable/usage-inventory-catalog/#example-script-to-merge-catalogs).
|
||||
|
||||
## Run multiple commands
|
||||
|
||||
- Filename: [`run_eos_commands.py`](./run_eos_commands.py)
|
||||
|
||||
This file is an example demonstrating how to run multiple commands on multiple devices, as documented in [advanced usages](https://anta.arista.com/stable/advanced_usages/as-python-lib/#run-eos-commands).
|
||||
|
||||
## Parse ANTA inventory file
|
||||
|
||||
- Filename: [`parse_anta_inventory_file.py`](./parse_anta_inventory_file.py)
|
||||
|
||||
This file is an example demonstrating how to parse an ANTA inventory file, as documented in [advanced usages](https://anta.arista.com/stable/advanced_usages/as-python-lib/#parse-anta-inventory-file).
|
30
examples/merge_catalogs.py
Normal file
30
examples/merge_catalogs.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2024 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the LICENSE file.
|
||||
"""Script that merge a collection of catalogs into one AntaCatalog."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from anta.catalog import AntaCatalog
|
||||
from anta.models import AntaTest
|
||||
|
||||
CATALOG_SUFFIX = "-catalog.yml"
|
||||
CATALOG_DIR = "intended/test_catalogs/"
|
||||
|
||||
if __name__ == "__main__":
|
||||
catalogs = []
|
||||
for file in Path(CATALOG_DIR).glob("*" + CATALOG_SUFFIX):
|
||||
device = str(file).removesuffix(CATALOG_SUFFIX).removeprefix(CATALOG_DIR)
|
||||
print(f"Loading test catalog for device {device}")
|
||||
catalog = AntaCatalog.parse(file)
|
||||
# Add the device name as a tag to all tests in the catalog
|
||||
for test in catalog.tests:
|
||||
test.inputs.filters = AntaTest.Input.Filters(tags={device})
|
||||
catalogs.append(catalog)
|
||||
|
||||
# Merge all catalogs
|
||||
merged_catalog = AntaCatalog.merge_catalogs(catalogs)
|
||||
|
||||
# Save the merged catalog to a file
|
||||
with Path("anta-catalog.yml").open("w") as f:
|
||||
f.write(merged_catalog.dump().yaml())
|
34
examples/parse_anta_inventory_file.py
Normal file
34
examples/parse_anta_inventory_file.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Copyright (c) 2024 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the LICENSE file.
|
||||
"""Script that parses an ANTA inventory file, connects to devices and print their status."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from anta.inventory import AntaInventory
|
||||
|
||||
|
||||
async def main(inv: AntaInventory) -> None:
|
||||
"""Read an AntaInventory and try to connect to every device in the inventory.
|
||||
|
||||
Print a message for every device connection status
|
||||
"""
|
||||
await inv.connect_inventory()
|
||||
|
||||
for device in inv.values():
|
||||
if device.established:
|
||||
print(f"Device {device.name} is online")
|
||||
else:
|
||||
print(f"Could not connect to device {device.name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create the AntaInventory instance
|
||||
inventory = AntaInventory.parse(
|
||||
filename="inventory.yaml",
|
||||
username="arista",
|
||||
password="@rista123",
|
||||
)
|
||||
|
||||
# Run the main coroutine
|
||||
res = asyncio.run(main(inventory))
|
59
examples/run_eos_commands.py
Normal file
59
examples/run_eos_commands.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Copyright (c) 2024 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the LICENSE file.
|
||||
"""Script that runs a list of EOS commands on reachable devices."""
|
||||
|
||||
# This is needed to run the script for python < 3.10 for typing annotations
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pprint import pprint
|
||||
|
||||
from anta.inventory import AntaInventory
|
||||
from anta.models import AntaCommand
|
||||
|
||||
|
||||
async def main(inv: AntaInventory, commands: list[str]) -> dict[str, list[AntaCommand]]:
|
||||
"""Run a list of commands against each valid device in the inventory.
|
||||
|
||||
Take an AntaInventory and a list of commands as string
|
||||
1. try to connect to every device in the inventory
|
||||
2. collect the results of the commands from each device
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict[str, list[AntaCommand]]
|
||||
a dictionary where key is the device name and the value is the list of AntaCommand ran towards the device
|
||||
"""
|
||||
await inv.connect_inventory()
|
||||
|
||||
# Make a list of coroutine to run commands towards each connected device
|
||||
coros = []
|
||||
# dict to keep track of the commands per device
|
||||
result_dict = {}
|
||||
for name, device in inv.get_inventory(established_only=True).items():
|
||||
anta_commands = [AntaCommand(command=command, ofmt="json") for command in commands]
|
||||
result_dict[name] = anta_commands
|
||||
coros.append(device.collect_commands(anta_commands))
|
||||
|
||||
# Run the coroutines
|
||||
await asyncio.gather(*coros)
|
||||
|
||||
return result_dict
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create the AntaInventory instance
|
||||
inventory = AntaInventory.parse(
|
||||
filename="inventory.yaml",
|
||||
username="arista",
|
||||
password="@rista123",
|
||||
)
|
||||
|
||||
# Create a list of commands with json output
|
||||
command_list = ["show version", "show ip bgp summary"]
|
||||
|
||||
# Run the main asyncio entry point
|
||||
res = asyncio.run(main(inventory, command_list))
|
||||
|
||||
pprint(res)
|
|
@ -83,10 +83,21 @@ anta.tests.bfd:
|
|||
multiplier: 3
|
||||
- VerifyBFDPeersHealth:
|
||||
down_threshold: 2
|
||||
- VerifyBFDPeersRegProtocols:
|
||||
bfd_peers:
|
||||
- peer_address: 192.0.255.8
|
||||
vrf: default
|
||||
protocols:
|
||||
- bgp
|
||||
- isis
|
||||
|
||||
anta.tests.configuration:
|
||||
- VerifyZeroTouch:
|
||||
- VerifyRunningConfigDiffs:
|
||||
- VerifyRunningConfigLines:
|
||||
regex_patterns:
|
||||
- "^enable password.*$"
|
||||
- "bla bla"
|
||||
|
||||
anta.tests.connectivity:
|
||||
- VerifyReachability:
|
||||
|
@ -94,9 +105,13 @@ anta.tests.connectivity:
|
|||
- source: Management1
|
||||
destination: 1.1.1.1
|
||||
vrf: MGMT
|
||||
df_bit: True
|
||||
size: 100
|
||||
- source: Management1
|
||||
destination: 8.8.8.8
|
||||
vrf: MGMT
|
||||
df_bit: True
|
||||
size: 100
|
||||
- VerifyLLDPNeighbors:
|
||||
neighbors:
|
||||
- port: Ethernet1
|
||||
|
@ -110,6 +125,21 @@ anta.tests.field_notices:
|
|||
- VerifyFieldNotice44Resolution:
|
||||
- VerifyFieldNotice72Resolution:
|
||||
|
||||
anta.tests.flow_tracking:
|
||||
- VerifyHardwareFlowTrackerStatus:
|
||||
trackers:
|
||||
- name: FLOW-TRACKER
|
||||
record_export:
|
||||
on_inactive_timeout: 700000
|
||||
on_interval: 3000000
|
||||
exporters:
|
||||
- name: CV-TELEMETRY
|
||||
local_interface: Loopback11
|
||||
template_interval: 3600
|
||||
- name: CVP-TELEMETRY
|
||||
local_interface: Loopback01
|
||||
template_interval: 36000000
|
||||
|
||||
anta.tests.greent:
|
||||
- VerifyGreenT:
|
||||
- VerifyGreenTCounters:
|
||||
|
@ -191,6 +221,12 @@ anta.tests.interfaces:
|
|||
- name: Eth2
|
||||
auto: False
|
||||
speed: 2.5
|
||||
- VerifyLACPInterfacesStatus:
|
||||
interfaces:
|
||||
- name: Ethernet5
|
||||
portchannel: Port-Channel5
|
||||
- name: Ethernet6
|
||||
portchannel: Port-Channel5
|
||||
|
||||
anta.tests.lanz:
|
||||
- VerifyLANZ:
|
||||
|
@ -324,6 +360,7 @@ anta.tests.security:
|
|||
destination_address: 100.64.2.2
|
||||
- source_address: 172.18.3.2
|
||||
destination_address: 172.18.2.2
|
||||
- VerifyHardwareEntropy:
|
||||
|
||||
anta.tests.services:
|
||||
- VerifyHostname:
|
||||
|
@ -361,6 +398,13 @@ anta.tests.snmp:
|
|||
location: New York
|
||||
- VerifySnmpContact:
|
||||
contact: Jon@example.com
|
||||
- VerifySnmpPDUCounters:
|
||||
pdus:
|
||||
- outTrapPdus
|
||||
- VerifySnmpErrorCounters:
|
||||
error_counters:
|
||||
- inVersionErrs
|
||||
- inBadCommunityNames
|
||||
|
||||
anta.tests.software:
|
||||
- VerifyEOSVersion:
|
||||
|
@ -390,6 +434,8 @@ anta.tests.stp:
|
|||
instances:
|
||||
- 10
|
||||
- 20
|
||||
- VerifyStpTopologyChanges:
|
||||
threshold: 10
|
||||
|
||||
anta.tests.stun:
|
||||
- VerifyStunClient:
|
||||
|
@ -402,6 +448,7 @@ anta.tests.stun:
|
|||
public_address: 100.64.3.21
|
||||
source_port: 4500
|
||||
public_port: 6006
|
||||
- VerifyStunServer:
|
||||
|
||||
anta.tests.system:
|
||||
- VerifyUptime:
|
||||
|
@ -413,6 +460,15 @@ anta.tests.system:
|
|||
- VerifyMemoryUtilization:
|
||||
- VerifyFileSystemUtilization:
|
||||
- VerifyNTP:
|
||||
- VerifyNTPAssociations:
|
||||
ntp_servers:
|
||||
- server_address: 1.1.1.1
|
||||
preferred: True
|
||||
stratum: 1
|
||||
- server_address: 2.2.2.2
|
||||
stratum: 1
|
||||
- server_address: 3.3.3.3
|
||||
stratum: 1
|
||||
|
||||
anta.tests.vlan:
|
||||
- VerifyVlanInternalPolicy:
|
||||
|
@ -505,6 +561,7 @@ anta.tests.routing:
|
|||
bgp_peers:
|
||||
- peer_address: 172.30.11.1
|
||||
vrf: default
|
||||
strict: False
|
||||
capabilities:
|
||||
- ipv4Unicast
|
||||
- VerifyBGPPeerASNCap:
|
||||
|
@ -543,6 +600,36 @@ anta.tests.routing:
|
|||
vrf: default
|
||||
hold_time: 180
|
||||
keep_alive_time: 60
|
||||
- VerifyBGPPeerDropStats:
|
||||
bgp_peers:
|
||||
- peer_address: 10.101.0.4
|
||||
vrf: default
|
||||
drop_stats:
|
||||
- inDropAsloop
|
||||
- inDropClusterIdLoop
|
||||
- inDropMalformedMpbgp
|
||||
- inDropOrigId
|
||||
- inDropNhLocal
|
||||
- inDropNhAfV6
|
||||
- VerifyBGPPeerUpdateErrors:
|
||||
bgp_peers:
|
||||
- peer_address: 10.100.0.8
|
||||
vrf: default
|
||||
update_errors:
|
||||
- inUpdErrWithdraw
|
||||
- inUpdErrIgnore
|
||||
- VerifyBgpRouteMaps:
|
||||
bgp_peers:
|
||||
- peer_address: 10.100.4.1
|
||||
vrf: default
|
||||
inbound_route_map: RM-MLAG-PEER-IN
|
||||
outbound_route_map: RM-MLAG-PEER-IN
|
||||
- VerifyBGPPeerRouteLimit:
|
||||
bgp_peers:
|
||||
- peer_address: 10.100.0.8
|
||||
vrf: default
|
||||
maximum_routes: 12000
|
||||
warning_limit: 10000
|
||||
ospf:
|
||||
- VerifyOSPFNeighborState:
|
||||
- VerifyOSPFNeighborCount:
|
||||
|
@ -573,4 +660,31 @@ anta.tests.routing:
|
|||
- name: Ethernet1
|
||||
mode: point-to-point
|
||||
vrf: default
|
||||
# level is set to 2 by default
|
||||
# level is set to 2 by default
|
||||
- VerifyISISSegmentRoutingAdjacencySegments:
|
||||
instances:
|
||||
- name: CORE-ISIS
|
||||
vrf: default
|
||||
segments:
|
||||
- interface: Ethernet2
|
||||
address: 10.0.1.3
|
||||
sid_origin: dynamic
|
||||
- VerifyISISSegmentRoutingDataplane:
|
||||
instances:
|
||||
- name: CORE-ISIS
|
||||
vrf: default
|
||||
dataplane: MPLS
|
||||
- VerifyISISSegmentRoutingTunnels:
|
||||
entries:
|
||||
# Check only endpoint
|
||||
- endpoint: 1.0.0.122/32
|
||||
# Check endpoint and via TI-LFA
|
||||
- endpoint: 1.0.0.13/32
|
||||
vias:
|
||||
- type: tunnel
|
||||
tunnel_id: ti-lfa
|
||||
# Check endpoint and via IP routers
|
||||
- endpoint: 1.0.0.14/32
|
||||
vias:
|
||||
- type: ip
|
||||
nexthop: 1.1.1.1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue