From 06ab7e904f08449e71ace6195b61861c8e5bf4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 13 Nov 2020 08:58:07 +0100 Subject: [PATCH] Split check for internet connection to help troubleshooting (#2248) * Split check for internet connection to help troubleshooting * Siplify * revert * cleanup Co-authored-by: Pascal Vizeli --- supervisor/core.py | 6 +----- supervisor/host/network.py | 16 +++++++--------- supervisor/job/decorator.py | 13 ++++++++++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/supervisor/core.py b/supervisor/core.py index 3a592092b..9ee31a435 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -58,11 +58,7 @@ class Core(CoreSysAttributes): await self.sys_supervisor.load() # Check internet on startup - if not self.sys_host.network.connectivity: - await self.sys_host.network.check_connectivity() - - if not self.sys_supervisor.connectivity: - await self.sys_supervisor.check_connectivity() + await self.sys_supervisor.check_connectivity() # Evaluate the system await self.sys_resolution.evaluate.evaluate_system() diff --git a/supervisor/host/network.py b/supervisor/host/network.py index 5323bb646..06e5c8cfe 100644 --- a/supervisor/host/network.py +++ b/supervisor/host/network.py @@ -38,10 +38,10 @@ class NetworkManager(CoreSysAttributes): def __init__(self, coresys: CoreSys): """Initialize system center handling.""" self.coresys: CoreSys = coresys - self._connectivity: bool = None + self._connectivity: Optional[bool] = None @property - def connectivity(self) -> bool: + def connectivity(self) -> Optional[bool]: """Return true current connectivity state.""" return self._connectivity @@ -67,15 +67,13 @@ class NetworkManager(CoreSysAttributes): return list(dict.fromkeys(servers)) async def check_connectivity(self): - """Check the internet connection.""" - if not self.sys_dbus.network.is_connected: - self._connectivity = None - return + """Check the internet connection. + + ConnectionState 4 == FULL (has internet) + https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMConnectivityState + """ try: state = await self.sys_dbus.network.check_connectivity() - - # ConnectionState 4 == FULL (has internet) - # https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMConnectivityState self._connectivity = state[0] == 4 except DBusError: self._connectivity = False diff --git a/supervisor/job/decorator.py b/supervisor/job/decorator.py index 02e76cac4..185898f4e 100644 --- a/supervisor/job/decorator.py +++ b/supervisor/job/decorator.py @@ -94,14 +94,21 @@ class Job: if JobCondition.INTERNET in self.conditions: if self._coresys.core.state == CoreState.RUNNING: - await self._coresys.host.network.check_connectivity() + if self._coresys.dbus.network.is_connected: + await self._coresys.host.network.check_connectivity() await self._coresys.supervisor.check_connectivity() - if not self._coresys.supervisor.connectivity or ( + if not self._coresys.supervisor.connectivity: + _LOGGER.warning( + "'%s' blocked from execution, no supervisor internet connection", + self._method.__qualname__, + ) + return False + elif ( self._coresys.host.network.connectivity is not None and not self._coresys.host.network.connectivity ): _LOGGER.warning( - "'%s' blocked from execution, no internet connection", + "'%s' blocked from execution, no host internet connection", self._method.__qualname__, ) return False