Merge pull request 'feat: get_network_targets names each bridge's uplinks (NetOrk/netork#1325)' (#38) from feat/network-target-uplinks into main
driver / standard (push) Successful in 20s
driver / lint (push) Successful in 16s
driver / types (push) Failing after 6s
driver / test (3.13) (push) Successful in 1m7s
driver / test (3.12) (push) Successful in 1m12s
driver / lowest (push) Successful in 34s
driver / build (push) Successful in 47s
driver / security (push) Successful in 1m23s
CI / driver (push) Failing after 2m56s
driver / publish (push) Skipped
driver / standard (push) Successful in 20s
driver / lint (push) Successful in 16s
driver / types (push) Failing after 6s
driver / test (3.13) (push) Successful in 1m7s
driver / test (3.12) (push) Successful in 1m12s
driver / lowest (push) Successful in 34s
driver / build (push) Successful in 47s
driver / security (push) Successful in 1m23s
CI / driver (push) Failing after 2m56s
driver / publish (push) Skipped
This commit was merged in pull request #38.
This commit is contained in:
commit
d8ac209fb9
4 files changed
+222
-8
No files matched your search
@@ -0,0 +1,135 @@
|
||||
"""get_network_targets names the physical NICs each bridge leaves the node through.
|
||||
|
||||
NetOrk follows their LLDP neighbours to the switch port behind the bridge, to
|
||||
tell whether a VM without a VLAN tag lands in a network at all
|
||||
(NetOrk/netork#1325). They come in groups, one per way out of the bridge: a
|
||||
bond's slaves together, a single NIC alone. Internal ports, VLAN subinterfaces
|
||||
and virtual ports are no uplinks. When a port cannot be told
|
||||
apart, ``uplinks`` is left out rather than guessed.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from napalm_proxmox.vm_provision_mixin import ProxmoxVMProvisionMixin
|
||||
|
||||
|
||||
def _targets(network: list[dict]) -> dict[str, dict]:
|
||||
mixin = ProxmoxVMProvisionMixin()
|
||||
mixin._get_node_network = MagicMock(return_value=network)
|
||||
mixin._get_sdn_vnets = MagicMock(return_value=[])
|
||||
return {t["name"]: t for t in mixin.get_network_targets()}
|
||||
|
||||
|
||||
def test_linux_bridge_on_a_nic():
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "eno1", "type": "eth"},
|
||||
{"iface": "vmbr0", "type": "bridge", "bridge_ports": "eno1", "bridge_vlan_aware": 1},
|
||||
]
|
||||
)
|
||||
|
||||
assert targets["vmbr0"]["uplinks"] == [["eno1"]]
|
||||
|
||||
|
||||
def test_linux_bridge_on_a_bond_lists_the_slaves():
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "eno1", "type": "eth"},
|
||||
{"iface": "eno2", "type": "eth"},
|
||||
{"iface": "bond0", "type": "bond", "slaves": "eno1 eno2"},
|
||||
{"iface": "vmbr0", "type": "bridge", "bridge_ports": "bond0"},
|
||||
]
|
||||
)
|
||||
|
||||
assert targets["vmbr0"]["uplinks"] == [["eno1", "eno2"]]
|
||||
|
||||
|
||||
def test_linux_bridge_on_a_vlan_subinterface_has_no_uplink():
|
||||
"""A bridge on ``eno1.40`` leaves tagged; the port's untagged VLAN is not its."""
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "eno1", "type": "eth"},
|
||||
{"iface": "eno1.40", "type": "vlan", "vlan-raw-device": "eno1"},
|
||||
{"iface": "vmbr40", "type": "bridge", "bridge_ports": "eno1.40"},
|
||||
]
|
||||
)
|
||||
|
||||
assert targets["vmbr40"]["uplinks"] == []
|
||||
|
||||
|
||||
def test_host_only_bridge_has_no_uplink():
|
||||
targets = _targets([{"iface": "vmbr9", "type": "bridge"}])
|
||||
|
||||
assert targets["vmbr9"]["uplinks"] == []
|
||||
|
||||
|
||||
def test_ovs_bridge_with_bond_and_internal_port():
|
||||
"""pve-dual's shape: vmbr0 carries an LACP bond and the management OVSIntPort."""
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "nic0", "type": "OVSPort"},
|
||||
{"iface": "nic1", "type": "OVSPort"},
|
||||
{
|
||||
"iface": "bond0",
|
||||
"type": "OVSBond",
|
||||
"ovs_bonds": "nic0 nic1",
|
||||
"ovs_bridge": "vmbr0",
|
||||
},
|
||||
{"iface": "mgmt_vlan", "type": "OVSIntPort", "ovs_bridge": "vmbr0", "ovs_tag": 8},
|
||||
{"iface": "vmbr0", "type": "OVSBridge", "ovs_ports": "bond0 mgmt_vlan"},
|
||||
]
|
||||
)
|
||||
|
||||
assert targets["vmbr0"]["uplinks"] == [["nic0", "nic1"]]
|
||||
|
||||
|
||||
def test_ovs_bridge_on_a_single_port():
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "eno1", "type": "OVSPort", "ovs_bridge": "vmbr1"},
|
||||
{"iface": "vmbr1", "type": "OVSBridge", "ovs_ports": "eno1"},
|
||||
]
|
||||
)
|
||||
|
||||
assert targets["vmbr1"]["uplinks"] == [["eno1"]]
|
||||
|
||||
|
||||
def test_ovs_bridge_on_two_single_ports_has_two_groups():
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "eno1", "type": "OVSPort", "ovs_bridge": "vmbr1"},
|
||||
{"iface": "eno2", "type": "OVSPort", "ovs_bridge": "vmbr1"},
|
||||
{"iface": "vmbr1", "type": "OVSBridge", "ovs_ports": "eno1 eno2"},
|
||||
]
|
||||
)
|
||||
|
||||
assert targets["vmbr1"]["uplinks"] == [["eno1"], ["eno2"]]
|
||||
|
||||
|
||||
def test_port_missing_from_the_network_config_leaves_uplinks_out():
|
||||
targets = _targets([{"iface": "vmbr0", "type": "bridge", "bridge_ports": "enp9s0"}])
|
||||
|
||||
assert "uplinks" not in targets["vmbr0"]
|
||||
|
||||
|
||||
def test_port_of_an_unknown_kind_leaves_uplinks_out():
|
||||
targets = _targets(
|
||||
[
|
||||
{"iface": "wg0", "type": "unknown"},
|
||||
{"iface": "vmbr0", "type": "bridge", "bridge_ports": "wg0"},
|
||||
]
|
||||
)
|
||||
|
||||
assert "uplinks" not in targets["vmbr0"]
|
||||
|
||||
|
||||
def test_vnet_has_no_uplinks():
|
||||
mixin = ProxmoxVMProvisionMixin()
|
||||
mixin._get_node_network = MagicMock(return_value=[])
|
||||
mixin._get_sdn_vnets = MagicMock(return_value=[{"vnet": "vnet0", "zone": "z", "tag": 10}])
|
||||
|
||||
(target,) = mixin.get_network_targets()
|
||||
|
||||
assert "uplinks" not in target
|
||||
Reference in new issue
Block a user