Skip to content

Commit f5478ba

Browse files
committed
framework: Add selinux_permissive_for_test context manager
Add context manager to BaseLinuxHost that temporarily sets SELinux to permissive mode for tests. This is needed for proxy provider tests that use nslcd (nss-pam-ldapd), as this test-only configuration lacks proper SELinux policies in enforcing mode.
1 parent bf0af01 commit f5478ba

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

sssd_test_framework/hosts/base.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import csv
67
import re
7-
from typing import Any
8+
from typing import Any, Generator
89

910
import ldap
1011
from ldap.ldapobject import ReconnectLDAPObject
@@ -345,3 +346,20 @@ def version_tuple(ver):
345346
return 1
346347
else:
347348
return 0
349+
350+
@contextlib.contextmanager
351+
def selinux_permissive_for_test(self) -> Generator[None, None, None]:
352+
"""Temporarily set SELinux to permissive for tests."""
353+
result = self.conn.run("getenforce")
354+
if result.stdout.strip() != "Enforcing":
355+
yield
356+
return
357+
358+
self.conn.run("setenforce 0")
359+
360+
try:
361+
yield
362+
finally:
363+
result = self.conn.run("setenforce 1", raise_on_error=False)
364+
if result.rc != 0:
365+
self.logger.warning("Failed to restore SELinux to enforcing mode.")

0 commit comments

Comments
 (0)