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 9816245b6c2e78e2f42515fde40dfe41e2fb6012..139660a2200d2613f77da8705073c53aa9171653 100644 (file)
@@ -74,6 +74,7 @@ class ConfigMgr(object):
                     "runtime": "bootstrap",
                     "extrarepos": {},
                     "ignore_ksrepo": False,
+                    "strict_mode": False,
                 },
                 'chroot': {
                     "saveto": None,
index dde1013e3cbd0773ba9d5294a1c77184f23ffc8a..be4773bd5cf9e20fded46a7559ec39b515fffa45 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 10af5f963db9190fba9d2d06415d670aa969fbb6..63ac3b9afd3dc97757526ff78099ad637e5fc715 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 05f4dbaa358fabaaafaed9eb3f00934073b49d40..8603da3bd542bb5bc99756387a91c14f8a0ae9df 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 e1c7641fcaf6616371b62d2e89f7612414abed46..4a41beadad82f3c027e65f635a5f671c96cee8cf 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