From 53d14a87406c5e76c334a523e2f978c36e7171d6 Mon Sep 17 00:00:00 2001 From: shridhargadekar Date: Mon, 17 Feb 2025 15:17:51 +0530 Subject: [PATCH] realm: add methods for realm utility realm utility is a tool manage enrollment in realm. This PR is adding methods provided by realm utility. --- sssd_test_framework/roles/client.py | 6 ++ sssd_test_framework/utils/realmd.py | 110 ++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 sssd_test_framework/utils/realmd.py diff --git a/sssd_test_framework/roles/client.py b/sssd_test_framework/roles/client.py index 829fd0a0..4465497d 100644 --- a/sssd_test_framework/roles/client.py +++ b/sssd_test_framework/roles/client.py @@ -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 @@ -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. diff --git a/sssd_test_framework/utils/realmd.py b/sssd_test_framework/utils/realmd.py new file mode 100644 index 00000000..deb8c006 --- /dev/null +++ b/sssd_test_framework/utils/realmd.py @@ -0,0 +1,110 @@ +"""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 leave `` 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 = [] + + 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])