From 81d3d673944fc61de4616b5572d24719637d1d50 Mon Sep 17 00:00:00 2001 From: Francesco Marella <fmare...@gmx.com> Date: Fri, 26 Sep 2014 14:07:25 +0200 Subject: [PATCH] Refactor selinuxenabled check
Ticket: https://fedorahosted.org/freeipa/ticket/4571 --- ipaplatform/fedora/tasks.py | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/ipaplatform/fedora/tasks.py b/ipaplatform/fedora/tasks.py index 9f4a76b8208cc78c330dc022730c4faac09995f9..439a045c96440342105bad7f9e587398a8894124 100644 --- a/ipaplatform/fedora/tasks.py +++ b/ipaplatform/fedora/tasks.py @@ -50,6 +50,20 @@ log = log_mgr.get_logger(__name__) class FedoraTaskNamespace(BaseTaskNamespace): + def check_enabled_selinux(self): + """ + Check if SELinux is enabled. + """ + if os.path.exists(paths.SELINUXENABLED): + try: + ipautil.run([paths.SELINUXENABLED]) + except ipautil.CalledProcessError: + # selinuxenabled returns 1 if not enabled + return False + else: + # No selinuxenabled, no SELinux + return False + def restore_context(self, filepath, restorecon=paths.SBIN_RESTORECON): """ restore security context on the file path @@ -59,15 +73,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 - return + + self.check_enabled_selinux() if (os.path.exists(restorecon)): ipautil.run([restorecon, filepath], raiseonerr=False) @@ -82,15 +89,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 - return + self.check_enabled_selinux() if not os.path.exists(restorecon): raise RuntimeError('SELinux is enabled but %s does not exist.\n' @@ -336,14 +335,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: - return False + self.check_enabled_selinux() updated_vars = {} failed_vars = {} -- 2.1.1
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel