summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDohyung Kim <dohyung2.kim@samsung.com>2017-11-21 14:55:28 +0900
committeryuhuan.yang <yuhuan.yang@samsung.com>2018-01-30 13:19:05 +0800
commita525045ae230064e5461cd3395e2e8d6c531bf9b (patch)
tree01fe0ebfd7454bc8780d11196da812f3ebe2a48b
parent3394e94e03ce666cfc770f7256583045c0f2774e (diff)
downloadmic-a525045ae230064e5461cd3395e2e8d6c531bf9b.tar.gz
mic-a525045ae230064e5461cd3395e2e8d6c531bf9b.tar.bz2
mic-a525045ae230064e5461cd3395e2e8d6c531bf9b.zip
support both %runscript and %post-umount to perform scripts before packaging
- add %post-umount section which behaves the same as %runscript (if both %runscript and %post-umount are defined then KickstartError occurs) - move post umount scripts from /var/tmp/post_umount_scripts/ on image to host - post umount scripts can be use UMOUNT_SCRIPTS_PATH env variable (UMOUNT_SCRIPTS_PATH: directory path where post umount scripts are located on host) Change-Id: Ib88c103f0d3e84c067d0d6683f406a5cac92739a Signed-off-by: Dohyung Kim <dohyung2.kim@samsung.com>
-rw-r--r--mic/3rdparty/pykickstart/constants.py1
-rw-r--r--mic/3rdparty/pykickstart/parser.py3
-rw-r--r--mic/3rdparty/pykickstart/sections.py26
-rwxr-xr-xmic/imager/loop.py27
-rwxr-xr-xmic/kickstart/__init__.py7
5 files changed, 61 insertions, 3 deletions
diff --git a/mic/3rdparty/pykickstart/constants.py b/mic/3rdparty/pykickstart/constants.py
index 92f8325..050d124 100644
--- a/mic/3rdparty/pykickstart/constants.py
+++ b/mic/3rdparty/pykickstart/constants.py
@@ -40,6 +40,7 @@ KS_SCRIPT_PRE = 0
KS_SCRIPT_POST = 1
KS_SCRIPT_TRACEBACK = 2
KS_SCRIPT_RUN = 3
+KS_SCRIPT_UMOUNT = 4
KS_WAIT = 0
KS_REBOOT = 1
diff --git a/mic/3rdparty/pykickstart/parser.py b/mic/3rdparty/pykickstart/parser.py
index f09f925..46495f6 100644
--- a/mic/3rdparty/pykickstart/parser.py
+++ b/mic/3rdparty/pykickstart/parser.py
@@ -203,6 +203,8 @@ class Script(KickstartObject):
retval += '\n%traceback'
elif self.type == constants.KS_SCRIPT_RUN:
retval += '\n%runscript'
+ elif self.type == constants.KS_SCRIPT_UMOUNT:
+ retval += '\n%post-umount'
if self.interp != "/bin/sh" and self.interp != "":
retval += " --interpreter=%s" % self.interp
@@ -720,6 +722,7 @@ class KickstartParser:
self.registerSection(PostScriptSection(self.handler, dataObj=Script))
self.registerSection(TracebackScriptSection(self.handler, dataObj=Script))
self.registerSection(RunScriptSection(self.handler, dataObj=Script))
+ self.registerSection(PostUmountScriptSection(self.handler, dataObj=Script))
self.registerSection(PackageSection(self.handler))
self.registerSection(TpkPackageSection(self.handler))
diff --git a/mic/3rdparty/pykickstart/sections.py b/mic/3rdparty/pykickstart/sections.py
index 223c440..c360a90 100644
--- a/mic/3rdparty/pykickstart/sections.py
+++ b/mic/3rdparty/pykickstart/sections.py
@@ -30,6 +30,7 @@ is necessary is to create a new subclass of Section and call
parser.registerSection with an instance of your new class.
"""
from constants import *
+from errors import *
from options import KSOptionParser
from version import *
@@ -196,9 +197,34 @@ class TracebackScriptSection(ScriptSection):
class RunScriptSection(ScriptSection):
sectionOpen = "%runscript"
+
def _resetScript(self):
ScriptSection._resetScript(self)
self._script["type"] = KS_SCRIPT_RUN
+
+ def finalize(self):
+ ScriptSection.finalize(self)
+ if self.handler:
+ for s in self.handler.scripts:
+ if s.type == KS_SCRIPT_UMOUNT:
+ raise KickstartError("%runscript and %post-umount " \
+ "can not be defined together")
+
+class PostUmountScriptSection(ScriptSection):
+ sectionOpen = "%post-umount"
+
+ def _resetScript(self):
+ ScriptSection._resetScript(self)
+ self._script["type"] = KS_SCRIPT_UMOUNT
+
+ def finalize(self):
+ ScriptSection.finalize(self)
+ if self.handler:
+ for s in self.handler.scripts:
+ if s.type == KS_SCRIPT_RUN:
+ raise KickstartError("%runscript and %post-umount " \
+ "can not be defined together")
+
class PackageSection(Section):
sectionOpen = "%packages"
diff --git a/mic/imager/loop.py b/mic/imager/loop.py
index fd4830c..e9815c9 100755
--- a/mic/imager/loop.py
+++ b/mic/imager/loop.py
@@ -180,6 +180,7 @@ class LoopImageCreator(BaseImageCreator):
self._instloops = []
self._imgdir = None
+ self._umountdir = None
if self.ks:
self.__image_size = kickstart.get_image_size(self.ks,
@@ -404,6 +405,15 @@ class LoopImageCreator(BaseImageCreator):
except:
pass
+ def _get_sign_scripts_env(self):
+ env = BaseImageCreator._get_sign_scripts_env(self)
+
+ # Directory path of %post-umounts scripts
+ if self._umountdir:
+ env['UMOUNT_SCRIPTS_PATH'] = str(self._umountdir)
+
+ return env
+
def _stage_final_image(self):
if self.pack_to or self.shrink_image:
@@ -505,6 +515,23 @@ class LoopImageCreator(BaseImageCreator):
msger.verbose("Move attachment %s to %s" % (item, dpath))
shutil.move(item, dpath)
+ def move_post_umount_scripts(self):
+ scripts_dir = self._instroot + "/var/tmp/post_umount_scripts"
+ if not os.path.exists(scripts_dir):
+ return
+ self._umountdir = self._mkdtemp("umount")
+ msger.info("Moving post umount scripts...")
+ for item in os.listdir(scripts_dir):
+ spath = os.path.join(scripts_dir, item)
+ dpath = os.path.join(self._umountdir, item)
+ msger.verbose("Move post umount scripts %s to %s" % (spath, dpath))
+ shutil.move(spath, dpath)
+ shutil.rmtree(scripts_dir)
+
+ def postinstall(self):
+ BaseImageCreator.postinstall(self)
+ self.move_post_umount_scripts()
+
def create_manifest(self):
if self.compress_image:
self.image_files.update({'compress': self.compress_image})
diff --git a/mic/kickstart/__init__.py b/mic/kickstart/__init__.py
index 75678ad..2eaa425 100755
--- a/mic/kickstart/__init__.py
+++ b/mic/kickstart/__init__.py
@@ -851,10 +851,11 @@ def get_post_scripts(ks):
def get_sign_scripts(ks):
scripts = []
for s in ks.handler.scripts:
- if s.type != ksparser.KS_SCRIPT_RUN:
- continue
- scripts.append(s)
+ if (s.type == ksparser.KS_SCRIPT_RUN or \
+ s.type == ksparser.KS_SCRIPT_UMOUNT):
+ scripts.append(s)
return scripts
+
def add_repo(ks, repostr):
args = repostr.split()
repoobj = ks.handler.repo.parse(args[1:])