Check if connectivity check if available on host (#2265)

* Check if connectivity check if available on host

* fix get

* not needed

* Update const.py

* Use enabled
This commit is contained in:
Pascal Vizeli 2020-11-18 12:40:55 +01:00 committed by GitHub
parent 80f4309799
commit 2f9fc39b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -63,6 +63,7 @@ DBUS_ATTR_TYPE = "Type"
DBUS_ATTR_UUID = "Uuid"
DBUS_ATTR_VARIANT = "Variant"
DBUS_ATTR_MANAGED = "Managed"
DBUS_ATTR_CONNECTION_ENABLED = "ConnectivityCheckEnabled"
class RaucState(str, Enum):

View File

@ -7,6 +7,7 @@ import sentry_sdk
from ...exceptions import DBusError, DBusInterfaceError
from ...utils.gdbus import DBus
from ..const import (
DBUS_ATTR_CONNECTION_ENABLED,
DBUS_ATTR_DEVICES,
DBUS_ATTR_PRIMARY_CONNECTION,
DBUS_NAME_NM,
@ -32,6 +33,8 @@ class NetworkManager(DBusInterface):
self._settings: NetworkManagerSettings = NetworkManagerSettings()
self._interfaces: Dict[str, NetworkInterface] = {}
self.properties: Dict[str, Any] = {}
@property
def dns(self) -> NetworkManagerDNS:
"""Return NetworkManager DNS interface."""
@ -47,6 +50,11 @@ class NetworkManager(DBusInterface):
"""Return a dictionary of active interfaces."""
return self._interfaces
@property
def connectivity_enabled(self) -> bool:
"""Return if connectivity check is enabled."""
return self.properties[DBUS_ATTR_CONNECTION_ENABLED]
@dbus_connected
def activate_connection(
self, connection_object: str, device_object: str
@ -86,16 +94,12 @@ class NetworkManager(DBusInterface):
@dbus_connected
async def update(self):
"""Update Properties."""
self.properties = await self.dbus.get_properties(DBUS_NAME_NM)
await self.dns.update()
data = await self.dbus.get_properties(DBUS_NAME_NM)
if not data:
_LOGGER.warning("Can't get properties for Network Manager")
return
self._interfaces.clear()
for device in data.get(DBUS_ATTR_DEVICES, []):
for device in self.properties[DBUS_ATTR_DEVICES]:
interface = NetworkInterface(self.dbus, device)
# Connect to interface
@ -118,8 +122,10 @@ class NetworkManager(DBusInterface):
):
continue
if interface.connection and interface.connection.object_path == data.get(
DBUS_ATTR_PRIMARY_CONNECTION
if (
interface.connection
and interface.connection.object_path
== self.properties[DBUS_ATTR_PRIMARY_CONNECTION]
):
interface.primary = True

View File

@ -72,6 +72,10 @@ class NetworkManager(CoreSysAttributes):
ConnectionState 4 == FULL (has internet)
https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMConnectivityState
"""
if not self.sys_dbus.network.connectivity_enabled:
return
# Check connectivity
try:
state = await self.sys_dbus.network.check_connectivity()
self._connectivity = state[0] == 4