Debug info for network connection problem (#3828)

* Debug info for network connection problem

* Update network tests
This commit is contained in:
Mike Degatano 2022-08-29 16:01:40 -04:00 committed by GitHub
parent df030e6209
commit bae7fe4184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 4 deletions

View File

@ -30,6 +30,7 @@ from ..const import (
ATTR_PARENT, ATTR_PARENT,
ATTR_PRIMARY, ATTR_PRIMARY,
ATTR_PSK, ATTR_PSK,
ATTR_READY,
ATTR_SIGNAL, ATTR_SIGNAL,
ATTR_SSID, ATTR_SSID,
ATTR_SUPERVISOR_INTERNET, ATTR_SUPERVISOR_INTERNET,
@ -89,6 +90,7 @@ def ipconfig_struct(config: IpConfig) -> dict[str, Any]:
ATTR_ADDRESS: [address.with_prefixlen for address in config.address], ATTR_ADDRESS: [address.with_prefixlen for address in config.address],
ATTR_NAMESERVERS: [str(address) for address in config.nameservers], ATTR_NAMESERVERS: [str(address) for address in config.nameservers],
ATTR_GATEWAY: str(config.gateway) if config.gateway else None, ATTR_GATEWAY: str(config.gateway) if config.gateway else None,
ATTR_READY: config.ready,
} }

View File

@ -251,6 +251,7 @@ ATTR_PROVIDERS = "providers"
ATTR_PSK = "psk" ATTR_PSK = "psk"
ATTR_PWNED = "pwned" ATTR_PWNED = "pwned"
ATTR_RATING = "rating" ATTR_RATING = "rating"
ATTR_READY = "ready"
ATTR_REALTIME = "realtime" ATTR_REALTIME = "realtime"
ATTR_REFRESH_TOKEN = "refresh_token" ATTR_REFRESH_TOKEN = "refresh_token"
ATTR_REGISTRIES = "registries" ATTR_REGISTRIES = "registries"

View File

@ -12,6 +12,7 @@ from ..const import ATTR_HOST_INTERNET
from ..coresys import CoreSys, CoreSysAttributes from ..coresys import CoreSys, CoreSysAttributes
from ..dbus.const import ( from ..dbus.const import (
DBUS_SIGNAL_NM_CONNECTION_ACTIVE_CHANGED, DBUS_SIGNAL_NM_CONNECTION_ACTIVE_CHANGED,
ConnectionStateFlags,
ConnectionStateType, ConnectionStateType,
ConnectivityState, ConnectivityState,
DeviceType, DeviceType,
@ -309,6 +310,7 @@ class IpConfig:
address: list[IPv4Interface | IPv6Interface] = attr.ib() address: list[IPv4Interface | IPv6Interface] = attr.ib()
gateway: IPv4Address | IPv6Address | None = attr.ib() gateway: IPv4Address | IPv6Address | None = attr.ib()
nameservers: list[IPv4Address | IPv6Address] = attr.ib() nameservers: list[IPv4Address | IPv6Address] = attr.ib()
ready: bool = attr.ib()
@attr.s(slots=True) @attr.s(slots=True)
@ -357,6 +359,14 @@ class Interface:
if inet.settings and inet.settings.ipv6 if inet.settings and inet.settings.ipv6
else InterfaceMethod.DISABLED else InterfaceMethod.DISABLED
) )
ipv4_ready = (
bool(inet.connection)
and ConnectionStateFlags.IP4_READY in inet.connection.state_flags
)
ipv6_ready = (
bool(inet.connection)
and ConnectionStateFlags.IP6_READY in inet.connection.state_flags
)
return Interface( return Interface(
inet.name, inet.name,
inet.settings is not None, inet.settings is not None,
@ -368,17 +378,19 @@ class Interface:
inet.connection.ipv4.address, inet.connection.ipv4.address,
inet.connection.ipv4.gateway, inet.connection.ipv4.gateway,
inet.connection.ipv4.nameservers, inet.connection.ipv4.nameservers,
ipv4_ready,
) )
if inet.connection and inet.connection.ipv4 if inet.connection and inet.connection.ipv4
else IpConfig(ipv4_method, [], None, []), else IpConfig(ipv4_method, [], None, [], ipv4_ready),
IpConfig( IpConfig(
ipv6_method, ipv6_method,
inet.connection.ipv6.address, inet.connection.ipv6.address,
inet.connection.ipv6.gateway, inet.connection.ipv6.gateway,
inet.connection.ipv6.nameservers, inet.connection.ipv6.nameservers,
ipv6_ready,
) )
if inet.connection and inet.connection.ipv6 if inet.connection and inet.connection.ipv6
else IpConfig(ipv6_method, [], None, []), else IpConfig(ipv6_method, [], None, [], ipv6_ready),
Interface._map_nm_wifi(inet), Interface._map_nm_wifi(inet),
Interface._map_nm_vlan(inet), Interface._map_nm_vlan(inet),
) )

