Correct reraising of exception

When an exception was caught and rethrown, it should
call 'raise' without any arguments because it shows
the place where an exception occured initially instead
of place where the exception re-raised

Change-Id: Ia5621c1c56fb9e2fc22dc792ddb1a36862fcd49b
This commit is contained in:
gengchc2 2016-12-02 10:34:38 +08:00 committed by Lucas Alvares Gomes
parent fb23ce68ce
commit 60eb60490a
1 changed files with 9 additions and 8 deletions

View File

@ -356,14 +356,15 @@ def destroy_disk_metadata(dev, node_uuid):
run_as_root=True,
use_standard_locale=True)
except processutils.ProcessExecutionError as e:
# NOTE(zhenguo): Check if --force option is supported for wipefs,
# if not, we should try without it.
if '--force' in str(e):
utils.execute('wipefs', '--all', dev,
run_as_root=True,
use_standard_locale=True)
else:
raise e
with excutils.save_and_reraise_exception() as ctxt:
# NOTE(zhenguo): Check if --force option is supported for wipefs,
# if not, we should try without it.
if '--force' in str(e):
ctxt.reraise = False
utils.execute('wipefs', '--all', dev,
run_as_root=True,
use_standard_locale=True)
LOG.info(_LI("Disk metadata on %(dev)s successfully destroyed for node "
"%(node)s"), {'dev': dev, 'node': node_uuid})