Skip to content

Commit

Permalink
utils sssd, adding clean flag, clearing the cache on starts and restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lavu committed Nov 6, 2024
1 parent 6bc1716 commit 0c2c3fb
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions sssd_test_framework/utils/sssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def async_start(
apply_config: bool = True,
check_config: bool = True,
debug_level: str | None = "0xfff0",
clean: bool | None = False,
) -> Process:
"""
Start the SSSD and KCM services. Non-blocking call.
Expand All @@ -133,6 +134,8 @@ def async_start(
:type check_config: bool, optional
:param debug_level: Automatically set debug level to the given value, defaults to 0xfff0
:type debug_level: str | None, optional
:param clean: Does a clean restart, clearing the cache, defaults to False
:type clean: bool, optional
:return: Running SSH process.
:rtype: Process
"""
Expand All @@ -145,6 +148,9 @@ def async_start(
if service == "sssd":
self.svc.async_stop("sssd-kcm.service")

if clean and service == "sssd":
self.clear()

return self.svc.async_start(service)

def start(
Expand All @@ -156,6 +162,7 @@ def start(
apply_config: bool = True,
check_config: bool = True,
debug_level: str | None = "0xfff0",
clean: bool | None = False,
) -> ProcessResult:
"""
Start the SSSD and KCM services. The call will wait until the operation is finished.
Expand All @@ -172,6 +179,8 @@ def start(
:type check_config: bool, optional
:param debug_level: Automatically set debug level to the given value, defaults to 0xfff0
:type debug_level: str | None, optional
:param clean: Does a clean restart, clearing the cache, defaults to False
:type clean: bool, optional
:return: SSH process result.
:rtype: ProcessResult
"""
Expand All @@ -184,6 +193,9 @@ def start(
if service == "sssd":
self.svc.stop("sssd-kcm.service")

if clean and service == "sssd":
self.clear()

return self.svc.start(service, raise_on_error=raise_on_error)

def async_stop(self, service="sssd") -> Process:
Expand Down Expand Up @@ -225,6 +237,7 @@ def async_restart(
apply_config: bool = True,
check_config: bool = True,
debug_level: str | None = "0xfff0",
clean: bool = False,
) -> Process:
"""
Restart the SSSD and KCM services. Non-blocking call.
Expand All @@ -237,6 +250,8 @@ def async_restart(
:type check_config: bool, optional
:param debug_level: Automatically set debug level to the given value, defaults to 0xfff0
:type debug_level: str | None, optional
:param clean: Does a clean restart, clearing the cache, defaults to False
:type clean: bool, defaults to False
:return: Running SSH process.
:rtype: Process
"""
Expand All @@ -247,6 +262,11 @@ def async_restart(
if service == "sssd":
self.svc.async_stop("sssd-kcm.service")

if clean and service == "sssd":
self.svc.stop(service)
self.clear()
return self.svc.async_restart(service)

return self.svc.async_restart(service)

def restart(
Expand All @@ -257,6 +277,7 @@ def restart(
apply_config: bool = True,
check_config: bool = True,
debug_level: str | None = "0xfff0",
clean: bool = False,
) -> ProcessResult:
"""
Restart the SSSD and KCM services. The call will wait until the operation is finished.
Expand All @@ -271,6 +292,8 @@ def restart(
:type check_config: bool, optional
:param debug_level: Automatically set debug level to the given value, defaults to 0xfff0
:type debug_level: str | None, optional
:param clean: Does a clean restart, clearing the cache, defaults to False
:type clean: bool, defaults to False
:return: SSH process result.
:rtype: ProcessResult
"""
Expand All @@ -281,6 +304,11 @@ def restart(
if service == "sssd":
self.svc.stop("sssd-kcm.service")

if clean and service == "sssd":
self.svc.stop(service)
self.clear()
return self.svc.start(service, raise_on_error=raise_on_error)

return self.svc.restart(service, raise_on_error=raise_on_error)

def clear(self, *, db: bool = True, memcache: bool = True, config: bool = False, logs: bool = False):
Expand Down Expand Up @@ -875,14 +903,14 @@ def autofs(self) -> None:
self.sssd.authselect.select("sssd")
self.sssd.enable_responder("autofs")

def mkhomedir(self, homedir: str = "/home", clean: bool | None = False) -> None:
def mkhomedir(self, homedir: str = "/home", clean: bool = False) -> None:
"""
Configure SSSD with mkhomedir and oddjobd.
:param homedir: Home directory path.
:type homedir: str | None, optional
:param clean: Clears contents for a clean directory.
:type clean: bool | None, optional
:type clean: bool, defaults to False
#. Select authselect sssd profile with 'with-mkhomedir'
#. Start oddjobd.service
Expand Down

0 comments on commit 0c2c3fb

Please sign in to comment.