Add postscripts-maxruntime option to set the max run time for post scripts
authorbiao716.wang <biao716.wang@samsung.com>
Tue, 16 Aug 2022 08:24:07 +0000 (17:24 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Tue, 16 Aug 2022 08:24:10 +0000 (17:24 +0900)
example: sudo mic create auto test.ks --postscripts-maxruntime=500
mean the max run time for post scripts is 500 minutes.
without this option, default max run time is 120 minutes.
Change-Id: I4fb90477307e75901b17e7ae92777e984fdd8743
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
mic/cmd_create.py
mic/conf.py
mic/imager/baseimager.py
tools/mic

index ce18ed5..3d84fca 100755 (executable)
@@ -151,7 +151,10 @@ def main(parser, args, argv):
     if args.skip_set_hosts:
         configmgr.create['skip_set_hosts']=args.skip_set_hosts
 
-    if args.runtime:
+    if args.postscripts_maxruntime:
+        configmgr.create['postscripts_maxruntime']=int(args.postscripts_maxruntime)
+
+if args.runtime:
         configmgr.set_runtime(args.runtime)
 
     if args.use_mic_in_bootstrap:
index d68d086..23653dd 100755 (executable)
@@ -80,6 +80,7 @@ class ConfigMgr(object):
                     "tpk_install": None,
                     "use_mic_in_bootstrap": False,
                     "skip_set_hosts": False,
+                    "postscripts_maxruntime": 120,
                 },
                 'chroot': {
                     "saveto": None,
index 43ac5f9..7a93c13 100644 (file)
@@ -39,8 +39,6 @@ from mic.chroot import kill_proc_inchroot
 from mic.archive import get_archive_suffixes
 from mic.conf import configmgr
 from mic.utils.grabber import myurlgrab
-# post script max run time
-MAX_RUN_TIME = 120
 
 
 class BaseImageCreator(object):
@@ -1314,9 +1312,8 @@ class BaseImageCreator(object):
                     while p.poll() == None:
                         msger.info(p.stdout.readline().strip())
                         end_time = time.time()
-                        if (end_time - start_time)/60 > MAX_RUN_TIME:
-                            raise CreatorError(
-                                "Your post script is executed more than "+MAX_RUN_TIME+"mins, please check it!")
+                        if (end_time - start_time)/60 > configmgr.create['postscripts_maxruntime']:
+                            raise CreatorError("Your post script is executed more than %d mins, please check it!" % configmgr.create['postscripts_maxruntime'])
                     if p.returncode != 0:
                         raise CreatorError("Failed to execute %%post script "
                                            "with '%s'" % (s.interp))
index 968118d..98b72cf 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -142,6 +142,7 @@ def create_parser(parser):
                                                                        default=None, help='Copy tpk file to /usr/apps/.preload-tpk')
     parent_parser.add_argument('--rpm-debug', action='store_true', dest='rpm_debug', help='Set debug mode for rpm install')
     parent_parser.add_argument('--skip-set-hosts', action='store_true', dest='skip_set_hosts', default=False, help='choose to skip set hosts by mic')
+    parent_parser.add_argument('--postscripts-maxruntime', dest='postscripts_maxruntime', default=120, help='max run time for post scripts')
 
     parser.set_defaults(alias="cr")