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
This commit is contained in:
Clint Byrum 2014-03-27 17:25:34 -07:00
parent fd60517cb8
commit 64d3619302
2 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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: