Change the order of generating image by cpio.
authorxiaojuan.mao <xiaojuan.mao@samsung.com>
Mon, 12 Jun 2017 12:18:06 +0000 (20:18 +0800)
committerxiaojuan.mao <xiaojuan.mao@samsung.com>
Thu, 13 Jul 2017 03:24:02 +0000 (11:24 +0800)
Change-Id: Ia1d2cc22b9a6e695a6f905574f8081c5910f0e8b

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

index 26104c8..a5c53b4 100755 (executable)
@@ -706,7 +706,7 @@ class BaseImageCreator(object):
         return self.cachedir
 
     def __sanity_check(self):
-        """Ensure that the config we've been given is sane."""
+        """Ensure that the config we've been given is same."""
         if not (kickstart.get_packages(self.ks) or
                 kickstart.get_groups(self.ks)):
             raise CreatorError("No packages or groups specified")
@@ -1268,15 +1268,26 @@ class BaseImageCreator(object):
                     cpiocmd = fs.find_binary_path('cpio')
                     if cpiocmd:
                         oldoutdir = os.getcwd()
-                        cpiomountdir = os.path.join(self._instroot, item['mountpoint'].lstrip('/'))
+                        cpiomountdir = os.path.join(self._imgdir, item['mountpoint'].lstrip('/'))
                         os.chdir(cpiomountdir)
                         # 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)
-                        fs.makedirs(cpiomountdir)
                         os.chdir(oldoutdir)
                 except OSError, (errno, msg):
                     raise errors.KsError("Create image by cpio error: %s" % msg)
+    def copy_cpio_resource(self):
+        for item in self._instloops:
+            if item['cpioopts']:
+                msger.info("Copy resouces to be used for creating image by cpio.")
+                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)
 
     def package(self, destdir = "."):
         """Prepares the created image for final delivery.
index 6005f46..70dafc0 100755 (executable)
@@ -102,8 +102,9 @@ class LoopPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
-            creator.create_cpio_image()
+            creator.copy_cpio_resource()
             creator.unmount()
+            creator.create_cpio_image()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()
 
index 76339a5..33ed358 100755 (executable)
@@ -133,8 +133,9 @@ class QcowPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
-            creator.create_cpio_image()
+            creator.copy_cpio_resource()
             creator.unmount()
+            creator.create_cpio_image()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()