Skip to content

Commit

Permalink
Add a module for nsldc support.
Browse files Browse the repository at this point in the history
Create a module that will configure nslcd in client machine.
  • Loading branch information
aborah-sudo committed Aug 4, 2023
1 parent 97a3994 commit 08cfe22
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
56 changes: 56 additions & 0 deletions sssd_test_framework/misc/nslcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Configuring nslcd."""

from __future__ import annotations

from pytest_mh import MultihostHost, MultihostUtility
from pytest_mh.utils.fs import LinuxFileSystem
from sssd_test_framework.roles.ldap import LDAP

__all__ = [
"Nslcd",
]


class Nslcd(MultihostUtility[MultihostHost]):
"""
Use nslcd to configure sssd proxy.
.. code-block:: python
:caption: Example usage
@pytest.mark.topology(KnownTopology.LDAP)
def test_example(client: Client, ldap: LDAP):
client.nslcd.confignslcd(ldap)
.. note::
All changes are automatically reverted when a test is finished.
"""

def __init__(self, host: MultihostHost, fs: LinuxFileSystem) -> None:
"""
:param host: Remote host instance.
:type host: MultihostHost
:param fs: Linux file system
:type fs: LinuxFileSystem
"""
super().__init__(host)
self.fs: LinuxFileSystem = fs

def confignslcd(self, ldap: LDAP) -> None:
"""
Configure nslcd.
:param ldap: Ldap role.
:type ldap: LDAP
"""
self.fs.write('/etc/pam.d/sssdproxyldap', '''
auth required pam_ldap.so
account required pam_ldap.so
password required pam_ldap.so
session required pam_ldap.so
''')
self.fs.write('/etc/nslcd.conf', f'uid nslcd\ngid ldap\nuri '
f'ldap://{ldap.host.hostname}\nbase '
f'{ldap.ldap.naming_context}\n', dedent=False)
self.host.ssh.run("systemctl restart nslcd")
5 changes: 5 additions & 0 deletions sssd_test_framework/roles/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..utils.sssctl import SSSCTLUtils
from ..utils.sssd import SSSDUtils
from .base import BaseLinuxRole
from ..misc.nslcd import Nslcd

__all__ = [
"Client",
Expand Down Expand Up @@ -69,6 +70,10 @@ def __init__(self, *args, **kwargs) -> None:
"""
Managing local overrides users and groups.
"""
self.nslcd = Nslcd(self.host, self.fs)
"""
Managing nslcd configuration.
"""

def setup(self) -> None:
"""
Expand Down

0 comments on commit 08cfe22

Please sign in to comment.