From a57d358b9aace407787a2aaaa0497ab91889865b Mon Sep 17 00:00:00 2001 From: wanchao-xu Date: Wed, 28 Feb 2024 15:50:02 +0800 Subject: [PATCH] Fix the mic can't create image into specified folder which defined in default mic config. Change-Id: I8d21b047ea864227662bb208e820b3343943dc75 Signed-off-by: wanchao-xu --- mic/rt_util.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/mic/rt_util.py b/mic/rt_util.py index 5e4f630..5867d93 100644 --- a/mic/rt_util.py +++ b/mic/rt_util.py @@ -116,12 +116,16 @@ def bootstrap_mic(argv=None): rootdir = os.path.join(rootdir, "bootstrap") bsenv.dirsetup(rootdir) - #when mic in mic-bootstrap is py2, use mic version in mic-bootstrap. - if cropts['use_mic_in_bootstrap'] | (mic_py2_in_mic_bootstrap(os.path.join(rootdir, '/usr/bin/mic'.lstrip('/'))) == True): + if cropts['use_mic_in_bootstrap']: msger.info("No copy host mic") else: - msger.info("Copy host mic to bootstrap") - sync_mic(rootdir, plugin=cropts['plugin_dir']) + #when mic in mic-bootstrap is py2, use mic version in mic-bootstrap. + if (mic_py2_in_mic_bootstrap(os.path.join(rootdir, '/usr/bin/mic'.lstrip('/'))) == True): + msger.info("Copy host mic conf to bootstrap") + sync_mic_conf(rootdir) + else: + msger.info("Copy host mic to bootstrap") + sync_mic(rootdir, plugin=cropts['plugin_dir']) #FIXME: sync the ks file to bootstrap if "/" == os.path.dirname(os.path.abspath(configmgr._ksconf)): @@ -206,6 +210,21 @@ def get_mic_modpath(): def get_mic_libpath(): return os.getenv("MIC_LIBRARY_PATH", "/usr/lib/mic") +def sync_mic_conf(bootstrap, conf = '/etc/mic/mic.conf'): + _path = lambda p: os.path.join(bootstrap, p.lstrip('/')) + + try: + safecopy(conf, _path(conf), False) + except (OSError, IOError) as err: + raise errors.BootstrapError(err) + + # auto select backend + with open(_path(conf), 'r') as rf: + conf_str = rf.read() + conf_str = re.sub("pkgmgr\s*=\s*.*", "pkgmgr=auto", conf_str) + with open(_path(conf), 'w') as wf: + wf.write(conf_str) + # the hard code path is prepared for bootstrap def sync_mic(bootstrap, binpth = '/usr/bin/mic', libpth='/usr/lib', @@ -238,7 +257,8 @@ def sync_mic(bootstrap, binpth = '/usr/bin/mic', raise errors.BootstrapError(err) # auto select backend - conf_str = open(_path(conf)).read() + with open(_path(conf), 'r') as rf: + conf_str = rf.read() conf_str = re.sub("pkgmgr\s*=\s*.*", "pkgmgr=auto", conf_str) with open(_path(conf), 'w') as wf: wf.write(conf_str) -- 2.7.4