Skip to contentSkip to conversation

sandbox: make test not fail on systems without SELinux

PATCH Applied Nicolas Iooss 2 participants 2 messages Nov 17, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sandbox: make test not fail on systems without SELinux

On systems without SELinux (eg. some continuous integration environments), "make test" fails with:

Traceback (most recent call last):
File "test_sandbox.py", line 110, in <module>
if selinux.security_getenforce() == 1:
FileNotFoundError: [Errno 2] No such file or directory

This is exception is thrown because the selinuxfs file system is not mounted.

Detect such configurations using selinux.is_selinux_enabled() and skip the test when SELinux is disabled accordingly.

---
 sandbox/test_sandbox.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sandbox/test_sandbox.py +1 -1
index bcecf66ee257..ba849a08141d 100644
@@ -107,7 +107,7 @@ class SandboxTests(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.10.2
#1 lore raw
Quoted 8 lines · Nicolas Iooss

On systems without SELinux (eg. some continuous integration environments), "make test" fails with:

Traceback (most recent call last):
File "test_sandbox.py", line 110, in <module>
if selinux.security_getenforce() == 1:
FileNotFoundError: [Errno 2] No such file or directory

Quoted 7 lines

This is exception is thrown because the selinuxfs file system is not mounted.

Detect such configurations using selinux.is_selinux_enabled() and skip the test when SELinux is disabled accordingly.

Thanks, applied

Quoted 18 lines
---
 sandbox/test_sandbox.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sandbox/test_sandbox.py +1 -1
index bcecf66ee257..ba849a08141d 100644
@@ -107,7 +107,7 @@ class SandboxTests(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")