1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-02-15 07:27:13 +00:00

Add configurable interface route metric (#6447)

* Add route_metric attribute to IpProperties class

Signed-off-by: David Rapan <david@rapan.cz>

* Refactor dbus setting IP constants

Signed-off-by: David Rapan <david@rapan.cz>

* Add route metric

Signed-off-by: David Rapan <david@rapan.cz>

* Merge test_api_network_interface_info

Signed-off-by: David Rapan <david@rapan.cz>

* Add test case for route metric update

Signed-off-by: David Rapan <david@rapan.cz>

---------

Signed-off-by: David Rapan <david@rapan.cz>
This commit is contained in:
David Rapan
2026-01-28 13:08:36 +01:00
committed by GitHub
parent de02bc991a
commit 641b205ee7
10 changed files with 116 additions and 109 deletions

View File

@@ -46,6 +46,7 @@ async def test_api_network_info(api_client: TestClient, coresys: CoreSys):
assert interface["ipv4"] == {
"address": [],
"gateway": None,
"route_metric": None,
"method": "disabled",
"nameservers": [],
"ready": False,
@@ -54,6 +55,7 @@ async def test_api_network_info(api_client: TestClient, coresys: CoreSys):
"addr_gen_mode": "default",
"address": [],
"gateway": None,
"route_metric": None,
"ip6_privacy": "default",
"method": "disabled",
"nameservers": [],
@@ -67,7 +69,7 @@ async def test_api_network_info(api_client: TestClient, coresys: CoreSys):
@pytest.mark.parametrize(
"interface_id", [TEST_INTERFACE_ETH_NAME, TEST_INTERFACE_ETH_MAC]
"interface_id", ["default", TEST_INTERFACE_ETH_NAME, TEST_INTERFACE_ETH_MAC]
)
async def test_api_network_interface_info(api_client: TestClient, interface_id: str):
"""Test network manager api."""
@@ -92,29 +94,6 @@ async def test_api_network_interface_info(api_client: TestClient, interface_id:
assert result["data"]["llmnr"] == "announce"
async def test_api_network_interface_info_default(api_client: TestClient):
"""Test network manager default api."""
resp = await api_client.get("/network/interface/default/info")
result = await resp.json()
assert result["data"]["ipv4"]["address"][-1] == "192.168.2.148/24"
assert result["data"]["ipv4"]["gateway"] == "192.168.2.1"
assert result["data"]["ipv4"]["nameservers"] == ["192.168.2.2"]
assert result["data"]["ipv4"]["ready"] is True
assert (
result["data"]["ipv6"]["address"][0] == "2a03:169:3df5:0:6be9:2588:b26a:a679/64"
)
assert result["data"]["ipv6"]["address"][1] == "2a03:169:3df5::2f1/128"
assert result["data"]["ipv6"]["gateway"] == "fe80::da58:d7ff:fe00:9c69"
assert result["data"]["ipv6"]["nameservers"] == [
"2001:1620:2777:1::10",
"2001:1620:2777:2::20",
]
assert result["data"]["ipv6"]["ready"] is True
assert result["data"]["interface"] == TEST_INTERFACE_ETH_NAME
assert result["data"]["mdns"] == "announce"
assert result["data"]["llmnr"] == "announce"
@pytest.mark.parametrize(
"interface_id", [TEST_INTERFACE_ETH_NAME, TEST_INTERFACE_ETH_MAC]
)
@@ -238,6 +217,24 @@ async def test_api_network_interface_update_ethernet(
assert settings["ipv4"]["dns"] == Variant("au", [134744072])
assert "gateway" not in settings["ipv4"]
# Update route metric
resp = await api_client.post(
f"/network/interface/{TEST_INTERFACE_ETH_NAME}/update",
json={
"ipv4": {
"route_metric": 100,
}
},
)
result = await resp.json()
assert result["result"] == "ok"
assert len(connection_settings_service.Update.calls) == 4
settings = connection_settings_service.Update.calls[3][0]
assert "ipv4" in settings
assert "route-metric" in settings["ipv4"]
assert settings["ipv4"]["route-metric"] == Variant("i", 100)
async def test_api_network_interface_update_wifi(api_client: TestClient):
"""Test network interface WiFi API."""

View File

@@ -58,9 +58,9 @@ async def test_generate_from_vlan(network_manager: NetworkManager):
primary=False,
type=InterfaceType.VLAN,
ipv4=IpConfig([], None, [], None),
ipv4setting=IpSetting(InterfaceMethod.AUTO, [], None, []),
ipv4setting=IpSetting(InterfaceMethod.AUTO, [], None, None, []),
ipv6=IpConfig([], None, [], None),
ipv6setting=Ip6Setting(InterfaceMethod.AUTO, [], None, []),
ipv6setting=Ip6Setting(InterfaceMethod.AUTO, [], None, None, []),
wifi=None,
vlan=VlanConfig(1, "eth0"),
mdns=MulticastDnsMode.RESOLVE,

View File

@@ -151,7 +151,7 @@ async def test_ipv6_addr_gen_mode(
):
"""Test addr_gen_mode with various NetworkManager versions."""
interface = Interface.from_dbus_interface(dbus_interface)
interface.ipv6setting = Ip6Setting(InterfaceMethod.AUTO, [], None, [])
interface.ipv6setting = Ip6Setting(InterfaceMethod.AUTO, [], None, None, [])
network_manager = MagicMock()
type(network_manager).version = PropertyMock(return_value=AwesomeVersion(version))