diff options
author | xiaojuan.mao <xiaojuan.mao@samsung.com> | 2017-04-07 15:08:40 +0800 |
---|---|---|
committer | xiaojuan.mao <xiaojuan.mao@samsung.com> | 2017-07-13 11:17:43 +0800 |
commit | 58861e311fe45272929b7db7939e76dba789a707 (patch) | |
tree | c75a24d8be2215c85b9623b7da95cd585bded638 | |
parent | b4e557cdfbef38dbc23d3a37265e8eec060596ac (diff) | |
download | mic-58861e311fe45272929b7db7939e76dba789a707.tar.gz mic-58861e311fe45272929b7db7939e76dba789a707.tar.bz2 mic-58861e311fe45272929b7db7939e76dba789a707.zip |
Use cpio gzip in mic.
Change-Id: Ifce99807698d3a35fd3dddcdf8f9d60f4c2bb22c
-rwxr-xr-x | mic/cmd_create.py | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | mic/conf.py | 1 | ||||
-rwxr-xr-x | mic/imager/baseimager.py | 24 | ||||
-rwxr-xr-x | mic/kickstart/__init__.py | 10 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/imager/fs_plugin.py | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/imager/loop_plugin.py | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/imager/qcow_plugin.py | 2 | ||||
-rwxr-xr-x | plugins/imager/raw_plugin.py | 2 | ||||
-rwxr-xr-x | tools/mic | 11 |
9 files changed, 47 insertions, 9 deletions
diff --git a/mic/cmd_create.py b/mic/cmd_create.py index 54fdbde..729100b 100755 --- a/mic/cmd_create.py +++ b/mic/cmd_create.py @@ -146,6 +146,8 @@ def main(parser, args, argv): if args.pack_to is not None:
configmgr.create['pack_to'] = args.pack_to
+ if args.cpio:
+ configmgr.create['cpio'] = args.cpio
if args.copy_kernel:
configmgr.create['copy_kernel'] = args.copy_kernel
diff --git a/mic/conf.py b/mic/conf.py index d844c65..45ea0c3 100644..100755 --- a/mic/conf.py +++ b/mic/conf.py @@ -75,6 +75,7 @@ class ConfigMgr(object): "extrarepos": {}, "ignore_ksrepo": False, "strict_mode": False, + "cpio":False, }, 'chroot': { "saveto": None, diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 5982dcc..a1e80fb 100755 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -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. diff --git a/mic/kickstart/__init__.py b/mic/kickstart/__init__.py index fb0e4d8..8ec653c 100755 --- a/mic/kickstart/__init__.py +++ b/mic/kickstart/__init__.py @@ -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): diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index d74530f..b573127 100644..100755 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -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() diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 1830230..50aab52 100644..100755 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -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() diff --git a/plugins/imager/qcow_plugin.py b/plugins/imager/qcow_plugin.py index 8acf572..cfbbd66 100644..100755 --- a/plugins/imager/qcow_plugin.py +++ b/plugins/imager/qcow_plugin.py @@ -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() diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 09a9714..0df535c 100755 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -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"]) @@ -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') |