Use cpio gzip in mic. 24/124624/1
authorxiaojuan.mao <xiaojuan.mao@samsung.com>
Fri, 7 Apr 2017 07:08:40 +0000 (15:08 +0800)
committerSoonKyu Park <sk7.park@samsung.com>
Wed, 12 Apr 2017 04:05:10 +0000 (13:05 +0900)
Change-Id: Ifce99807698d3a35fd3dddcdf8f9d60f4c2bb22c

mic/cmd_create.py
mic/conf.py [changed mode: 0644->0755]
mic/imager/baseimager.py
mic/kickstart/__init__.py
plugins/imager/fs_plugin.py [changed mode: 0644->0755]
plugins/imager/loop_plugin.py [changed mode: 0644->0755]
plugins/imager/qcow_plugin.py [changed mode: 0644->0755]
plugins/imager/raw_plugin.py
tools/mic

index 54fdbde..729100b 100755 (executable)
@@ -146,6 +146,8 @@ def main(parser, args, argv):
 \r
     if args.pack_to is not None:\r
         configmgr.create['pack_to'] = args.pack_to\r
+    if args.cpio:\r
+       configmgr.create['cpio'] = args.cpio \r
 \r
     if args.copy_kernel:\r
         configmgr.create['copy_kernel'] = args.copy_kernel\r
old mode 100644 (file)
new mode 100755 (executable)
index d844c65..45ea0c3
@@ -75,6 +75,7 @@ class ConfigMgr(object):
                     "extrarepos": {},
                     "ignore_ksrepo": False,
                     "strict_mode": False,
+                    "cpio":False,
                 },
                 'chroot': {
                     "saveto": None,
index 5982dcc..a1e80fb 100755 (executable)
@@ -87,6 +87,7 @@ class BaseImageCreator(object):
         self.pack_to = None
         self.repourl = {}
         self.multiple_partitions = False
+        self.cpio = False
 
         # If the kernel is save to the destdir when copy_kernel cmd is called.
         self._need_copy_kernel = False
@@ -1250,6 +1251,29 @@ class BaseImageCreator(object):
                         pass
                 self._instloops.remove(item)
 
+    def create_cpio_image(self):
+        if self.cpio:
+            cpiomountdir = self._instroot + '/mnt/initrd'
+            if os.path.exists(cpiomountdir):
+                msger.info("Create image by cpio.")
+                imgfile = os.path.join(self._imgdir, 'ramdisk.img')
+                if imgfile:
+                    os.remove(imgfile)
+                try:
+                    cpiocmd = fs.find_binary_path('cpio')
+                    if cpiocmd:
+                        oldoutdir = os.getcwd()
+                        os.chdir(cpiomountdir)
+                        # find . | cpio --create --'format=newc' | gzip > ../ramdisk.img
+                        runner.show('find . | cpio -o -H newc | gzip > %s' % 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)
+            else:
+                msger.warning("Do not create image by cpio. There is no directory '/mnt/initrd'.")
+
     def package(self, destdir = "."):
         """Prepares the created image for final delivery.
 
index fb0e4d8..8ec653c 100755 (executable)
@@ -203,12 +203,12 @@ class TimezoneConfig(KickstartConfig):
         tz_source = "/usr/share/zoneinfo/%s" % (tz)
         tz_dest = "/etc/localtime"
         try:
-            cpcmd = fs.find_binary_inchroot('ln', self.instroot)
-            if cpcmd:
-                self.call([cpcmd, "-s", tz_source, tz_dest])
+            lncmd = fs.find_binary_inchroot('ln', self.instroot)
+            if lncmd:
+                self.call([lncmd, "-s", tz_source, tz_dest])
             else:
-                cpcmd = fs.find_binary_path('ln')
-                subprocess.call([cpcmd, "-s",
+                lncmd = fs.find_binary_path('ln')
+                subprocess.call([lncmd, "-s",
                                  self.path(tz_source),
                                  self.path(tz_dest)])
         except (IOError, OSError), (errno, msg):
old mode 100644 (file)
new mode 100755 (executable)
index d74530f..b573127
@@ -103,6 +103,8 @@ class FsPlugin(ImagerPlugin):
 
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
+            if creatoropts['cpio']:
+                creator.create_cpio_image()
             creator.unmount()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()
old mode 100644 (file)
new mode 100755 (executable)
index 1830230..50aab52
@@ -102,6 +102,8 @@ class LoopPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
+            if creatoropts['cpio']:
+                creator.create_cpio_image()
             creator.unmount()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()
old mode 100644 (file)
new mode 100755 (executable)
index 8acf572..cfbbd66
@@ -133,6 +133,8 @@ class QcowPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
+            if creatoropts['cpio']:
+                creator.create_cpio_image()
             creator.unmount()
             creator.package(creatoropts["destdir"])
             creator.create_manifest()
index 09a9714..0df535c 100755 (executable)
@@ -100,6 +100,8 @@ class RawPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
+            if creatoropts['cpio']:
+                creator.create_cpio_image()
             creator.unmount()
             creator.generate_bmap()
             creator.package(creatoropts["destdir"])
index 26df153..44df61e 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -54,7 +54,7 @@ def chroot_parser(parser):
                         help = "command which will be executed in chroot environment")
     parser.set_defaults(alias="ch")
     return parser
-    
+
 @subparser
 def create_parser(parser):
     """create an image
@@ -64,15 +64,18 @@ def create_parser(parser):
     """
 
     parent_parser = ArgumentParser(add_help=False)
-    parent_parser.add_argument('ksfile', help='Path of ksfile');
+    parent_parser.add_argument('--cpio', action='store_true',
+                                dest='cpio', default=False,
+                               help='Use cpio to generate image')
+    parent_parser.add_argument('ksfile', help='Path of ksfile')
     parent_parser.add_argument('--logfile', dest='logfile', default=None,
                                help='Path of logfile')
     parent_parser.add_argument('-c', '--config', dest='config', default=None,
-                               help='Specify config file for mic')                
+                               help='Specify config file for mic')
     parent_parser.add_argument('-k', '--cachedir', action='store',
                                dest='cachedir', default=None,
                                help='Cache directory to store the downloaded')
-    parent_parser.add_argument('-o', '--outdir', action='store', dest='outdir', 
+    parent_parser.add_argument('-o', '--outdir', action='store', dest='outdir',
                                default=None, help='Output directory')
     parent_parser.add_argument('-A', '--arch', dest='arch', default=None,
                                help='Specify repo architecture')