Skip to content

realm: add methods for realm utility #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sssd_test_framework/hosts/ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def __init__(self, *args, **kwargs) -> None:
self.adminpw: str = self.config.get("adminpw", "Secret123")
"""Password of the Administrator user, defaults to ``Secret123``."""

self.adminuser: str = self.config.get("adminuser", "Administrator")
"""Administrator user, defaults to ``Administrator``."""

# Additional client configuration
self.client.setdefault("id_provider", "ad")
self.client.setdefault("access_provider", "ad")
Expand Down
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 RealmUtils
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.realm: RealmUtils = RealmUtils(self.host)
"""
Call commands from realm.
"""

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

from __future__ import annotations

from pytest_mh import MultihostHost, MultihostUtility
from pytest_mh.conn import ProcessResult

__all__ = [
"RealmUtils",
]


class RealmUtils(MultihostUtility[MultihostHost]):
"""
Interface to the realm utility.

.. code-block:: python
:caption: Example usage

@pytest.mark.topology(KnownTopology.AD)
def test_realm_discover(client: Client, provider: ADProvider):
r = client.realm.discover(["--use-ldaps"])
assert provider.host.domain in r.stdout, "realm failed to discover domain info!"

"""

def discover(self, domain: str | None = None, *, args: list[str] | None = None) -> ProcessResult:
"""
Discover a realm and it's capabilities.

:param domain: domain, defaults to None
:type domain: str, optional
:param args: Additional arguments, defaults to None
:type args: list[str] | None, optional
"""
if args is None:
args = []
if domain is None:
domain = ""

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

def leave(self, domain, args: list[str] | None = None) -> ProcessResult:
"""
Deconfigure and remove a client from realm.

:param domain: domain, defaults to None
:type domain: str, optional
:param args: Additional arguments, defaults to None
:type args: list[str] | None, optional
"""
if args is None:
args = []
if domain is None:
domain = ""

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

def join(
self,
domain: str,
*,
args: list[str] | None = None,
password: str,
user: str,
krb: bool = False,
) -> ProcessResult:
"""
Join and configure a client to realm.

:param domain: Domain to join.
:type domain: str
:param args: Additional arguments, defaults to None
:type args: list[str] | None, optional
:param password: Password to run the operation.
:type password: str
:param user: Authenticating user.
:type user: str
:param krb: Enable kerberos authentication, defaults to False
:type krb: bool
"""
if args is None:
args = []

if krb:
self.host.conn.exec(["kinit", user], input=password)
result = self.host.conn.exec(["realm", "join", "--verbose", *args, domain])
else:
result = self.host.conn.exec(["realm", "join", "--verbose", *args, "-U", user, domain], input=password)

return result

def list(self, *, args: list[str] | None = None) -> ProcessResult:
"""
List discovered, and configured realms.

:param args: Additional arguments, defaults to None
:type args: list[str] | None, optional
"""
if args is None:
args = []

return self.host.conn.exec(["realm", "list", "--verbose", *args])