diff options
author | Dohyung Kim <dohyung2.kim@samsung.com> | 2017-11-21 15:45:37 +0900 |
---|---|---|
committer | yuhuan.yang <yuhuan.yang@samsung.com> | 2018-01-30 10:40:16 +0800 |
commit | 925cece6ba20bcf90724b53815953725b6cae2a2 (patch) | |
tree | 44fa539914c058d602ec31c5741ef2dde7380120 | |
parent | b6dcc8b96ee150bc7afce70aa619a01c59c029fd (diff) | |
download | mic-925cece6ba20bcf90724b53815953725b6cae2a2.tar.gz mic-925cece6ba20bcf90724b53815953725b6cae2a2.tar.bz2 mic-925cece6ba20bcf90724b53815953725b6cae2a2.zip |
if post scripts fails, CreatorError is raised to catch script errors such as signing error
$ cat PLATFORM.ks
...
%post
# if you want to catch script error, add set command and trap command at the top of script
set -e
trap 'echo KS POST ERROR: command \"$BASH_COMMAND\" failed with error code $?' ERR
# it will cause an error
/usr/bin/error_command
%end
...
$ sudo mic cr auto PLATFORM.ks
...
INFO: Running post scripts ...
INFO: /tmp/ks-postscript-FShzJp: line 5: /usr/bin/error_command: No such file or directory
INFO: KS POST ERROR: command "/usr/bin/error_command" failed with error code 1
INFO:
ERROR: Failed to execute %post script with '/bin/sh'
Change-Id: I1a34a343b8bdd044ca85939e446c43cce783c900
Signed-off-by: Dohyung Kim <dohyung2.kim@samsung.com>
-rwxr-xr-x | mic/imager/baseimager.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 257af8e..d9bc2cf 100755 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1210,6 +1210,9 @@ class BaseImageCreator(object): dir = self._instroot + "/tmp") s.script = s.script.replace("\r", "") os.write(fd, s.script) + if s.interp == '/bin/sh' or s.interp == '/bin/bash': + os.write(fd, '\n') + os.write(fd, 'exit 0\n') os.close(fd) os.chmod(path, 0700) for item in os.listdir(self._imgdir): @@ -1226,6 +1229,9 @@ class BaseImageCreator(object): stderr = subprocess.STDOUT) while p.poll() == None: msger.info(p.stdout.readline().strip()) + if p.returncode != 0: + raise CreatorError("Failed to execute %%sign script " + "with '%s'" % (s.interp)) except OSError, (err, msg): raise CreatorError("Failed to execute %%sign script " "with '%s' : %s" % (s.interp, msg)) @@ -1246,6 +1252,9 @@ class BaseImageCreator(object): s.script = s.script.replace("\r", "") os.write(fd, s.script) + if s.interp == '/bin/sh' or s.interp == '/bin/bash': + os.write(fd, '\n') + os.write(fd, 'exit 0\n') os.close(fd) os.chmod(path, 0700) @@ -1273,6 +1282,9 @@ class BaseImageCreator(object): end_time = time.time() if (end_time - start_time)/60 > MAX_RUN_TIME: raise CreatorError("Your post script is executed more than "+MAX_RUN_TIME+"mins, please check it!") + if p.returncode != 0: + raise CreatorError("Failed to execute %%post script " + "with '%s'" % (s.interp)) except OSError, (err, msg): raise CreatorError("Failed to execute %%post script " "with '%s' : %s" % (s.interp, msg)) |