semanage, sepolicy: make tests not fail on systems without SELinux
PATCH 1/1 semanage, sepolicy: make tests not fail on systems without SELinux
selinux.security_getenforce() triggers an exception when running tests on systems without SELinux. In order to skip tests which need SELinux in enforcing mode, test selinux.is_selinux_enabled() too, like commit 945bc8853b62 ("sandbox: make test not fail on systems without SELinux").
--- python/semanage/test-semanage.py | 2 +- python/sepolicy/test_sepolicy.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
python/semanage/test-semanage.py +1 -1
@@ -276,7 +276,7 @@ def gen_semanage_test_args(parser): if __name__ == "__main__": import selinux semanage_test_list = [x for x in dir(SemanageTests) if x.startswith("test_")] - if selinux.security_getenforce() == 1: + if selinux.is_selinux_enabled() and selinux.security_getenforce() == 1: parser = argparse.ArgumentParser(description='Semanage unit test script') gen_semanage_test_args(parser) try:
python/sepolicy/test_sepolicy.py +1 -1
@@ -115,7 +115,7 @@ class SepolicyTests(unittest.TestCase): if __name__ == "__main__": import selinux - if selinux.security_getenforce() == 1: + if selinux.is_selinux_enabled() and selinux.security_getenforce() == 1: unittest.main() else: print("SELinux must be in enforcing mode for this test")
Signature · 1 line
2.11.0
Stephen Smalley
AppliedQuoted 7 lines · Nicolas Iooss
selinux.security_getenforce()triggers an exception when running tests
on systems without SELinux. In order to skip tests which need SELinux in
enforcing mode, testselinux.is_selinux_enabled()too, like commit945bc8853b62("sandbox: make test not fail on systems without SELinux").
Thanks, applied.
Quoted 39 lines
Signed-off-by Nicolas Iooss <[email protected]>---
python/semanage/test-semanage.py | 2 +-
python/sepolicy/test_sepolicy.py | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)python/semanage/test- renamed from python/semanage/test-semanage.py +0
-0
semanage.py
index12ffc98afd6e..c8f6ec231fc2100644python/semanage/test-semanage.py +0
-0@@ -276,7 +276,7 @@ def gen_semanage_test_args(parser):if
__name__== "__main__":
import selinux
semanage_test_list = [x for x in dir(SemanageTests) ifx.startswith("test_")]
- ifselinux.security_getenforce()== 1:
+ ifselinux.is_selinux_enabled()andselinux.security_getenforce()== 1:
parser =argparse.ArgumentParser(description='Semanage unit test script')
gen_semanage_test_args(parser)
try:python/sepolicy/test_sepolicy.py +0
-0@@ -115,7 +115,7 @@ class SepolicyTests(unittest.TestCase):
if__name__== "__main__":
import selinux
- ifselinux.security_getenforce()== 1:
+ ifselinux.is_selinux_enabled()andselinux.security_getenforce()== 1:
unittest.main()
else:
print("SELinux must be in enforcing mode for this test")