| 1 |
Symptom: |
| 2 |
running something in a manifest and that fails does not exist |
| 3 |
the cdist run |
| 4 |
|
| 5 |
Analysis: |
| 6 |
Find out what the shell does: |
| 7 |
|
| 8 |
[23:56] bento:testshell% cat a.sh |
| 9 |
# source something that fails |
| 10 |
. b.sh |
| 11 |
[23:57] bento:testshell% cat b.sh |
| 12 |
nosuchcommand |
| 13 |
[23:57] bento:testshell% sh -e a.sh |
| 14 |
a.sh: 2: .: b.sh: not found |
| 15 |
[23:57] bento:testshell% echo $? |
| 16 |
2 |
| 17 |
|
| 18 |
-> exit 2 -> looks good |
| 19 |
|
| 20 |
|
| 21 |
Find out what the python does: |
| 22 |
|
| 23 |
[23:57] bento:testshell% python3 |
| 24 |
Python 3.3.2 (default, May 21 2013, 15:40:45) |
| 25 |
[GCC 4.8.0 20130502 (prerelease)] on linux |
| 26 |
Type "help", "copyright", "credits" or "license" for more information. |
| 27 |
>>> import subprocess |
| 28 |
>>> subprocess.check_call(["/bin/sh", "-e", "a.sh"]) |
| 29 |
a.sh: 2: .: b.sh: not found |
| 30 |
Traceback (most recent call last): |
| 31 |
File "<stdin>", line 1, in <module> |
| 32 |
File "/usr/lib/python3.3/subprocess.py", line 544, in check_call |
| 33 |
raise CalledProcessError(retcode, cmd) |
| 34 |
subprocess.CalledProcessError: Command '['/bin/sh', '-e', 'a.sh']' returned non-zero exit status 2 |
| 35 |
>>> |
| 36 |
|
| 37 |
|
| 38 |
Conclusion: |
| 39 |
Manifests that execute (!) other shell scripts does |
| 40 |
not necessarily give the -e flag to the other script |
| 41 |
-> called script can have failures, but exit 0 |
| 42 |
if something the last thing executed does exit 0! |
| 43 |
|
| 44 |
Solution: |
| 45 |
Instead of doing stuff like |
| 46 |
"$__manifest/special" |
| 47 |
|
| 48 |
use |
| 49 |
sh -e "$__manifest/special" |
| 50 |
|
| 51 |
or source the script: |
| 52 |
. "$__manifest/special" |
| 53 |
|
| 54 |
(runs the script in the same namespace/process as everything in the |
| 55 |
calling script) |
| 56 |
|