summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxiaojuan.mao <xiaojuan.mao@samsung.com>2017-07-07 13:52:29 +0800
committerxiaojuan.mao <xiaojuan.mao@samsung.com>2017-07-13 13:46:18 +0800
commita9ea35b7087e1face424a72e939945f6a34756d1 (patch)
treee7b710c060b6ce866496f19eee4c0ce3b4a77b06
parent6013c22469a16fa8655fc35db4f4aa11f1989253 (diff)
downloadmic-a9ea35b7087e1face424a72e939945f6a34756d1.tar.gz
mic-a9ea35b7087e1face424a72e939945f6a34756d1.tar.bz2
mic-a9ea35b7087e1face424a72e939945f6a34756d1.zip
Modify the order of generating image by cpio.
Change-Id: I90cb12a4d68f6989af25318b6181a2ed9e9ebe88
-rwxr-xr-xmic/imager/baseimager.py33
-rwxr-xr-xplugins/imager/loop_plugin.py4
-rwxr-xr-xplugins/imager/qcow_plugin.py4
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()