summaryrefslogtreecommitdiffstats
path: root/ipaplatform/fedora
diff options
context:
space:
mode:
authorFrancesco Marella <fmarella@gmx.com>2014-09-26 14:07:25 +0200
committerPetr Viktorin <pviktori@redhat.com>2014-09-30 19:03:40 +0200
commitf5b302be47eb94fb064af6b9a1855da4d318898e (patch)
treeea0254ec88b4bfd97e49551a3c26650ec3a97c81 /ipaplatform/fedora
parent915837c14af5f0839d1d08683ea8332334e284ba (diff)
downloadfreeipa-f5b302be47eb94fb064af6b9a1855da4d318898e.tar.gz
freeipa-f5b302be47eb94fb064af6b9a1855da4d318898e.tar.xz
freeipa-f5b302be47eb94fb064af6b9a1855da4d318898e.zip
Refactor selinuxenabled check
Ticket: https://fedorahosted.org/freeipa/ticket/4571 Reviewed-By: Thierry Bordaz <tbordaz@redhat.com>
Diffstat (limited to 'ipaplatform/fedora')
-rw-r--r--ipaplatform/fedora/tasks.py43
1 files changed, 20 insertions, 23 deletions
diff --git a/ipaplatform/fedora/tasks.py b/ipaplatform/fedora/tasks.py
index 351f523c1..279fbc07f 100644
--- a/ipaplatform/fedora/tasks.py
+++ b/ipaplatform/fedora/tasks.py
@@ -48,6 +48,22 @@ from ipaplatform.base.tasks import BaseTaskNamespace
log = log_mgr.get_logger(__name__)
+def selinux_enabled():
+ """
+ Check if SELinux is enabled.
+ """
+ if os.path.exists(paths.SELINUXENABLED):
+ try:
+ ipautil.run([paths.SELINUXENABLED])
+ return True
+ except ipautil.CalledProcessError:
+ # selinuxenabled returns 1 if not enabled
+ return False
+ else:
+ # No selinuxenabled, no SELinux
+ return False
+
+
class FedoraTaskNamespace(BaseTaskNamespace):
def restore_context(self, filepath, restorecon=paths.SBIN_RESTORECON):
@@ -59,14 +75,8 @@ class FedoraTaskNamespace(BaseTaskNamespace):
ipautil.run() will do the logging.
"""
- try:
- if os.path.exists(paths.SELINUXENABLED):
- ipautil.run([paths.SELINUXENABLED])
- else:
- # No selinuxenabled, no SELinux
- return
- except ipautil.CalledProcessError:
- # selinuxenabled returns 1 if not enabled
+
+ if not selinux_enabled():
return
if (os.path.exists(restorecon)):
@@ -82,14 +92,7 @@ class FedoraTaskNamespace(BaseTaskNamespace):
This function returns nothing but may raise a Runtime exception
if SELinux is enabled but restorecon is not available.
"""
- try:
- if os.path.exists(paths.SELINUXENABLED):
- ipautil.run([paths.SELINUXENABLED])
- else:
- # No selinuxenabled, no SELinux
- return
- except ipautil.CalledProcessError:
- # selinuxenabled returns 1 if not enabled
+ if not selinux_enabled():
return
if not os.path.exists(restorecon):
@@ -354,13 +357,7 @@ class FedoraTaskNamespace(BaseTaskNamespace):
return args
- if (os.path.exists(paths.SELINUXENABLED)):
- try:
- ipautil.run([paths.SELINUXENABLED])
- except ipautil.CalledProcessError:
- # selinuxenabled returns 1 if not enabled
- return False
- else:
+ if not selinux_enabled():
return False
updated_vars = {}