begin support for sensible exit codes of cdist
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
53ca7e7aca
commit
d3b9aa6769
1 changed files with 15 additions and 8 deletions
23
bin/cdist
23
bin/cdist
|
@ -91,13 +91,13 @@ def commandline():
|
||||||
logging.root.setLevel(logging.DEBUG)
|
logging.root.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
log.debug(args)
|
log.debug(args)
|
||||||
args.func(args)
|
return args.func(args)
|
||||||
|
|
||||||
def config(args):
|
def config(args):
|
||||||
configinstall(args, mode=cdist.config.Config)
|
return configinstall(args, mode=cdist.config.Config)
|
||||||
|
|
||||||
def install(args):
|
def install(args):
|
||||||
configinstall(args, mode=cdist.install.Install)
|
return configinstall(args, mode=cdist.install.Install)
|
||||||
|
|
||||||
def configinstall(args, mode):
|
def configinstall(args, mode):
|
||||||
"""Configure or install remote system"""
|
"""Configure or install remote system"""
|
||||||
|
@ -140,6 +140,7 @@ def configinstall(args, mode):
|
||||||
if len(failed_hosts) > 0:
|
if len(failed_hosts) > 0:
|
||||||
log.warn("Failed to deploy to the following hosts: " +
|
log.warn("Failed to deploy to the following hosts: " +
|
||||||
" ".join(failed_hosts))
|
" ".join(failed_hosts))
|
||||||
|
exit_code = 1
|
||||||
|
|
||||||
time_end = time.time()
|
time_end = time.time()
|
||||||
log.info("Total processing time for %s host(s): %s", len(args.host),
|
log.info("Total processing time for %s host(s): %s", len(args.host),
|
||||||
|
@ -203,6 +204,8 @@ if __name__ == "__main__":
|
||||||
# Sys is needed for sys.exit()
|
# Sys is needed for sys.exit()
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
exit_code = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -226,11 +229,15 @@ if __name__ == "__main__":
|
||||||
logging.basicConfig(format='%(levelname)s: %(message)s')
|
logging.basicConfig(format='%(levelname)s: %(message)s')
|
||||||
|
|
||||||
if re.match("__", os.path.basename(sys.argv[0])):
|
if re.match("__", os.path.basename(sys.argv[0])):
|
||||||
emulator()
|
run = emulator()
|
||||||
else:
|
else:
|
||||||
commandline()
|
run = commandline()
|
||||||
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
pass
|
||||||
|
|
||||||
|
# Determine exit code by return value of function
|
||||||
|
if not run:
|
||||||
|
exit_code = 1
|
||||||
|
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
Loading…
Reference in a new issue