From 5e47cf2c1a2b7a3334c79f73c457c613f313ac3d Mon Sep 17 00:00:00 2001 From: "biao716.wang" Date: Tue, 8 Feb 2022 12:47:40 +0900 Subject: [PATCH] Add postscripts-maxruntime option to set the max run time for post scripts 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: Ib58e5200ac7c75b1708a86b58eec3c682f0d6e2e Signed-off-by: biao716.wang --- mic/cmd_create.py | 4 ++-- mic/conf.py | 1 + mic/imager/baseimager.py | 7 ++----- tools/mic | 1 + 4 files changed, 6 insertions(+), 7 deletions(-) mode change 100755 => 100644 mic/cmd_create.py diff --git a/mic/cmd_create.py b/mic/cmd_create.py old mode 100755 new mode 100644 index ab353a8..ed19072 --- a/mic/cmd_create.py +++ b/mic/cmd_create.py @@ -82,7 +82,6 @@ def main(parser, args, argv): rpm.setVerbosity(rpm.RPMLOG_DEBUG) except ImportError: pass - #check the imager type createrClass = None for subcmd, klass in pluginmgr.get_plugins('imager').iteritems(): @@ -150,7 +149,8 @@ def main(parser, args, argv): if args.skip_set_hosts: configmgr.create['skip_set_hosts']=args.skip_set_hosts - + if args.postscripts_maxruntime: + configmgr.create['postscripts_maxruntime']=int(args.postscripts_maxruntime) if args.runtime: configmgr.set_runtime(args.runtime) diff --git a/mic/conf.py b/mic/conf.py index 031c1af..9269d56 100755 --- a/mic/conf.py +++ b/mic/conf.py @@ -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, diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index f362385..f0243f7 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -38,8 +38,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): """Installs a system to a chroot directory. @@ -1300,7 +1298,6 @@ class BaseImageCreator(object): else: preexec = self._chroot script = "/tmp/" + os.path.basename(path) - start_time = time.time() try: try: @@ -1312,8 +1309,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)) diff --git a/tools/mic b/tools/mic index fc4fb2c..9b55f56 100755 --- a/tools/mic +++ b/tools/mic @@ -143,6 +143,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") -- 2.7.4