Files
napalm-proxmox/tests/test_switch_uplink.py
T
Christian Manivong d142db73e5 fix(sdn): restore the virtual interface prefixes for set_vlan
b1ba991 removed _VIRTUAL_IFACE_PREFIXES while _is_physical_uplink still
read it. The AttributeError was swallowed by _find_switch_uplink, so
set_vlan never found an uplink on any node. Restore the constant and
cover both helpers with tests.

Closes #37
2026-11-01 21:43:09 +01:00

59 lines
2.0 KiB
Python

"""The physical port set_vlan configures: _find_switch_uplink / _is_physical_uplink."""
from __future__ import annotations
from unittest.mock import MagicMock
from napalm_proxmox.sdn_mixin import ProxmoxSDNMixin
NETWORK = [
{"iface": "eno1", "type": "eth"},
{"iface": "vmbr0", "type": "bridge", "bridge_ports": "eno1"},
]
def _mixin(detail: dict, basic: dict) -> ProxmoxSDNMixin:
m = ProxmoxSDNMixin()
m._get_node_network = MagicMock(return_value=NETWORK)
m.get_lldp_neighbors_detail = MagicMock(return_value=detail)
m.get_lldp_neighbors = MagicMock(return_value=basic)
return m
class TestFindSwitchUplink:
def test_physical_port_with_a_bridge_neighbour_is_the_uplink(self):
m = _mixin(
detail={
"tap100i0": [{"remote_system_capab": ["bridge"]}],
"eno1": [{"remote_system_capab": ["bridge", "router"]}],
},
basic={},
)
assert m._find_switch_uplink() == "eno1"
def test_basic_lldp_fallback_skips_a_virtual_port(self):
m = _mixin(
detail={},
basic={"fwpr100p0": [{"hostname": "sw"}], "eno1": [{"hostname": "sw"}]},
)
assert m._find_switch_uplink() == "eno1"
def test_no_physical_neighbour_is_none(self):
m = _mixin(detail={"tap100i0": [{"remote_system_capab": ["bridge"]}]}, basic={})
assert m._find_switch_uplink() is None
class TestIsPhysicalUplink:
def test_eth_in_the_network_config_is_physical(self):
assert ProxmoxSDNMixin()._is_physical_uplink("eno1", {"eno1": {"type": "eth"}})
def test_virtual_prefix_is_never_physical(self):
network = {"tap100i0": {"type": ""}}
assert not ProxmoxSDNMixin()._is_physical_uplink("tap100i0", network)
def test_port_missing_from_the_network_config_is_not_physical(self):
assert not ProxmoxSDNMixin()._is_physical_uplink("eno9", {})
def test_bridge_is_not_physical(self):
assert not ProxmoxSDNMixin()._is_physical_uplink("vmbr0", {"vmbr0": {"type": "bridge"}})