From 9990697a1702e65d43e513556bc4ca1f608d5814 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Mon, 11 Jun 2012 19:01:45 +0800 Subject: [PATCH] move selinux_check func to misc module Signed-off-by: Gui Chen --- mic/conf.py | 37 ++++--------------------------------- mic/utils/misc.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/mic/conf.py b/mic/conf.py index 972c048..0cc5797 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -182,37 +182,6 @@ class ConfigMgr(object): self.bootstraps[name] = repostr - def _selinux_check(self, arch, ks): - """If a user needs to use btrfs or creates ARM image, - selinux must be disabled at start. - """ - - for path in ["/usr/sbin/getenforce", - "/usr/bin/getenforce", - "/sbin/getenforce", - "/bin/getenforce", - "/usr/local/sbin/getenforce", - "/usr/locla/bin/getenforce" - ]: - 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 disable it and try again") - - use_btrfs = False - 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 using btrfs " - "filesystem if selinux is enabled, " - "please disable it and try again.") - break - def _parse_kickstart(self, ksconf=None): if not ksconf: return @@ -226,8 +195,6 @@ class ConfigMgr(object): self.create['name'] = "%s-%s" % (self.create['name_prefix'], self.create['name']) - self._selinux_check (self.create['arch'], ks) - msger.info("Retrieving repo metadata:") ksrepos = misc.get_repostrs_from_ks(ks) if not ksrepos: @@ -257,4 +224,8 @@ class ConfigMgr(object): kickstart.resolve_groups(self.create, self.create['repomd']) + # check selinux, it will block arm and btrfs image creation + misc.selinux_check(self.create['arch'], + [p.fstype for p in ks.handler.partition.partitions]) + configmgr = ConfigMgr() diff --git a/mic/utils/misc.py b/mic/utils/misc.py index df2ced7..f4b461c 100644 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -200,6 +200,22 @@ def _check_meego_chroot(rootdir): return +def selinux_check(arch, fstypes): + try: + getenforce = find_binary_path('getenforce') + except CreatorError: + return + + selinux_status = runner.outs([getenforce]) + if arch and arch.startswith("arm") and selinux_status == "Enforcing": + raise CreatorError("Can't create arm image if selinux is enabled, " + "please run 'setenforce 0' to disable selinux") + + use_btrfs = filter(lambda typ: typ == 'btrfs', fstypes) + if use_btrfs and selinux_status == "Enforcing": + raise CreatorError("Can't create btrfs image if selinux is enabled," + " please run 'setenforce 0' to disable selinux") + def get_image_type(path): def _get_extension_name(path): match = re.search("(?<=\.)\w+$", path) -- 2.7.4