Skip to content

Commit

Permalink
CI: Add examples to pytest (aristanetworks#4739)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Mulocher <[email protected]>
  • Loading branch information
ClausHolbechArista and gmuloc authored Nov 18, 2024
1 parent a64df3f commit 7edc69f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 2 deletions.
10 changes: 10 additions & 0 deletions python-avd/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.
from pathlib import Path
from sys import path

# Since the pyavd and schema_tools code it stored a layer deeper than the repo root,
# we need to add it to the path when running pytest from repo root.
# That is relevant when using pytest extensions in IDE (VSCode)
path.insert(0, str(Path(__file__).parents[1]))
17 changes: 15 additions & 2 deletions python-avd/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

REPO_ROOT = Path(__file__).parents[2]
MOLECULE_PATH = REPO_ROOT / "ansible_collections/arista/avd/molecule"
EXAMPLE_PATH = REPO_ROOT / "ansible_collections/arista/avd/examples"


class MoleculeHost:
Expand Down Expand Up @@ -86,12 +87,24 @@ def __init__(self, name: str) -> None:
for each host found in the inventory.
"""
self.name = name
self.path = MOLECULE_PATH / name
self._inventory = InventoryManager(loader=DataLoader(), sources=[(self.path / "inventory/hosts.yml").as_posix()])
if name.startswith("example-"):
# Example paths
self.path = EXAMPLE_PATH / name.removeprefix("example-")
inventory_path = self.path / "inventory.yml"
else:
# Molecule paths
self.path = MOLECULE_PATH / name
inventory_path = self.path / "inventory/hosts.yml"

self._inventory = InventoryManager(loader=DataLoader(), sources=[inventory_path.as_posix()])
self._vars = VariableManager(loader=DataLoader(), inventory=self._inventory)
self.hosts = []
for host in self._inventory.get_hosts():
if self.name.startswith("example-") and host.name in ["cvp", "cloudvision"]:
# Ignore CVP devices in examples without bloating the example without test groups.
continue
if "IGNORE_IN_PYTEST" in [group.name for group in host.groups]:
# Ignore members of the group IGNORE_IN_PYTEST from Molecule scenarios.
continue
self.hosts.append(MoleculeHost(name=host.name, ansible_host=host, scenario=self))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"evpn_underlay_isis_overlay_ibgp",
"evpn_underlay_ospf_overlay_ebgp",
"evpn_underlay_rfc5549_overlay_ebgp",
"example-campus-fabric",
# TODO: "example-cv-pathfinder", # Work around Ansible vault
"example-dual-dc-l3ls",
"example-isis-ldp-ipvpn",
"example-l2ls-fabric",
"example-single-dc-l3ls",
)
def test_get_avd_facts(molecule_scenario: MoleculeScenario) -> None:
"""Test get_avd_facts."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"evpn_underlay_isis_overlay_ibgp",
"evpn_underlay_ospf_overlay_ebgp",
"evpn_underlay_rfc5549_overlay_ebgp",
"example-campus-fabric",
# TODO: "example-cv-pathfinder", # Work around Ansible vault
"example-dual-dc-l3ls",
"example-isis-ldp-ipvpn",
"example-l2ls-fabric",
"example-single-dc-l3ls",
)
def test_get_device_config(molecule_host: MoleculeHost) -> None:
"""Test get_device_config."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"evpn_underlay_isis_overlay_ibgp",
"evpn_underlay_ospf_overlay_ebgp",
"evpn_underlay_rfc5549_overlay_ebgp",
"example-campus-fabric",
# TODO: "example-cv-pathfinder", # Work around Ansible vault
"example-dual-dc-l3ls",
"example-isis-ldp-ipvpn",
"example-l2ls-fabric",
"example-single-dc-l3ls",
)
def test_get_device_doc(molecule_host: MoleculeHost) -> None:
"""Test get_device_config."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"evpn_underlay_isis_overlay_ibgp",
"evpn_underlay_ospf_overlay_ebgp",
"evpn_underlay_rfc5549_overlay_ebgp",
"example-campus-fabric",
# TODO: "example-cv-pathfinder", # Work around Ansible vault
"example-dual-dc-l3ls",
"example-isis-ldp-ipvpn",
"example-l2ls-fabric",
"example-single-dc-l3ls",
)
def test_get_device_structured_config(molecule_host: MoleculeHost) -> None:
"""Test get_device_structured_config."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"evpn_underlay_isis_overlay_ibgp",
"evpn_underlay_ospf_overlay_ebgp",
"evpn_underlay_rfc5549_overlay_ebgp",
"example-campus-fabric",
# TODO: "example-cv-pathfinder", # Work around Ansible vault
"example-dual-dc-l3ls",
"example-isis-ldp-ipvpn",
"example-l2ls-fabric",
"example-single-dc-l3ls",
)
def test_validate_inputs_with_valid_inputs(molecule_host: MoleculeHost) -> None:
"""Test validate_inputs."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"evpn_underlay_isis_overlay_ibgp",
"evpn_underlay_ospf_overlay_ebgp",
"evpn_underlay_rfc5549_overlay_ebgp",
"example-campus-fabric",
# TODO: "example-cv-pathfinder", # Work around Ansible vault
"example-dual-dc-l3ls",
"example-isis-ldp-ipvpn",
"example-l2ls-fabric",
"example-single-dc-l3ls",
)
def test_validate_structured_config_with_valid_data(molecule_host: MoleculeHost) -> None:
"""Test validate_structured_config."""
Expand Down

0 comments on commit 7edc69f

Please sign in to comment.