diff mbox

[1/1] semanage, sepolicy: make tests not fail on systems without SELinux

Message ID 20170114144024.4709-1-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Jan. 14, 2017, 2:40 p.m. UTC
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 <nicolas.iooss@m4x.org>
---
 python/semanage/test-semanage.py | 2 +-
 python/sepolicy/test_sepolicy.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Stephen Smalley Jan. 17, 2017, 9:49 p.m. UTC | #1
On Sat, 2017-01-14 at 15:40 +0100, Nicolas Iooss wrote:
> 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.

> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
>  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 12ffc98afd6e..c8f6ec231fc2 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 61dfb4550830..304e56f60a7c 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")
diff mbox

Patch

diff --git a/python/semanage/test-semanage.py b/python/semanage/test-semanage.py
index 12ffc98afd6e..c8f6ec231fc2 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 61dfb4550830..304e56f60a7c 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")