Skip to content

Commit

Permalink
Pavel's review - 3 - Removed SBUSUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
aplopez committed May 16, 2024
1 parent 5378c7c commit 470185a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
12 changes: 6 additions & 6 deletions sssd_test_framework/roles/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..utils.automount import AutomountUtils
from ..utils.ldb import LDBUtils
from ..utils.local_users import LocalUsersUtils
from ..utils.sbus import SBUSUtils
from ..utils.sbus import DBUSDestination, DBUSKnownBus
from ..utils.sss_override import SSSOverrideUtils
from ..utils.sssctl import SSSCTLUtils
from ..utils.sssd import SSSDUtils
Expand Down Expand Up @@ -98,15 +98,15 @@ def setup(self) -> None:

self.sssd.import_domain(domain, role)

def sbus(self) -> SBUSUtils:
def infopipe(self) -> DBUSDestination:
"""
Run an sbus operation from the client.
Run an infopipe operation from the client.
"""

if "_sbus" not in self.__dict__:
self._sbus: SBUSUtils = SBUSUtils(self.host)
if "_infopipe" not in self.__dict__:
self._infopipe = DBUSDestination(self.host, dest="org.freedesktop.sssd.infopipe", bus=DBUSKnownBus.SYSTEM)

return self._sbus
return self._infopipe

def sss_ssh_knownhosts(self, *args: str) -> SSHProcessResult:
"""
Expand Down
40 changes: 8 additions & 32 deletions sssd_test_framework/utils/sbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .dbus.types import DBUSResult, DBUSSignatureReader, DBUSType, DBUSTypeString, DBUSTypeVariant

__all__ = [
"SBUSUtils",
"DBUSDestination",
"DBUSKnownBus",
]

Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(
):
super().__init__(host, dest, objpath, bus, interface=interface, child=child)
# Properties always return a variant of the provided type.
self.type = DBUSTypeVariant(type)
self.type: DBUSTypeVariant = DBUSTypeVariant(type)
# access can be "read", "write" or "readwrite"
self.readable = "read" in child.attrib["access"]
self.writable = "write" in child.attrib["access"]
Expand Down Expand Up @@ -213,16 +213,15 @@ def __call__(self, *args) -> Any:
return ret


class DBUSObject(MultihostUtility[MultihostHost]):
class DBUSObject:
"""
A D-Bus object accesible as a Python object.
Objects of this class represent D-Bus nodes.
"""

def __init__(self, host: MultihostHost, *, dest: str, objpath: str, bus: str):
super().__init__(host)

self.host = host
self._properties: dict[Any, Any] = {}
self._objpath = objpath
self._dest = dest
Expand Down Expand Up @@ -383,7 +382,7 @@ def __exit__(*args):
pass


class DBUSDestination:
class DBUSDestination(MultihostUtility[MultihostHost]):
def __init__(self, host: MultihostHost, dest: str, bus: str):
"""
Create a destination object associated to a bus and a name.
Expand All @@ -394,13 +393,13 @@ def __init__(self, host: MultihostHost, dest: str, bus: str):
For other cases, a string can be provided with the explicit bus path.
:type bus: str | DBUSBus, optional
"""
self._host = host
super().__init__(host)
self._dest = dest
self._bus = bus
self._objPaths: list[str] | None = None

def _instrospect(self, objPath: str) -> xml.Element:
introspection = ProxyMethod(self._host, self._dest, objPath, self._bus)
introspection = ProxyMethod(self.host, self._dest, objPath, self._bus)
res = introspection._run("org.freedesktop.DBus.Introspectable.Introspect")
if res.rc != 0:
raise RuntimeError(f"Introspection failed for {objPath}")
Expand Down Expand Up @@ -438,30 +437,7 @@ def getObject(self, objpath: str) -> DBUSObject:
:param objpath: The path to the object at destination.
:type objpath: str
"""
return DBUSObject(self._host, dest=self._dest, objpath=objpath, bus=self._bus)

def __enter__(self):
return self

def __exit__(*args):
pass


class SBUSUtils:
"""
Tool to access D-Bus on a host.
"""

def __init__(self, host: MultihostHost):
self._host = host
# self.ifp = SBUSInfoPipe(host)
"""Always exists and can be used to access ``infopipe``'s objects."""

def getDestination(self, dest: str, bus: str = DBUSKnownBus.SYSTEM) -> DBUSDestination:
return DBUSDestination(self._host, dest, bus)

def getInfoPipe(self):
return DBUSDestination(self._host, dest="org.freedesktop.sssd.infopipe", bus=DBUSKnownBus.SYSTEM)
return DBUSObject(self.host, dest=self._dest, objpath=objpath, bus=self._bus)

def __enter__(self):
return self
Expand Down

0 comments on commit 470185a

Please sign in to comment.