Skip to content
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

Adcli: adding class and methods for adcli #145

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