Skip to content

Commit

Permalink
realm: add methods for realm utility
Browse files Browse the repository at this point in the history
realm utility is a tool manage enrollment in realm. This PR
is adding methods provided by realm utility.
  • Loading branch information
shridhargadekar committed Feb 17, 2025
1 parent 7bcb65e commit 08c9668
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sssd_test_framework/roles/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..utils.automount import AutomountUtils
from ..utils.ldb import LDBUtils
from ..utils.local_users import LocalUsersUtils
from ..utils.realmd import Realmd
from ..utils.sbus import DBUSDestination, DBUSKnownBus
from ..utils.sss_override import SSSOverrideUtils
from ..utils.sssctl import SSSCTLUtils
Expand Down Expand Up @@ -53,6 +54,11 @@ def __init__(self, *args, **kwargs) -> None:
Call commands from sssctl.
"""

self.realmd: Realmd = Realmd(self.host, self.fs)
"""
Call commands from realmd.
"""

self.ldb: LDBUtils = LDBUtils(self.host)
"""
Utility for ldb functions.
Expand Down
108 changes: 108 additions & 0 deletions sssd_test_framework/utils/realmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""Manage enrollment in realms"""

from __future__ import annotations

from pytest_mh import MultihostHost, MultihostUtility
from pytest_mh.cli import CLIBuilder, CLIBuilderArgs
from pytest_mh.conn import ProcessResult
from pytest_mh.utils.fs import LinuxFileSystem

__all__ = [
"realmdUtils",
]


class Realmd(MultihostUtility[MultihostHost]):
"""
Call commands from realmd
"""

def __init__(self, host: MultihostHost, fs: LinuxFileSystem) -> None:
super().__init__(host)

self.cli: CLIBuilder = self.host.cli
"""Command line builder."""

self.fs: LinuxFileSystem = fs
"""Filesystem utils."""

def discover(
self,
args: list[Any]| None = None,
) -> ProcessResult:
"""
Call ``realm discover `` with given arguments.
:param domain: Discover information about domains
:type domain: str,
:param args: additional arguments to pass to the discover operation
:type args: list,
"""
if args is None:
args = []

return self.host.conn.exec(["realm", "discover", *args])

def leave(
self,
args: list[Any] | None = None
) -> ProcessResult:
"""
Call ``realm discover `` with given arguments.
:param args: additional arguments to pass to the leave operation
:type args: list,
"""
if args is None:
args = []

return self.host.conn.exec(["realm", "leave", *args])

def join(
self,
domain: str,
args: list[Any] | None = None,
passwd: str | None = None,
) -> ProcessResult:
"""
Call ``realm join `` with given arguments.
:param domain: join information about domains
:type domain: str,
:param args: additional arguments to pass to the join operation
:type args: list,
"""
if args is None:
args = []
dom = domain.upper()
return self.host.conn.exec(["realm", "join", "--verbose", *args, domain], input=passwd)

def list(
self,
args: list[Any] | None = None,
) -> ProcessResult:
"""
Call ``realm list `` with given arguments.
List all discovered, and configured realms
:param args: additional arguments to pass to the list operation
:type args: list,
"""
if args is None:
args = []
return self.host.conn.exec(["realm", "list", *args])

def permit(
self,
args: list[Any] | None = None,
) -> ProcessResult:
"""
Call ``realm permit `` with given arguments.
Permit local login by users of the realm
:param args: permit information about domains
:type args: list,
"""
if args is None:
args = []
return self.host.conn.exec(["realm", "permit", *args])

0 comments on commit 08c9668

Please sign in to comment.