add strict_mode(MHA-1115)
authorAndrii Boichuk <andrii.boichuk@globallogic.com>
Wed, 23 Jul 2014 13:35:36 +0000 (16:35 +0300)
committeradmin <yuhuan.yang@samsung.com>
Thu, 4 Feb 2016 10:20:20 +0000 (18:20 +0800)
mic/conf.py
mic/creator.py
mic/imager/baseimager.py
plugins/backend/yumpkgmgr.py
plugins/backend/zypppkgmgr.py

index 9816245..139660a 100644 (file)
@@ -74,6 +74,7 @@ class ConfigMgr(object):
                     "runtime": "bootstrap",
                     "extrarepos": {},
                     "ignore_ksrepo": False,
+                    "strict_mode": False,
                 },
                 'chroot': {
                     "saveto": None,
index dde1013..be4773b 100644 (file)
@@ -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:
index 10af5f9..63ac3b9 100644 (file)
@@ -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():
index 05f4dba..8603da3 100644 (file)
@@ -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:
index e1c7641..4a41bea 100644 (file)
@@ -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