Fix the mic can't create image into specified folder which defined in default mic... 46/306846/3
authorwanchao-xu <wanchao.xu@samsung.com>
Wed, 28 Feb 2024 07:50:02 +0000 (15:50 +0800)
committerwanchao-xu <wanchao.xu@samsung.com>
Mon, 4 Mar 2024 08:28:12 +0000 (16:28 +0800)
Change-Id: I8d21b047ea864227662bb208e820b3343943dc75
Signed-off-by: wanchao-xu <wanchao.xu@samsung.com>
mic/rt_util.py

index 5e4f630..5867d93 100644 (file)
@@ -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)