Go-based network automation with YANG models, gRPC, Ansible, Terraform, and Kubernetes integration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
"""Tests for the YANG site config compiler."""
|
|
|
|
from pathlib import Path
|
|
|
|
from compiler.compile import compile_site, extract_circuits, extract_zones, parse_site_config
|
|
|
|
FIXTURES_DIR = Path(__file__).parent.parent / "site-config"
|
|
|
|
|
|
class TestParseHomelab:
|
|
"""Test parsing of the homelab site configuration."""
|
|
|
|
def test_parse_homelab_zones(self) -> None:
|
|
root = parse_site_config(str(FIXTURES_DIR / "homelab.xml"))
|
|
zones = extract_zones(root)
|
|
|
|
assert len(zones) == 5
|
|
|
|
zone_names = [z["name"] for z in zones]
|
|
assert "transit" in zone_names
|
|
assert "tyler-lab" in zone_names
|
|
assert "roommate" in zone_names
|
|
assert "shared" in zone_names
|
|
assert "dmz" in zone_names
|
|
|
|
def test_transit_zone_properties(self) -> None:
|
|
root = parse_site_config(str(FIXTURES_DIR / "homelab.xml"))
|
|
zones = extract_zones(root)
|
|
|
|
transit = next(z for z in zones if z["name"] == "transit")
|
|
assert transit["subnet"] == "172.16.0.0/24"
|
|
assert transit["vlan_id"] == 100
|
|
assert transit["owner_device"] == "fortigate.transit.local"
|
|
assert len(transit["policies"]) == 2
|
|
|
|
def test_parse_circuits(self) -> None:
|
|
root = parse_site_config(str(FIXTURES_DIR / "homelab.xml"))
|
|
circuits = extract_circuits(root)
|
|
|
|
assert len(circuits) == 1
|
|
assert circuits[0]["name"] == "fios-primary"
|
|
assert circuits[0]["type"] == "primary"
|
|
assert circuits[0]["sla"]["latency_ms"] == 20
|
|
|
|
|
|
class TestParseCloudAnchor:
|
|
"""Test parsing of the cloud anchor site configuration."""
|
|
|
|
def test_cloud_anchor_no_zones(self) -> None:
|
|
root = parse_site_config(str(FIXTURES_DIR / "cloud-anchor.xml"))
|
|
zones = extract_zones(root)
|
|
assert len(zones) == 0
|
|
|
|
def test_cloud_anchor_has_circuit(self) -> None:
|
|
root = parse_site_config(str(FIXTURES_DIR / "cloud-anchor.xml"))
|
|
circuits = extract_circuits(root)
|
|
assert len(circuits) == 1
|
|
assert circuits[0]["name"] == "vps-primary"
|
|
|
|
|
|
class TestCompileSite:
|
|
"""Test full site compilation pipeline."""
|
|
|
|
def test_compile_homelab(self) -> None:
|
|
result = compile_site(str(FIXTURES_DIR / "homelab.xml"))
|
|
|
|
assert "devices" in result
|
|
# FortiGate should have compiled zones.
|
|
forti_devices = [
|
|
d for d in result["devices"] if "fortigate" in d.lower()
|
|
]
|
|
assert len(forti_devices) > 0
|
|
|
|
def test_compile_cloud_anchor(self) -> None:
|
|
result = compile_site(str(FIXTURES_DIR / "cloud-anchor.xml"))
|
|
|
|
# Cloud anchor has no underlay devices.
|
|
assert len(result["devices"]) == 0
|
|
assert len(result.get("circuits", [])) == 1
|