Skip to contentSkip to conversation

semanage, sepolicy: make tests not fail on systems without SELinux

PATCH Applied Nicolas Iooss 2 participants 2 messages Jan 14, 2017 – Jan 17, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

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
index 12ffc98afd6e..c8f6ec231fc2 100644
@@ -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
index 61dfb4550830..304e56f60a7c 100644
@@ -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
#1 lore raw
Quoted 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, test selinux.is_selinux_enabled() too, like commit 945bc8853b62 ("sandbox: make test not fail on systems without SELinux").

Thanks, applied.

Quoted 39 lines

---
 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
index 12ffc98afd6e..c8f6ec231fc2 100644

python/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) 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 +0 -0
index 61dfb4550830..304e56f60a7c 100644
@@ -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")