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

@ -1,4 +1,4 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Copyright (c) 2023-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.
"""Tests for inventory submodule."""

View file

@ -1,11 +1,11 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Copyright (c) 2023-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.
"""ANTA Inventory unit tests."""
from __future__ import annotations
from pathlib import Path
import logging
from typing import TYPE_CHECKING
import pytest
@ -15,11 +15,10 @@ from anta.inventory import AntaInventory
from anta.inventory.exceptions import InventoryIncorrectSchemaError, InventoryRootKeyError
if TYPE_CHECKING:
from pathlib import Path
from _pytest.mark.structures import ParameterSet
FILE_DIR: Path = Path(__file__).parent.parent.resolve() / "data" / "inventory"
INIT_VALID_PARAMS: list[ParameterSet] = [
pytest.param(
{"anta_inventory": {"hosts": [{"host": "192.168.0.17"}, {"host": "192.168.0.2"}, {"host": "my.awesome.host.com"}]}},
@ -76,3 +75,15 @@ class TestAntaInventory:
"""Parse invalid YAML file to create ANTA inventory."""
with pytest.raises((InventoryIncorrectSchemaError, InventoryRootKeyError, ValidationError)):
AntaInventory.parse(filename=yaml_file, username="arista", password="arista123")
def test_parse_wrong_format(self) -> None:
"""Use wrong file format to parse the ANTA inventory."""
with pytest.raises(ValueError, match=" is not a valid format for an AntaInventory file. Only 'yaml' and 'json' are supported."):
AntaInventory.parse(filename="dummy.yml", username="arista", password="arista123", file_format="wrong") # type: ignore[arg-type]
def test_parse_os_error(self, caplog: pytest.LogCaptureFixture) -> None:
"""Use wrong file name to parse the ANTA inventory."""
caplog.set_level(logging.INFO)
with pytest.raises(OSError, match="No such file or directory"):
_ = AntaInventory.parse(filename="dummy.yml", username="arista", password="arista123")
assert "Unable to parse ANTA Device Inventory file" in caplog.records[0].message

View file

@ -1,20 +1,25 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Copyright (c) 2023-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.
"""ANTA Inventory models unit tests."""
from __future__ import annotations
import json
from pathlib import Path
from typing import TYPE_CHECKING, Any
import pytest
from pydantic import ValidationError
from yaml import safe_load
from anta.inventory.models import AntaInventoryHost, AntaInventoryNetwork, AntaInventoryRange
from anta.inventory.models import AntaInventoryHost, AntaInventoryInput, AntaInventoryNetwork, AntaInventoryRange
if TYPE_CHECKING:
from _pytest.mark.structures import ParameterSet
FILE_DIR: Path = Path(__file__).parents[2] / "data"
INVENTORY_HOST_VALID_PARAMS: list[ParameterSet] = [
pytest.param(None, "1.1.1.1", None, None, None, id="IPv4"),
pytest.param(None, "fe80::cc62:a9ff:feef:932a", None, None, None, id="IPv6"),
@ -164,3 +169,33 @@ class TestAntaInventoryRange:
"""Invalid model parameters."""
with pytest.raises(ValidationError):
AntaInventoryRange.model_validate({"start": start, "end": end, "tags": tags, "disable_cache": disable_cache})
class TestAntaInventoryInputs:
"""Test anta.inventory.models.AntaInventoryInputs."""
def test_dump_to_json(self) -> None:
"""Load a YAML file, dump it to JSON and verify it works."""
input_yml_path = FILE_DIR / "test_inventory_with_tags.yml"
expected_json_path = FILE_DIR / "test_inventory_with_tags.json"
with input_yml_path.open("r") as f:
data = safe_load(f)
anta_inventory_input = AntaInventoryInput(**data["anta_inventory"])
with expected_json_path.open("r") as f:
expected_data = json.load(f)
assert anta_inventory_input.to_json() == json.dumps(expected_data["anta_inventory"], indent=2)
def test_dump_to_yaml(self) -> None:
"""Load a JSON file, dump it to YAML and verify it works."""
input_json_path = FILE_DIR / "test_inventory_medium.json"
expected_yml_path = FILE_DIR / "test_inventory_medium.yml"
with input_json_path.open("r") as f:
data = json.load(f)
anta_inventory_input = AntaInventoryInput(**data["anta_inventory"])
with expected_yml_path.open("r") as f:
expected_data = safe_load(f)
assert safe_load(anta_inventory_input.yaml()) == expected_data["anta_inventory"]