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

utils sssd, adding clean flag, clearing the cache on starts and restarts #136

Open
wants to merge 2 commits 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
4 changes: 3 additions & 1 deletion sssd_test_framework/hosts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def backup(self) -> Any:
backup /etc/sssd "$path/config"
backup /var/log/sssd "$path/logs"
backup /var/lib/sss "$path/lib"
backup /home "$path/home"

echo $path
""",
Expand Down Expand Up @@ -148,12 +149,13 @@ def restore(self, backup_data: Any | None) -> None:
fi
}}

rm --force --recursive /etc/sssd /var/lib/sss /var/log/sssd
rm --force --recursive /etc/sssd /var/lib/sss /var/log/sssd /home
restore "{backup_path}/krb5.conf" /etc/krb5.conf
restore "{backup_path}/krb5.keytab" /etc/krb5.keytab
restore "{backup_path}/config" /etc/sssd
restore "{backup_path}/logs" /var/log/sssd
restore "{backup_path}/lib" /var/lib/sss
restore "{backup_path}/home" /home
""",
log_level=ProcessLogLevel.Error,
)
31 changes: 25 additions & 6 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 = 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, defaults to False
: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 = 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, defaults to False
: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,9 @@ def async_restart(
if service == "sssd":
self.svc.async_stop("sssd-kcm.service")

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

return self.svc.async_restart(service)

def restart(
Expand All @@ -257,6 +275,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 +290,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 +302,9 @@ def restart(
if service == "sssd":
self.svc.stop("sssd-kcm.service")

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

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,20 +899,15 @@ def autofs(self) -> None:
self.sssd.authselect.select("sssd")
self.sssd.enable_responder("autofs")

def mkhomedir(self, homedir: str = "/home") -> None:
def mkhomedir(self) -> None:
"""
Configure SSSD with mkhomedir and oddjobd.

:param homedir: Home directory path.
:type homedir: str | None, optional

#. Select authselect sssd profile with 'with-mkhomedir'
#. Start oddjobd.service
#. Backup home directory
"""
self.sssd.authselect.select("sssd", ["with-mkhomedir"])
self.sssd.svc.start("oddjobd.service")
self.sssd.fs.backup(homedir)
danlavu marked this conversation as resolved.
Show resolved Hide resolved

def proxy(
self,
Expand Down