Make dbus connection more robust (#2325)

* Make dbus connection more robust

* move rauc down
This commit is contained in:
Pascal Vizeli 2020-12-02 17:22:28 +01:00 committed by GitHub
parent 80763c4bbf
commit 3d79891249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 8 deletions

View File

@ -1,9 +1,11 @@
"""D-Bus interface objects.""" """D-Bus interface objects."""
import logging import logging
from typing import List
from ..const import SOCKET_DBUS
from ..coresys import CoreSys, CoreSysAttributes from ..coresys import CoreSys, CoreSysAttributes
from ..exceptions import DBusNotConnectedError
from .hostname import Hostname from .hostname import Hostname
from .interface import DBusInterface
from .network import NetworkManager from .network import NetworkManager
from .rauc import Rauc from .rauc import Rauc
from .systemd import Systemd from .systemd import Systemd
@ -45,15 +47,22 @@ class DBusManager(CoreSysAttributes):
async def load(self) -> None: async def load(self) -> None:
"""Connect interfaces to D-Bus.""" """Connect interfaces to D-Bus."""
if not SOCKET_DBUS.exists():
try:
await self.systemd.connect()
await self.hostname.connect()
await self.rauc.connect()
await self.network.connect()
except DBusNotConnectedError:
_LOGGER.error( _LOGGER.error(
"No D-Bus support on Host. Disabled any kind of host control!" "No D-Bus support on Host. Disabled any kind of host control!"
) )
return
dbus_loads: List[DBusInterface] = [
self.systemd,
self.hostname,
self.network,
self.rauc,
]
for dbus in dbus_loads:
try:
await dbus.connect()
except Exception as err: # pylint: disable=broad-except
_LOGGER.warning("Can't load dbus interface %s: %s", dbus.name, err)
self.sys_host.supported_features.cache_clear() self.sys_host.supported_features.cache_clear()

View File

@ -23,6 +23,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
class Hostname(DBusInterface): class Hostname(DBusInterface):
"""Handle D-Bus interface for hostname/system.""" """Handle D-Bus interface for hostname/system."""
name = DBUS_NAME_HOSTNAME
def __init__(self): def __init__(self):
"""Initialize Properties.""" """Initialize Properties."""
self._hostname: Optional[str] = None self._hostname: Optional[str] = None

View File

@ -9,6 +9,7 @@ class DBusInterface(ABC):
"""Handle D-Bus interface for hostname/system.""" """Handle D-Bus interface for hostname/system."""
dbus: Optional[DBus] = None dbus: Optional[DBus] = None
name: Optional[str] = None
@property @property
def is_connected(self): def is_connected(self):

View File

@ -27,6 +27,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
class NetworkManager(DBusInterface): class NetworkManager(DBusInterface):
"""Handle D-Bus interface for Network Manager.""" """Handle D-Bus interface for Network Manager."""
name = DBUS_NAME_NM
def __init__(self) -> None: def __init__(self) -> None:
"""Initialize Properties.""" """Initialize Properties."""
self._dns: NetworkManagerDNS = NetworkManagerDNS() self._dns: NetworkManagerDNS = NetworkManagerDNS()

View File

@ -25,6 +25,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
class Rauc(DBusInterface): class Rauc(DBusInterface):
"""Handle D-Bus interface for rauc.""" """Handle D-Bus interface for rauc."""
name = DBUS_NAME_RAUC
def __init__(self): def __init__(self):
"""Initialize Properties.""" """Initialize Properties."""
self._operation: Optional[str] = None self._operation: Optional[str] = None

View File

@ -13,6 +13,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
class Systemd(DBusInterface): class Systemd(DBusInterface):
"""Systemd function handler.""" """Systemd function handler."""
name = DBUS_NAME_SYSTEMD
async def connect(self): async def connect(self):
"""Connect to D-Bus.""" """Connect to D-Bus."""
try: try: