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
945bc8853b ("sandbox: make test not fail on systems without SELinux").

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2017-01-14 15:40:24 +01:00 committed by Stephen Smalley
parent 5b0ad2f00e
commit baee7238b8
2 changed files with 2 additions and 2 deletions

View File

@ -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:

View File

@ -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")