mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-18 06:36:30 +00:00
Fallback on interface name if path is missing (#4479)
This commit is contained in:
parent
9647fba98f
commit
71077fb0f7
@ -59,7 +59,10 @@ def get_connection_from_interface(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if interface.type != InterfaceType.VLAN:
|
if interface.type != InterfaceType.VLAN:
|
||||||
conn[CONF_ATTR_MATCH] = {CONF_ATTR_PATH: Variant("as", [interface.path])}
|
if interface.path:
|
||||||
|
conn[CONF_ATTR_MATCH] = {CONF_ATTR_PATH: Variant("as", [interface.path])}
|
||||||
|
else:
|
||||||
|
conn[CONF_ATTR_CONNECTION]["interface-name"] = Variant("s", interface.name)
|
||||||
|
|
||||||
ipv4 = {}
|
ipv4 = {}
|
||||||
if not interface.ipv4 or interface.ipv4.method == InterfaceMethod.AUTO:
|
if not interface.ipv4 or interface.ipv4.method == InterfaceMethod.AUTO:
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
"""Test settings generation from interface."""
|
"""Test settings generation from interface."""
|
||||||
|
|
||||||
|
from unittest.mock import PropertyMock, patch
|
||||||
|
|
||||||
from supervisor.dbus.network import NetworkManager
|
from supervisor.dbus.network import NetworkManager
|
||||||
|
from supervisor.dbus.network.interface import NetworkInterface
|
||||||
from supervisor.dbus.network.setting.generate import get_connection_from_interface
|
from supervisor.dbus.network.setting.generate import get_connection_from_interface
|
||||||
from supervisor.host.network import Interface
|
from supervisor.host.network import Interface
|
||||||
|
|
||||||
@ -24,3 +27,17 @@ async def test_get_connection_from_interface(network_manager: NetworkManager):
|
|||||||
|
|
||||||
assert connection_payload["ipv6"]["method"].value == "auto"
|
assert connection_payload["ipv6"]["method"].value == "auto"
|
||||||
assert "address-data" not in connection_payload["ipv6"]
|
assert "address-data" not in connection_payload["ipv6"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_connection_no_path(network_manager: NetworkManager):
|
||||||
|
"""Test network interface without a path."""
|
||||||
|
dbus_interface = network_manager.get(TEST_INTERFACE)
|
||||||
|
with patch.object(NetworkInterface, "path", new=PropertyMock(return_value=None)):
|
||||||
|
interface = Interface.from_dbus_interface(dbus_interface)
|
||||||
|
|
||||||
|
connection_payload = get_connection_from_interface(interface)
|
||||||
|
|
||||||
|
assert "connection" in connection_payload
|
||||||
|
assert "match" not in connection_payload
|
||||||
|
|
||||||
|
assert connection_payload["connection"]["interface-name"].value == "eth0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user