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 <pvizeli@syshack.ch>
This commit is contained in:
Joakim Sørensen 2020-11-13 08:58:07 +01:00 committed by GitHub
parent e4bf820038
commit 06ab7e904f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View File

@ -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()

View File

@ -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

View File

@ -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