From 64d3619302bb86a09d171b0e5dfb0efcf87c689b Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 27 Mar 2014 17:25:34 -0700 Subject: [PATCH] Add error handler to os-refresh-config Previously on error the program simply exitted. This will allow script writers to write error handlers to be called whenever any phase fails. Change-Id: I3f8025663700192e9d8132a0e9122b4e0085ebbd --- README.rst | 9 +++++---- os_refresh_config/os_refresh_config.py | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 3f29a41..0967b63 100644 --- a/README.rst +++ b/README.rst @@ -9,6 +9,7 @@ pre-defined set of directories:: /opt/stack/os-config-refresh/configure.d /opt/stack/os-config-refresh/post-configure.d /opt/stack/os-config-refresh/migration.d + /opt/stack/os-config-refresh/error.d `/opt/stack/os-config-refresh` is the default base directory. You can set `OS_REFRESH_CONFIG_BASE_DIR` environment variable to override the @@ -21,10 +22,10 @@ Its intended purpose is to separate scripts execution into 4 phases: 3. Activate(post-configure.d). 4. Migrate(migration.d), -It runs through all the phases above to ensure configuration is -applied and enabled on a machine. It will exit with an error if any -phase has a problem. The scripts in each phase should not depend on -each other having worked properly. +It runs through all the phases above to ensure configuration is applied +and enabled on a machine. It will run the scripts in error.d and then +exit with a non-zero exit status if any phase has a problem. The scripts +in each phase should not depend on each other having worked properly. Note: Earlier versions of os-refresh-config ran migration before post-configure. This was an oversight in the initial design, as diff --git a/os_refresh_config/os_refresh_config.py b/os_refresh_config/os_refresh_config.py index 642eae2..8202fbf 100755 --- a/os_refresh_config/os_refresh_config.py +++ b/os_refresh_config/os_refresh_config.py @@ -91,6 +91,13 @@ def main(argv=sys.argv): log.info('Completed phase %s' % phase) except subprocess.CalledProcessError as e: log.error("during %s phase. [%s]\n" % (phase, e)) + error_dir = os.path.join(BASE_DIR, 'error.d') + if os.path.exists(error_dir): + log.info('Calling error handlers.') + try: + subprocess.call(['dib-run-parts', error_dir]) + except OSError: + pass log.error("Aborting...") return 1 else: