From 60eb60490a99e14d60ba421d23cda38e747309e9 Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Fri, 2 Dec 2016 10:34:38 +0800 Subject: [PATCH] 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 --- ironic_lib/disk_utils.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ironic_lib/disk_utils.py b/ironic_lib/disk_utils.py index b694b125..f01a5e33 100644 --- a/ironic_lib/disk_utils.py +++ b/ironic_lib/disk_utils.py @@ -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})