BMC#18552: selinux checking for btrfs and ARM
authorZhang Qiang <qiang.z.zhang@intel.com>
Thu, 27 Oct 2011 06:16:48 +0000 (14:16 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Thu, 27 Oct 2011 06:16:48 +0000 (14:16 +0800)
backport mic2 commit:
    30d7b89bc357a199a99d216c7e82059f5a30bf1f

mic/configmgr.py

index f56e7a6..6cebfbe 100644 (file)
@@ -20,7 +20,7 @@ import ConfigParser
 
 from mic import kickstart
 from mic import msger
-from mic.utils import misc
+from mic.utils import misc, runner
 from mic.utils import errors
 
 DEFAULT_GSITECONF='/etc/mic/mic.conf'
@@ -111,6 +111,35 @@ class ConfigMgr(object):
             value = siteconf_parser.get('chroot', option)
             self.chroot[option] = value
 
+    def selinux_check(self, arch, ks):
+        """ If a user needs to use btrfs or creates ARM image, selinux must be disabled at start """
+
+        paths = ["/usr/sbin/getenforce",
+                 "/usr/bin/getenforce",
+                 "/sbin/getenforce",
+                 "/bin/getenforce",
+                 "/usr/local/sbin/getenforce",
+                 "/usr/locla/bin/getenforce"
+                ]
+
+        for path in paths:
+            if os.path.exists(path):
+                selinux_status = runner.outs([path])
+                if  arch and arch.startswith("arm") and selinux_status == "Enforcing":
+                    raise errors.ConfigError("Can't create arm image if selinux is enabled, please disbale it and try again")
+
+                use_btrfs = False
+                parts = ks.handler.partition.partitions
+                for part in ks.handler.partition.partitions:
+                    if part.fstype == "btrfs":
+                        use_btrfs = True
+                        break
+
+                if use_btrfs and selinux_status == "Enforcing":
+                    raise errors.ConfigError("Can't create image useing btrfs filesystem if selinux is enabled, please disbale it and try again")
+
+                break
+
     def parse_kickstart(self, ksconf=None):
         if not ksconf:
             return
@@ -120,6 +149,8 @@ class ConfigMgr(object):
         self.create['ks'] = ks
         self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0]
 
+        self.selinux_check (self.create['arch'], ks)
+
         msger.info("Retrieving repo metadata:")
         ksrepos = misc.get_repostrs_from_ks(ks)
         self.create['repomd'] = misc.get_metadata_from_repos(ksrepos, self.create['cachedir'])