Skip to content

Commit

Permalink
Adcli: adding class and methods for adcli
Browse files Browse the repository at this point in the history
Adding adcli class, and methods including info, discovery, join
  • Loading branch information
shridhargadekar committed Jan 16, 2025
1 parent 7bcb65e commit dfdf2a7
Show file tree
Hide file tree
Showing 2 changed files with 86 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 @@ -12,6 +12,7 @@
from ..utils.sbus import DBUSDestination, DBUSKnownBus
from ..utils.sss_override import SSSOverrideUtils
from ..utils.sssctl import SSSCTLUtils
from ..utils.adcli import ADCLI
from ..utils.sssd import SSSDUtils
from .base import BaseLinuxRole

Expand Down Expand Up @@ -53,6 +54,11 @@ def __init__(self, *args, **kwargs) -> None:
Call commands from sssctl.
"""

self.adcli: ADCLI = ADCLI(self.host, self.fs)
"""
Call commands from adcli.
"""

self.ldb: LDBUtils = LDBUtils(self.host)
"""
Utility for ldb functions.
Expand Down
80 changes: 80 additions & 0 deletions sssd_test_framework/utils/adcli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Perform actions on Active Directory."""

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__ = [
"ADCLIUtils",
]


class ADCLI(MultihostUtility[MultihostHost]):
"""
Call commands from adcli
"""

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 info(
self,
domain: str,
) -> str:
"""
Call ``adcli info `` with given arguments.
:param domain: Displays discovered information about an Active Directory domain, defaults to None
:type domain: str | None,
:param domain_controller: Domain controller to connect, defaults to None
:type domain_controller: str | None, optional
"""
args: CLIBuilderArgs = {
"domain": (self.cli.option.POSITIONAL, domain),
"domain_controller": (self.cli.option.POSITIONAL, domain_controller),
}

return self.host.conn.exec(["adcli", "info"] + self.cli.args(args))

def testjoin(
self,
domain: str| None = None,
) -> ProcessResult:
"""
call ``adcli testjoin `` with given arguments.
:param domain: Target Active Directory domain, defaults to None
:type domain: str | None, optional
:param domain_controller: Domain controller to connect
:type domain_controller: str | None, optional
"""
args: CLIBuilderArgs = {
"domain": (self.cli.option.VALUE, domain),
"domain_controller": (self.cli.option.VALUE, domain_controller),
"host_keytab": (self.cli.option.VALUE, host_keytab),
}
return self.host.conn.exec(["adcli", "testjoin"] + self.cli.args(args))

def join(
self,
domain: str,
) -> str:
"""
call ``adcli join`` with given arguments.
:param domain: Target Active Directory domain, defaults to None
:type domain: str | None, optional
"""
args: CLIBuilderArgs = {
"domain": (self.cli.option.POSITIONAL, domain),
}
self.host.conn.exec(["adcli", "join"] + self.cli.args(args))

0 comments on commit dfdf2a7

Please sign in to comment.