From 531ad2966fe1580880fc4c1192192eb98f1f0b26 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Mar 2012 11:48:41 +0100 Subject: [PATCH] in fork() do sys.exit() so parent knows about failures Signed-off-by: Nico Schottelius --- bin/cdist | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/bin/cdist b/bin/cdist index edd610a5..9c15a8cf 100755 --- a/bin/cdist +++ b/bin/cdist @@ -177,28 +177,25 @@ def configinstall_onehost(host, args, mode, parallel): context.cleanup() except cdist.Error as e: - log.error(e) - return False - except KeyboardInterrupt: - # Do not care in sequential mode, catch in parallel mode - if not parallel: - raise + if parallel: + log.error(e) + sys.exit(1) else: - # Catch here, above does not need to know about our errors - return False + raise - return True + except KeyboardInterrupt: + # Ignore in parallel mode, we are existing anyway + if parallel: + sys.exit(0) + # Pass back to controlling code in sequential mode + else: + raise def emulator(): """Prepare and run emulator""" - try: - import cdist.emulator - emulator = cdist.emulator.Emulator(sys.argv) - emulator.run() - - except cdist.Error as e: - log.error(e) - sys.exit(1) + import cdist.emulator + emulator = cdist.emulator.Emulator(sys.argv) + return emulator.run() if __name__ == "__main__": # Sys is needed for sys.exit() @@ -213,9 +210,8 @@ if __name__ == "__main__": cdistpythonversion = '3.2' if sys.version < cdistpythonversion: - print('Cdist requires Python >= ' + cdistpythonversion + + raise cdist.Error('Cdist requires Python >= ' + cdistpythonversion + ' on the source host.') - sys.exit(1) # Ensure our /lib/ is included into PYTHON_PATH sys.path.insert(0, os.path.abspath( @@ -236,6 +232,10 @@ if __name__ == "__main__": except KeyboardInterrupt: pass + except cdist.Error as e: + log.error(e) + exit_code = 1 + # Determine exit code by return value of function if not run: exit_code = 1