Modify the order of generating image by cpio. 89/151489/1
authorxiaojuan.mao <xiaojuan.mao@samsung.com>
Thu, 21 Sep 2017 05:47:26 +0000 (13:47 +0800)
committerxiaojuan.mao <xiaojuan.mao@samsung.com>
Thu, 21 Sep 2017 05:47:26 +0000 (13:47 +0800)
Change-Id: If2ce4df88b067cb4883d66b7d3f869aadb314ae3

mic/imager/baseimager.py
plugins/imager/loop_plugin.py
plugins/imager/qcow_plugin.py

index 7fb5c42945be888291897e9433aa736b795a1511..616225fbf416451db9634f169913b53fda9946df 100755 (executable)
@@ -1261,34 +1261,32 @@ class BaseImageCreator(object):
         for item in self._instloops:
             if item['cpioopts']:
                 msger.info("Create image by cpio.")
-                imgfile = os.path.join(self._imgdir, item['name'])
-                if imgfile:
-                    os.remove(imgfile)
+                tmp_cpio = self.__builddir + "/tmp_cpio"
+                if not os.path.exists(tmp_cpio):
+                    os.mkdir(tmp_cpio)
+                tmp_cpio_imgfile = os.path.join(tmp_cpio, item['name'])
                 try:
                     cpiocmd = fs.find_binary_path('cpio')
                     if cpiocmd:
                         oldoutdir = os.getcwd()
-                        cpiomountdir = os.path.join(self._imgdir, item['mountpoint'].lstrip('/'))
-                        os.chdir(cpiomountdir)
+                        os.chdir(tmp_cpio)
                         # find . | cpio --create --'format=newc' | gzip > ../ramdisk.img
-                        runner.show('find . | cpio --create %s | gzip > %s' % (item['cpioopts'], imgfile))
-                        shutil.rmtree(cpiomountdir, ignore_errors=True)
+                        runner.show('find . | cpio --create %s | gzip > %s' % (item['cpioopts'], tmp_cpio_imgfile))
                         os.chdir(oldoutdir)
                 except OSError, (errno, msg):
-                    raise errors.KsError("Create image by cpio error: %s" % msg)
-
-    def copy_cpio_resource(self):
+                    raise errors.CreatorError("Create image by cpio error: %s" % msg)
+    def copy_cpio_image(self):
         for item in self._instloops:
             if item['cpioopts']:
-                msger.info("Copy resouces to be used for creating image by cpio.")
+                tmp_cpio = self.__builddir + "/tmp_cpio"
+                msger.info("Copy cpio image from %s to %s." %(tmp_cpio, self._imgdir)) 
                 try:
-                    cpcmd = fs.find_binary_path('cp')
-                    if cpcmd:
-                        cpiomountdir = os.path.join(self._instroot, item['mountpoint'].lstrip('/'))
-                        runner.show('cp -r %s %s' % (cpiomountdir, self._imgdir))
-                        shutil.rmtree(cpiomountdir, ignore_errors=True)
-                except OSError, (errno, msg):
-                    raise errors.KsError("Copy resouces error: %s" % msg)
+                    shutil.copyfile(os.path.join(tmp_cpio, item['name']),os.path.join(self._imgdir, item['name']))  
+                except IOError:
+                    raise errors.CreatorError("Copy cpio image error")
+                os.remove(os.path.join(tmp_cpio, item['name']))
+                if not os.listdir(tmp_cpio):
+                    shutil.rmtree(tmp_cpio, ignore_errors=True)
 
     def package(self, destdir = "."):
         """Prepares the created image for final delivery.
index 70dafc0560ad9f63cf0400a1b56bb65bf1d9e9c7..755d8d5cb0600a6841c0c4aa292737c3c7b57ba1 100755 (executable)
@@ -102,9 +102,9 @@ class LoopPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
-            creator.copy_cpio_resource()
-            creator.unmount()
             creator.create_cpio_image()
+            creator.unmount()
+            creator.copy_cpio_image()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()
 
index 33ed358fb30d640ecabb7688499dbd70add9d50e..09bc7904a7f67b58bb9fce64da841e3e5dc53d78 100755 (executable)
@@ -133,9 +133,9 @@ class QcowPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
-            creator.copy_cpio_resource()
-            creator.unmount()
             creator.create_cpio_image()
+            creator.unmount()
+            creator.copy_cpio_image()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()