From 05296a7c2fad8920d5372838bcedbde0f710b04e Mon Sep 17 00:00:00 2001 From: Andrii Boichuk Date: Wed, 23 Jul 2014 16:35:36 +0300 Subject: [PATCH] add strict_mode(MHA-1115) --- mic/conf.py | 1 + mic/creator.py | 6 ++++++ mic/imager/baseimager.py | 5 ++++- plugins/backend/yumpkgmgr.py | 7 +++++-- plugins/backend/zypppkgmgr.py | 3 ++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mic/conf.py b/mic/conf.py index 9816245..139660a 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -74,6 +74,7 @@ class ConfigMgr(object): "runtime": "bootstrap", "extrarepos": {}, "ignore_ksrepo": False, + "strict_mode": False, }, 'chroot': { "saveto": None, diff --git a/mic/creator.py b/mic/creator.py index dde1013..be4773b 100644 --- a/mic/creator.py +++ b/mic/creator.py @@ -129,6 +129,10 @@ class Creator(cmdln.Cmdln): optparser.add_option('', '--ignore-ksrepo', action='store_true', dest='ignore_ksrepo', default=False, help=SUPPRESS_HELP) + optparser.add_option('', '--strict_mode', action='store_true', + dest='strict_mode', default=False, + help='Abort creation of image, if there are some errors' + ' during rpm installation. ') return optparser def preoptparse(self, argv): @@ -226,6 +230,8 @@ class Creator(cmdln.Cmdln): configmgr.create['record_pkgs'].append(infotype) + if self.options.strict_mode: + configmgr.create['strict_mode'] = self.options.strict_mode if self.options.arch is not None: supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True) if self.options.arch in supported_arch: diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 10af5f9..63ac3b9 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -82,6 +82,7 @@ class BaseImageCreator(object): self.destdir = "." self.installerfw_prefix = "INSTALLERFW_" self.target_arch = "noarch" + self.strict_mode = False self._local_pkgs_path = None self.pack_to = None self.repourl = {} @@ -97,6 +98,7 @@ class BaseImageCreator(object): "arch" : "target_arch", "local_pkgs_path" : "_local_pkgs_path", "copy_kernel" : "_need_copy_kernel", + "strict_mode" : "strict_mode", } # update setting from createopts @@ -1358,7 +1360,8 @@ class BaseImageCreator(object): def get_pkg_manager(self): return self.pkgmgr(target_arch = self.target_arch, instroot = self._instroot, - cachedir = self.cachedir) + cachedir = self.cachedir, + strict_mode = self.strict_mode) def create_manifest(self): def get_pack_suffix(): diff --git a/plugins/backend/yumpkgmgr.py b/plugins/backend/yumpkgmgr.py index 05f4dba..8603da3 100644 --- a/plugins/backend/yumpkgmgr.py +++ b/plugins/backend/yumpkgmgr.py @@ -112,12 +112,13 @@ from mic.pluginbase import BackendPlugin class Yum(BackendPlugin, yum.YumBase): name = 'yum' - def __init__(self, target_arch, instroot, cachedir): + def __init__(self, target_arch, instroot, cachedir, strict_mode = False): yum.YumBase.__init__(self) self.cachedir = cachedir self.instroot = instroot self.target_arch = target_arch + self.strict_mode = strict_mode if self.target_arch: if not rpmUtils.arch.arches.has_key(self.target_arch): @@ -438,7 +439,9 @@ class Yum(BackendPlugin, yum.YumBase): installlogfile = "%s/__catched_stderr.buf" % (self.instroot) msger.enable_logstderr(installlogfile) - self.runTransaction(cb) + transactionResult = self.runTransaction(cb) + if transactionResult.return_code != 0 and self.strict_mode: + raise CreatorError("mic failes to install some packages") self._cleanupRpmdbLocks(self.conf.installroot) except rpmUtils.RpmUtilsError, e: diff --git a/plugins/backend/zypppkgmgr.py b/plugins/backend/zypppkgmgr.py index e1c7641..4a41bea 100644 --- a/plugins/backend/zypppkgmgr.py +++ b/plugins/backend/zypppkgmgr.py @@ -54,7 +54,8 @@ from mic.pluginbase import BackendPlugin class Zypp(BackendPlugin): name = 'zypp' - def __init__(self, target_arch, instroot, cachedir): + #strict_mode not used in zypp yet(yum only) + def __init__(self, target_arch, instroot, cachedir, strict_mode = False): self.cachedir = cachedir self.instroot = instroot self.target_arch = target_arch -- 2.34.1