From baee7238b82908663d07cc025996895380abe70b Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Sat, 14 Jan 2017 15:40:24 +0100 Subject: [PATCH] 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"). Signed-off-by: Nicolas Iooss --- python/semanage/test-semanage.py | 2 +- python/sepolicy/test_sepolicy.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/semanage/test-semanage.py b/python/semanage/test-semanage.py index 12ffc98a..c8f6ec23 100644 --- a/python/semanage/test-semanage.py +++ b/python/semanage/test-semanage.py @@ -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: diff --git a/python/sepolicy/test_sepolicy.py b/python/sepolicy/test_sepolicy.py index 61dfb455..304e56f6 100644 --- a/python/sepolicy/test_sepolicy.py +++ b/python/sepolicy/test_sepolicy.py @@ -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")