From 10d1e96446cde5cc019a231d7c3f03198bb3857f Mon Sep 17 00:00:00 2001 From: "xiaojuan.mao" Date: Mon, 12 Jun 2017 20:18:06 +0800 Subject: [PATCH] Change the order of generating image by cpio. Change-Id: Ia1d2cc22b9a6e695a6f905574f8081c5910f0e8b --- mic/imager/baseimager.py | 18 +++++++++++++++--- plugins/imager/loop_plugin.py | 3 ++- plugins/imager/qcow_plugin.py | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 26104c8..7fb5c42 100755 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -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,16 +1268,28 @@ 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. diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 6005f46..70dafc0 100755 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -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() diff --git a/plugins/imager/qcow_plugin.py b/plugins/imager/qcow_plugin.py index 76339a5..33ed358 100755 --- a/plugins/imager/qcow_plugin.py +++ b/plugins/imager/qcow_plugin.py @@ -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() -- 2.7.4