Adding upstream version 1.3.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-17 07:33:45 +01:00
parent 6fd6eb426a
commit dc7df702ea
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
337 changed files with 16571 additions and 4891 deletions

View file

@ -0,0 +1,7 @@
# Copyright (c) 2024-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.
"""Integration tests for ANTA.
In particular this module test the examples/*.py scripts to make sure they are still working.
"""

View file

@ -0,0 +1,5 @@
---
anta.tests.software:
- VerifyEOSVersion:
versions:
- 4.31.1F

View file

@ -0,0 +1,5 @@
---
anta.tests.software:
- VerifyEOSVersion:
versions:
- 4.31.2F

View file

@ -0,0 +1,5 @@
---
anta.tests.software:
- VerifyEOSVersion:
versions:
- 4.31.3F

View file

@ -0,0 +1,40 @@
# Copyright (c) 2024-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.
"""Test examples/merge_catalogs.py script."""
from __future__ import annotations
import runpy
from pathlib import Path
from anta.catalog import AntaCatalog
DATA = Path(__file__).parent / "data"
MERGE_CATALOGS_PATH = Path(__file__).parents[2] / "examples/merge_catalogs.py"
def test_merge_catalogs() -> None:
"""Test merge_catalogs script."""
# Adding symlink to match the script data
intended_path = Path.cwd() / "intended"
intended_path.mkdir(exist_ok=True)
intended_catalogs_path = intended_path / "test_catalogs/"
intended_catalogs_path.symlink_to(DATA, target_is_directory=True)
try:
# Run the script
runpy.run_path(str(MERGE_CATALOGS_PATH), run_name="__main__")
# Assert that the created file exist and is a combination of the inputs
output_catalog = Path("anta-catalog.yml")
assert output_catalog.exists()
total_tests = sum(len(AntaCatalog.parse(catalog_file).tests) for catalog_file in DATA.rglob("*-catalog.yml"))
assert total_tests == len(AntaCatalog.parse(output_catalog).tests)
finally:
# Cleanup
output_catalog.unlink()
intended_catalogs_path.unlink()
intended_path.rmdir()

View file

@ -0,0 +1,40 @@
# Copyright (c) 2024-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.
"""Test examples/parse_anta_inventory_file.py script."""
from __future__ import annotations
import runpy
from pathlib import Path
import pytest
from yaml import safe_dump
from anta.inventory import AntaInventory
DATA = Path(__file__).parent / "data"
PARSE_ANTA_INVENTORY_FILE_PATH = Path(__file__).parents[2] / "examples/parse_anta_inventory_file.py"
@pytest.mark.parametrize("inventory", [{"count": 3}], indirect=["inventory"])
def test_parse_anta_inventory_file(capsys: pytest.CaptureFixture[str], inventory: AntaInventory) -> None:
"""Test parse_anta_inventory_file script."""
# Create the inventory.yaml file expected by the script
# TODO: 2.0.0 this is horrendous - need to align how to dump things properly
inventory_path = Path.cwd() / "inventory.yaml"
yaml_data = {AntaInventory.INVENTORY_ROOT_KEY: inventory.dump().model_dump()}
with inventory_path.open("w") as f:
safe_dump(yaml_data, f)
try:
# Run the script
runpy.run_path(str(PARSE_ANTA_INVENTORY_FILE_PATH), run_name="__main__")
captured = capsys.readouterr()
assert "Device device-0 is online" in captured.out
assert "Device device-1 is online" in captured.out
assert "Device device-2 is online" in captured.out
finally:
# Cleanup
inventory_path.unlink()

View file

@ -0,0 +1,52 @@
# Copyright (c) 2024-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.
"""Test examples/run_eos_commands.py script."""
from __future__ import annotations
import runpy
from pathlib import Path
import pytest
import respx
from yaml import safe_dump
from anta.inventory import AntaInventory
DATA = Path(__file__).parent / "data"
RUN_EOS_COMMANDS_PATH = Path(__file__).parents[2] / "examples/run_eos_commands.py"
@pytest.mark.parametrize("inventory", [{"count": 3}], indirect=["inventory"])
def test_run_eos_commands(capsys: pytest.CaptureFixture[str], inventory: AntaInventory) -> None:
"""Test run_eos_commands script."""
# Create the inventory.yaml file expected by the script
# TODO: 2.0.0 this is horrendous - need to align how to dump things properly
inventory_path = Path.cwd() / "inventory.yaml"
yaml_data = {AntaInventory.INVENTORY_ROOT_KEY: inventory.dump().model_dump()}
with inventory_path.open("w") as f:
safe_dump(yaml_data, f)
try:
respx.post(path="/command-api", headers={"Content-Type": "application/json-rpc"}, json__params__cmds__0__cmd="show ip bgp summary").respond(
json={
"result": [
{
"mocked": "mock",
}
],
}
)
# Run the script
runpy.run_path(str(RUN_EOS_COMMANDS_PATH), run_name="__main__")
captured = capsys.readouterr()
# This is only to make sure we get the expected output - what counts is that the script runs.
assert "'device-0': [AntaCommand(command='show version', version='latest', revision=None, ofmt='json', output={'modelName': 'pytest'}," in captured.out
assert "'device-1': [AntaCommand(command='show version', version='latest', revision=None, ofmt='json', output={'modelName': 'pytest'}," in captured.out
assert "'device-2': [AntaCommand(command='show version', version='latest', revision=None, ofmt='json', output={'modelName': 'pytest'}," in captured.out
assert "AntaCommand(command='show ip bgp summary', version='latest', revision=None, ofmt='json', output={'mocked': 'mock'}, " in captured.out
finally:
# Cleanup
inventory_path.unlink()