View File

@ -31,12 +31,14 @@ async def test_api_network_info(api_client, coresys):
"gateway": None, "gateway": None,
"method": "disabled", "method": "disabled",
"nameservers": [], "nameservers": [],
"ready": False,
} }
assert interface["ipv6"] == { assert interface["ipv6"] == {
"address": [], "address": [],
"gateway": None, "gateway": None,
"method": "disabled", "method": "disabled",
"nameservers": [], "nameservers": [],
"ready": False,
} }
assert result["data"]["docker"]["interface"] == DOCKER_NETWORK assert result["data"]["docker"]["interface"] == DOCKER_NETWORK
@ -53,6 +55,7 @@ async def test_api_network_interface_info(api_client):
assert result["data"]["ipv4"]["address"][-1] == "192.168.2.148/24" assert result["data"]["ipv4"]["address"][-1] == "192.168.2.148/24"
assert result["data"]["ipv4"]["gateway"] == "192.168.2.1" assert result["data"]["ipv4"]["gateway"] == "192.168.2.1"
assert result["data"]["ipv4"]["nameservers"] == ["192.168.2.2"] assert result["data"]["ipv4"]["nameservers"] == ["192.168.2.2"]
assert result["data"]["ipv4"]["ready"] is True
assert ( assert (
result["data"]["ipv6"]["address"][0] == "2a03:169:3df5:0:6be9:2588:b26a:a679/64" result["data"]["ipv6"]["address"][0] == "2a03:169:3df5:0:6be9:2588:b26a:a679/64"
) )
@ -65,6 +68,7 @@ async def test_api_network_interface_info(api_client):
"2001:1620:2777:1::10", "2001:1620:2777:1::10",
"2001:1620:2777:2::20", "2001:1620:2777:2::20",
] ]
assert result["data"]["ipv6"]["ready"] is True
assert result["data"]["interface"] == TEST_INTERFACE assert result["data"]["interface"] == TEST_INTERFACE
@ -76,6 +80,7 @@ async def test_api_network_interface_info_default(api_client):
assert result["data"]["ipv4"]["address"][-1] == "192.168.2.148/24" assert result["data"]["ipv4"]["address"][-1] == "192.168.2.148/24"
assert result["data"]["ipv4"]["gateway"] == "192.168.2.1" assert result["data"]["ipv4"]["gateway"] == "192.168.2.1"
assert result["data"]["ipv4"]["nameservers"] == ["192.168.2.2"] assert result["data"]["ipv4"]["nameservers"] == ["192.168.2.2"]
assert result["data"]["ipv4"]["ready"] is True
assert ( assert (
result["data"]["ipv6"]["address"][0] == "2a03:169:3df5:0:6be9:2588:b26a:a679/64" result["data"]["ipv6"]["address"][0] == "2a03:169:3df5:0:6be9:2588:b26a:a679/64"
) )
@ -88,6 +93,7 @@ async def test_api_network_interface_info_default(api_client):
"2001:1620:2777:1::10", "2001:1620:2777:1::10",
"2001:1620:2777:2::20", "2001:1620:2777:2::20",
] ]
assert result["data"]["ipv6"]["ready"] is True
assert result["data"]["interface"] == TEST_INTERFACE assert result["data"]["interface"] == TEST_INTERFACE

View File

@ -29,10 +29,12 @@ async def test_load(coresys: CoreSys):
assert coresys.host.network.interfaces[0].ipv4.gateway == IPv4Address( assert coresys.host.network.interfaces[0].ipv4.gateway == IPv4Address(
"192.168.2.1" "192.168.2.1"
) )
assert coresys.host.network.interfaces[0].ipv4.ready is True
assert coresys.host.network.interfaces[0].ipv6.method == InterfaceMethod.AUTO assert coresys.host.network.interfaces[0].ipv6.method == InterfaceMethod.AUTO
assert coresys.host.network.interfaces[0].ipv6.gateway == IPv6Address( assert coresys.host.network.interfaces[0].ipv6.gateway == IPv6Address(
"fe80::da58:d7ff:fe00:9c69" "fe80::da58:d7ff:fe00:9c69"
) )
assert coresys.host.network.interfaces[0].ipv6.ready is True
assert coresys.host.network.interfaces[1].name == "wlan0" assert coresys.host.network.interfaces[1].name == "wlan0"
assert coresys.host.network.interfaces[1].enabled is False assert coresys.host.network.interfaces[1].enabled is False
@ -52,8 +54,8 @@ async def test_load_with_disabled_methods(coresys: CoreSys):
False, False,
False, False,
InterfaceType.ETHERNET, InterfaceType.ETHERNET,
IpConfig(InterfaceMethod.DISABLED, [], None, []), IpConfig(InterfaceMethod.DISABLED, [], None, [], False),
IpConfig(InterfaceMethod.DISABLED, [], None, []), IpConfig(InterfaceMethod.DISABLED, [], None, [], False),
None, None,
None, None,
), ),