Skip to content

Commit cff7382

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove six.reraise"
2 parents d140d80 + 2c074b9 commit cff7382

File tree

9 files changed

+34
-47
lines changed

9 files changed

+34
-47
lines changed

nova/api/metadata/vendordata_dynamic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from keystoneauth1 import loading as ks_loading
2222
from oslo_log import log as logging
2323
from oslo_serialization import jsonutils
24-
import six
2524

2625
from nova.api.metadata import vendordata
2726
import nova.conf
@@ -115,7 +114,7 @@ def _do_request(self, service_name, url):
115114
'error': e},
116115
instance=self.instance)
117116
if CONF.api.vendordata_dynamic_failure_fatal:
118-
six.reraise(type(e), e, sys.exc_info()[2])
117+
raise e.with_traceback(sys.exc_info()[2])
119118

120119
return {}
121120

nova/compute/manager.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,15 +1740,14 @@ def _allocate_network_async(self, context, instance, requested_networks,
17401740
# for this async greenthread to finish before calling
17411741
# instance.save().
17421742
return nwinfo
1743-
except Exception:
1744-
exc_info = sys.exc_info()
1743+
except Exception as e:
17451744
log_info = {'attempt': attempt,
17461745
'attempts': attempts}
17471746
if attempt == attempts:
17481747
LOG.exception('Instance failed network setup '
17491748
'after %(attempts)d attempt(s)',
17501749
log_info)
1751-
six.reraise(*exc_info)
1750+
raise e
17521751
LOG.warning('Instance failed network setup '
17531752
'(attempt %(attempt)d of %(attempts)d)',
17541753
log_info, instance=instance)
@@ -2911,7 +2910,7 @@ def _shutdown_instance(self, context, instance,
29112910

29122911
def _cleanup_volumes(self, context, instance, bdms, raise_exc=True,
29132912
detach=True):
2914-
exc_info = None
2913+
original_exception = None
29152914
for bdm in bdms:
29162915
if detach and bdm.volume_id:
29172916
try:
@@ -2921,7 +2920,7 @@ def _cleanup_volumes(self, context, instance, bdms, raise_exc=True,
29212920
self._detach_volume(context, bdm, instance,
29222921
destroy_bdm=destroy)
29232922
except Exception as exc:
2924-
exc_info = sys.exc_info()
2923+
original_exception = exc
29252924
LOG.warning('Failed to detach volume: %(volume_id)s '
29262925
'due to %(exc)s',
29272926
{'volume_id': bdm.volume_id, 'exc': exc})
@@ -2932,12 +2931,12 @@ def _cleanup_volumes(self, context, instance, bdms, raise_exc=True,
29322931
instance_uuid=instance.uuid)
29332932
self.volume_api.delete(context, bdm.volume_id)
29342933
except Exception as exc:
2935-
exc_info = sys.exc_info()
2934+
original_exception = exc
29362935
LOG.warning('Failed to delete volume: %(volume_id)s '
29372936
'due to %(exc)s',
29382937
{'volume_id': bdm.volume_id, 'exc': exc})
2939-
if exc_info is not None and raise_exc:
2940-
six.reraise(exc_info[0], exc_info[1], exc_info[2])
2938+
if original_exception is not None and raise_exc:
2939+
raise original_exception
29412940

29422941
def _delete_instance(self, context, instance, bdms):
29432942
"""Delete an instance on this host.
@@ -5299,7 +5298,11 @@ def _reschedule_resize_or_reraise(self, context, instance, exc_info,
52995298
)
53005299
else:
53015300
# not re-scheduling
5302-
six.reraise(*exc_info)
5301+
if exc_info[1] is None:
5302+
exc_info[1] = exc_info[0]()
5303+
if exc_info[1].__traceback__ is not exc_info[2]:
5304+
raise exc_info[1].with_traceback(exc_info[2])
5305+
raise exc_info[1]
53035306

53045307
# TODO(stephenfin): Remove unused request_spec parameter in API v6.0
53055308
@messaging.expected_exceptions(exception.MigrationPreCheckError)

nova/image/glance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,14 +969,14 @@ def _reraise_translated_image_exception(image_id):
969969
"""Transform the exception for the image but keep its traceback intact."""
970970
exc_type, exc_value, exc_trace = sys.exc_info()
971971
new_exc = _translate_image_exception(image_id, exc_value)
972-
six.reraise(type(new_exc), new_exc, exc_trace)
972+
raise new_exc.with_traceback(exc_trace)
973973

974974

975975
def _reraise_translated_exception():
976976
"""Transform the exception but keep its traceback intact."""
977977
exc_type, exc_value, exc_trace = sys.exc_info()
978978
new_exc = _translate_plain_exception(exc_value)
979-
six.reraise(type(new_exc), new_exc, exc_trace)
979+
raise new_exc.with_traceback(exc_trace)
980980

981981

982982
def _translate_image_exception(image_id, exc_value):

nova/network/security_group_api.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
# License for the specific language governing permissions and limitations
1818
# under the License.
1919

20-
import sys
21-
2220
import netaddr
2321
from neutronclient.common import exceptions as n_exc
2422
from neutronclient.neutron import v2_0 as neutronv20
@@ -72,13 +70,12 @@ def validate_name(
7270
except n_exc.NeutronClientNoUniqueMatch as e:
7371
raise exception.NoUniqueMatch(six.text_type(e))
7472
except n_exc.NeutronClientException as e:
75-
exc_info = sys.exc_info()
7673
if e.status_code == 404:
7774
LOG.debug('Neutron security group %s not found', name)
7875
raise exception.SecurityGroupNotFound(six.text_type(e))
7976
else:
8077
LOG.error('Neutron Error: %s', e)
81-
six.reraise(*exc_info)
78+
raise e
8279

8380

8481
def parse_cidr(cidr):
@@ -241,7 +238,6 @@ def create_security_group(context, name, description):
241238
except n_exc.BadRequest as e:
242239
raise exception.Invalid(six.text_type(e))
243240
except n_exc.NeutronClientException as e:
244-
exc_info = sys.exc_info()
245241
LOG.exception("Neutron Error creating security group %s", name)
246242
if e.status_code == 401:
247243
# TODO(arosen) Cannot raise generic response from neutron here
@@ -250,7 +246,7 @@ def create_security_group(context, name, description):
250246
raise exc.HTTPBadRequest()
251247
elif e.status_code == 409:
252248
raise exception.SecurityGroupLimitExceeded(six.text_type(e))
253-
six.reraise(*exc_info)
249+
raise e
254250
return _convert_to_nova_security_group_format(security_group)
255251

256252

@@ -261,14 +257,13 @@ def update_security_group(context, security_group, name, description):
261257
security_group = neutron.update_security_group(
262258
security_group['id'], body).get('security_group')
263259
except n_exc.NeutronClientException as e:
264-
exc_info = sys.exc_info()
265260
LOG.exception("Neutron Error updating security group %s", name)
266261
if e.status_code == 401:
267262
# TODO(arosen) Cannot raise generic response from neutron here
268263
# as this error code could be related to bad input or over
269264
# quota
270265
raise exc.HTTPBadRequest()
271-
six.reraise(*exc_info)
266+
raise e
272267
return _convert_to_nova_security_group_format(security_group)
273268

274269

@@ -314,13 +309,12 @@ def get(context, id):
314309
group = neutron.show_security_group(id).get('security_group')
315310
return _convert_to_nova_security_group_format(group)
316311
except n_exc.NeutronClientException as e:
317-
exc_info = sys.exc_info()
318312
if e.status_code == 404:
319313
LOG.debug('Neutron security group %s not found', id)
320314
raise exception.SecurityGroupNotFound(six.text_type(e))
321315
else:
322316
LOG.error("Neutron Error: %s", e)
323-
six.reraise(*exc_info)
317+
raise e
324318

325319

326320
def list(context, project, search_opts=None):
@@ -364,14 +358,13 @@ def destroy(context, security_group):
364358
try:
365359
neutron.delete_security_group(security_group['id'])
366360
except n_exc.NeutronClientException as e:
367-
exc_info = sys.exc_info()
368361
if e.status_code == 404:
369362
raise exception.SecurityGroupNotFound(six.text_type(e))
370363
elif e.status_code == 409:
371364
raise exception.Invalid(six.text_type(e))
372365
else:
373366
LOG.error("Neutron Error: %s", e)
374-
six.reraise(*exc_info)
367+
raise e
375368

376369

377370
def add_rules(context, id, name, vals):
@@ -389,7 +382,6 @@ def add_rules(context, id, name, vals):
389382
rules = neutron.create_security_group_rule(
390383
body).get('security_group_rules')
391384
except n_exc.NeutronClientException as e:
392-
exc_info = sys.exc_info()
393385
if e.status_code == 404:
394386
LOG.exception("Neutron Error getting security group %s", name)
395387
raise exception.SecurityGroupNotFound(six.text_type(e))
@@ -401,7 +393,7 @@ def add_rules(context, id, name, vals):
401393
LOG.exception("Neutron Error: %s", e)
402394
raise exception.Invalid(six.text_type(e))
403395
else:
404-
six.reraise(*exc_info)
396+
raise e
405397
converted_rules = []
406398
for rule in rules:
407399
converted_rules.append(
@@ -467,13 +459,12 @@ def get_rule(context, id):
467459
rule = neutron.show_security_group_rule(
468460
id).get('security_group_rule')
469461
except n_exc.NeutronClientException as e:
470-
exc_info = sys.exc_info()
471462
if e.status_code == 404:
472463
LOG.debug("Neutron security group rule %s not found", id)
473464
raise exception.SecurityGroupNotFound(six.text_type(e))
474465
else:
475466
LOG.error("Neutron Error: %s", e)
476-
six.reraise(*exc_info)
467+
raise e
477468
return _convert_to_nova_security_group_rule_format(rule)
478469

479470

@@ -616,15 +607,14 @@ def add_to_instance(context, instance, security_group_name):
616607
except n_exc.NeutronClientNoUniqueMatch as e:
617608
raise exception.NoUniqueMatch(six.text_type(e))
618609
except n_exc.NeutronClientException as e:
619-
exc_info = sys.exc_info()
620610
if e.status_code == 404:
621611
msg = (_("Security group %(name)s is not found for "
622612
"project %(project)s") %
623613
{'name': security_group_name,
624614
'project': context.project_id})
625615
raise exception.SecurityGroupNotFound(msg)
626616
else:
627-
six.reraise(*exc_info)
617+
raise e
628618
params = {'device_id': instance.uuid}
629619
try:
630620
ports = neutron.list_ports(**params).get('ports')
@@ -657,12 +647,11 @@ def add_to_instance(context, instance, security_group_name):
657647
'port_id': port['id']})
658648
neutron.update_port(port['id'], {'port': updated_port})
659649
except n_exc.NeutronClientException as e:
660-
exc_info = sys.exc_info()
661650
if e.status_code == 400:
662651
raise exception.SecurityGroupCannotBeApplied(
663652
six.text_type(e))
664653
else:
665-
six.reraise(*exc_info)
654+
raise e
666655
except Exception:
667656
with excutils.save_and_reraise_exception():
668657
LOG.exception("Neutron Error:")
@@ -677,15 +666,14 @@ def remove_from_instance(context, instance, security_group_name):
677666
security_group_name,
678667
context.project_id)
679668
except n_exc.NeutronClientException as e:
680-
exc_info = sys.exc_info()
681669
if e.status_code == 404:
682670
msg = (_("Security group %(name)s is not found for "
683671
"project %(project)s") %
684672
{'name': security_group_name,
685673
'project': context.project_id})
686674
raise exception.SecurityGroupNotFound(msg)
687675
else:
688-
six.reraise(*exc_info)
676+
raise e
689677
params = {'device_id': instance.uuid}
690678
try:
691679
ports = neutron.list_ports(**params).get('ports')

nova/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def patch(cls):
137137
def _wrap_log_exception(self):
138138
exc_info = sys.exc_info()
139139
NovaExceptionReraiseFormatError.real_log_exception(self)
140-
six.reraise(*exc_info)
140+
raise exc_info[1]
141141

142142

143143
# NOTE(melwitt) This needs to be done at import time in order to also catch

nova/tests/functional/notification_sample_tests/test_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,8 @@ def test_resize_server_error_and_reschedule_was_failed(
11201120
call, but the rescheduled also was unsuccessful. In this
11211121
case called the exception block.
11221122
In the exception block send a notification about error.
1123-
At end called the six.reraise(*exc_info), which not
1124-
send another error.
1123+
At end called raising an exception based on *exc_info,
1124+
which not send another error.
11251125
"""
11261126
def _build_resources(*args, **kwargs):
11271127
raise exception.FlavorDiskTooSmall()

nova/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def wrapper(*args, **kwargs):
584584
try:
585585
return func(*args, **kwargs)
586586
except messaging.ExpectedException as e:
587-
six.reraise(*e.exc_info)
587+
raise e.exc_info[1]
588588
return wrapper
589589

590590

nova/virt/hyperv/driver.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from os_win import exceptions as os_win_exc
2525
from os_win import utilsfactory
2626
from oslo_log import log as logging
27-
import six
2827

2928
from nova import context as nova_context
3029
from nova import exception
@@ -62,12 +61,10 @@ def wrapper(*args, **kwargs):
6261
break
6362

6463
exc_info = sys.exc_info()
65-
# NOTE(claudiub): Python 3 raises the exception object given as
66-
# the second argument in six.reraise.
67-
# The original message will be maintained by passing the original
68-
# exception.
69-
exc = raised_exception(six.text_type(exc_info[1]))
70-
six.reraise(raised_exception, exc, exc_info[2])
64+
# NOTE(claudiub): The original message will be maintained
65+
# by passing the original exception.
66+
exc = raised_exception(str(exc_info[1]))
67+
raise exc.with_traceback(exc_info[2])
7168
return wrapper
7269

7370

nova/volume/cinder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def wrapper(self, ctx, res_id, *args, **kwargs):
480480

481481

482482
def _reraise(desired_exc):
483-
six.reraise(type(desired_exc), desired_exc, sys.exc_info()[2])
483+
raise desired_exc.with_traceback(sys.exc_info()[2])
484484

485485

486486
class API(object):

0 commit comments

Comments
 (0)