From d3b9aa6769ca1e8ffad410c2e5d5c3babfa3ed7e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Mar 2012 11:19:26 +0100 Subject: [PATCH] begin support for sensible exit codes of cdist Signed-off-by: Nico Schottelius --- bin/cdist | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bin/cdist b/bin/cdist index 5456b134..edd610a5 100755 --- a/bin/cdist +++ b/bin/cdist @@ -91,13 +91,13 @@ def commandline(): logging.root.setLevel(logging.DEBUG) log.debug(args) - args.func(args) + return args.func(args) def config(args): - configinstall(args, mode=cdist.config.Config) + return configinstall(args, mode=cdist.config.Config) def install(args): - configinstall(args, mode=cdist.install.Install) + return configinstall(args, mode=cdist.install.Install) def configinstall(args, mode): """Configure or install remote system""" @@ -140,6 +140,7 @@ def configinstall(args, mode): if len(failed_hosts) > 0: log.warn("Failed to deploy to the following hosts: " + " ".join(failed_hosts)) + exit_code = 1 time_end = time.time() 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() import sys + exit_code = 0 + try: import logging import os @@ -226,11 +229,15 @@ if __name__ == "__main__": logging.basicConfig(format='%(levelname)s: %(message)s') if re.match("__", os.path.basename(sys.argv[0])): - emulator() + run = emulator() else: - commandline() - - sys.exit(0) + run = commandline() except KeyboardInterrupt: - sys.exit(0) + pass + + # Determine exit code by return value of function + if not run: + exit_code = 1 + + sys.exit(exit_code)