|
| 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