From 609c7497d548c8d5421ddde5347e46939342e62b Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Thu, 27 Jun 2013 03:41:59 -0400 Subject: [PATCH] implement '--check-pkgs' to check if packages included in image check the given package list, if it will be installed, remove it from the checking list. when check done, it proves some given packages won't be installed to the image, mic should abort Signed-off-by: Gui Chen --- mic/imager/baseimager.py | 5 +++++ plugins/backend/yumpkgmgr.py | 10 ++++++++++ plugins/backend/zypppkgmgr.py | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 40d011d..b5a5290 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -922,6 +922,10 @@ class BaseImageCreator(object): for pkg in self._preinstall_pkgs: pkg_manager.preInstall(pkg) + def __check_packages(self, pkg_manager): + for pkg in self.check_pkgs: + pkg_manager.checkPackage(pkg) + def __attachment_packages(self, pkg_manager): if not self.ks: return @@ -1019,6 +1023,7 @@ class BaseImageCreator(object): self.__select_groups(pkg_manager) self.__deselect_packages(pkg_manager) self.__localinst_packages(pkg_manager) + self.__check_packages(pkg_manager) BOOT_SAFEGUARD = 256L * 1024 * 1024 # 256M checksize = self._root_fs_avail diff --git a/plugins/backend/yumpkgmgr.py b/plugins/backend/yumpkgmgr.py index 955f813..8a297be 100644 --- a/plugins/backend/yumpkgmgr.py +++ b/plugins/backend/yumpkgmgr.py @@ -127,6 +127,7 @@ class Yum(BackendPlugin, yum.YumBase): self.__pkgs_license = {} self.__pkgs_content = {} self.__pkgs_vcsinfo = {} + self.check_pkgs = [] self.install_debuginfo = False @@ -194,6 +195,9 @@ class Yum(BackendPlugin, yum.YumBase): # FIXME: handle pre-install package return None + def checkPackage(self, pkg): + self.check_pkgs.append(pkg) + def selectPackage(self, pkg): """Select a given package. Can be specified with name.arch or name* @@ -369,6 +373,12 @@ class Yum(BackendPlugin, yum.YumBase): else: self.__pkgs_license[license] = [pkg_long_name] + if pkg.name in self.check_pkgs: + self.check_pkgs.remove(pkg.name) + + if self.check_pkgs: + raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs)) + total_count = len(dlpkgs) cached_count = 0 download_total_size = sum(map(lambda x: int(x.packagesize), dlpkgs)) diff --git a/plugins/backend/zypppkgmgr.py b/plugins/backend/zypppkgmgr.py index 7ee83b6..fb01e47 100755 --- a/plugins/backend/zypppkgmgr.py +++ b/plugins/backend/zypppkgmgr.py @@ -73,6 +73,7 @@ class Zypp(BackendPlugin): self.incpkgs = {} self.excpkgs = {} self.pre_pkgs = [] + self.check_pkgs = [] self.probFilterFlags = [ rpm.RPMPROB_FILTER_OLDPACKAGE, rpm.RPMPROB_FILTER_REPLACEPKG ] @@ -443,6 +444,9 @@ class Zypp(BackendPlugin): def preInstall(self, pkg): self.pre_pkgs.append(pkg) + def checkPackage(self, pkg): + self.check_pkgs.append(pkg) + def runInstall(self, checksize = 0): os.environ["HOME"] = "/" os.environ["LD_PRELOAD"] = "" @@ -451,12 +455,16 @@ class Zypp(BackendPlugin): todo = zypp.GetResolvablesToInsDel(self.Z.pool()) installed_pkgs = todo._toInstall dlpkgs = [] + for pitem in installed_pkgs: if not zypp.isKindPattern(pitem) and \ not self.inDeselectPackages(pitem): item = zypp.asKindPackage(pitem) dlpkgs.append(item) + if item.name() in self.check_pkgs: + self.check_pkgs.remove(item.name()) + if not self.install_debuginfo or str(item.arch()) == "noarch": continue @@ -468,6 +476,9 @@ class Zypp(BackendPlugin): msger.warning("No debuginfo rpm found for: %s" \ % item.name()) + if self.check_pkgs: + raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs)) + # record all pkg and the content localpkgs = self.localpkgs.keys() for pkg in dlpkgs: -- 2.7.4