diff options
-rwxr-xr-x | mic/imager/baseimager.py | 33 | ||||
-rwxr-xr-x | plugins/imager/loop_plugin.py | 4 | ||||
-rwxr-xr-x | plugins/imager/qcow_plugin.py | 4 |
3 files changed, 20 insertions, 21 deletions
diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index a5c53b4..616225f 100755 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1261,33 +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. diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 70dafc0..755d8d5 100755 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -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() diff --git a/plugins/imager/qcow_plugin.py b/plugins/imager/qcow_plugin.py index 33ed358..09bc790 100755 --- a/plugins/imager/qcow_plugin.py +++ b/plugins/imager/qcow_plugin.py @@ -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() |