Skip to content

Commit e84826b

Browse files
shridhargadekardanlavu
authored andcommitted
realm: add methods for realm utility
realm utility is a tool manage enrollment in realm. This PR is adding methods provided by realm utility.
1 parent c727782 commit e84826b

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

sssd_test_framework/roles/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ..utils.automount import AutomountUtils
1010
from ..utils.ldb import LDBUtils
1111
from ..utils.local_users import LocalUsersUtils
12+
from ..utils.realmd import RealmUtils
1213
from ..utils.sbus import DBUSDestination, DBUSKnownBus
1314
from ..utils.sss_override import SSSOverrideUtils
1415
from ..utils.sssctl import SSSCTLUtils
@@ -53,6 +54,11 @@ def __init__(self, *args, **kwargs) -> None:
5354
Call commands from sssctl.
5455
"""
5556

57+
self.realm: RealmUtils = RealmUtils(self.host)
58+
"""
59+
Call commands from realm.
60+
"""
61+
5662
self.ldb: LDBUtils = LDBUtils(self.host)
5763
"""
5864
Utility for ldb functions.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""Manage realm operations."""
2+
3+
from __future__ import annotations
4+
5+
from pytest_mh import MultihostHost, MultihostUtility
6+
from pytest_mh.conn import ProcessResult
7+
8+
__all__ = [
9+
"RealmUtils",
10+
]
11+
12+
13+
class RealmUtils(MultihostUtility[MultihostHost]):
14+
"""
15+
Interface to the realm utility.
16+
17+
.. code-block:: python
18+
:caption: Example usage
19+
20+
@pytest.mark.topology(KnownTopology.AD)
21+
def test_realm_discover(client: Client, provider: ADProvider):
22+
r = client.realm.discover(["--use-ldaps"])
23+
assert provider.host.domain in r.stdout, "realm failed to discover domain info!"
24+
25+
"""
26+
27+
def discover(self, domain: str | None = None, *, args: list[str] | None = None) -> ProcessResult:
28+
"""
29+
Discover a realm and it's capabilities.
30+
31+
:param domain: domain, defaults to None
32+
:type domain: str, optional
33+
:param args: Additional arguments, defaults to None
34+
:type args: list[str] | None, optional
35+
"""
36+
if args is None:
37+
args = []
38+
if domain is None:
39+
domain = ""
40+
41+
return self.host.conn.exec(["realm", "discover", domain, *args])
42+
43+
def leave(self, domain, args: list[str] | None = None) -> ProcessResult:
44+
"""
45+
Deconfigure and remove a client from realm.
46+
47+
:param domain: domain, defaults to None
48+
:type domain: str, optional
49+
:param args: Additional arguments, defaults to None
50+
:type args: list[str] | None, optional
51+
"""
52+
if args is None:
53+
args = []
54+
if domain is None:
55+
domain = ""
56+
57+
return self.host.conn.exec(["realm", "leave", "--verbose", domain, *args])
58+
59+
def join(
60+
self,
61+
domain: str,
62+
*,
63+
args: list[str] | None = None,
64+
password: str,
65+
user: str,
66+
krb: bool = False,
67+
) -> ProcessResult:
68+
"""
69+
Join and configure a client to realm.
70+
71+
:param domain: Domain to join.
72+
:type domain: str
73+
:param args: Additional arguments, defaults to None
74+
:type args: list[str] | None, optional
75+
:param password: Password to run the operation.
76+
:type password: str
77+
:param user: Authenticating user.
78+
:type user: str
79+
:param krb: Enable kerberos authentication, defaults to False
80+
:type krb: bool
81+
"""
82+
if args is None:
83+
args = []
84+
85+
if krb:
86+
self.host.conn.exec(["kinit", user], input=password)
87+
result = self.host.conn.exec(["realm", "join", "--verbose", *args, domain])
88+
else:
89+
result = self.host.conn.exec(["realm", "join", "--verbose", *args, "-U", user, domain], input=password)
90+
91+
return result
92+
93+
def list(self, *, args: list[str] | None = None) -> ProcessResult:
94+
"""
95+
List discovered, and configured realms.
96+
97+
:param args: Additional arguments, defaults to None
98+
:type args: list[str] | None, optional
99+
"""
100+
if args is None:
101+
args = []
102+
103+
return self.host.conn.exec(["realm", "list", "--verbose", *args])

0 commit comments

Comments
 (0)