From db3987f515ca9f9e9d9437f7a7454e050e1ec273 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sat, 7 Aug 2010 20:38:25 +0200 Subject: [PATCH] action: Let each action track a status and log it. This allows (in the future) for a nice summary after each run and allows actions to fail without breaking out with an exception right away. --- src/lib/backupninja/action.py | 10 +++++++++- src/lib/backupninja/handlers/__init__.py | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/backupninja/action.py b/src/lib/backupninja/action.py index 83afc95..7707f3b 100644 --- a/src/lib/backupninja/action.py +++ b/src/lib/backupninja/action.py @@ -68,7 +68,15 @@ def run_action(action_config, opts, global_config): # Run it action.run(test=opts.test) action.finish(test=opts.test) + # Ask the action if there where any failures + success = not action.failed except Exception, e: - log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e) + log.error('Unexpected exception: %s', e) import traceback log.debug(traceback.format_exc()) + success = False + + if success: + log.info('Running action "%s.%s" succeeded', action_name, action_ty) + else: + log.info('Running action "%s.%s" failed', action_name, action_ty) diff --git a/src/lib/backupninja/handlers/__init__.py b/src/lib/backupninja/handlers/__init__.py index f6559f9..dbc403e 100644 --- a/src/lib/backupninja/handlers/__init__.py +++ b/src/lib/backupninja/handlers/__init__.py @@ -38,6 +38,9 @@ class Action(object): # See backupninja.config.load_config for the structure of this # value. self.default_config = {} + # Assume we'll run succesfully. If anything fails in the + # meanwhile, set this to True. + self.failed = False def run(self, **kwargs): """ -- 2.30.2