Skip to content

Commit a9e0b05

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use 'Exception.__traceback__' for versioned notifications"
2 parents bc23ce7 + 125df26 commit a9e0b05

File tree

13 files changed

+161
-187
lines changed

13 files changed

+161
-187
lines changed

nova/compute/manager.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,42 +2339,38 @@ def _build_and_run_instance(self, context, instance, image, injected_files,
23392339
with excutils.save_and_reraise_exception():
23402340
self._notify_about_instance_usage(context, instance,
23412341
'create.error', fault=e)
2342-
tb = traceback.format_exc()
23432342
compute_utils.notify_about_instance_create(
23442343
context, instance, self.host,
23452344
phase=fields.NotificationPhase.ERROR, exception=e,
2346-
bdms=block_device_mapping, tb=tb)
2345+
bdms=block_device_mapping)
23472346
except exception.ComputeResourcesUnavailable as e:
23482347
LOG.debug(e.format_message(), instance=instance)
23492348
self._notify_about_instance_usage(context, instance,
23502349
'create.error', fault=e)
2351-
tb = traceback.format_exc()
23522350
compute_utils.notify_about_instance_create(
23532351
context, instance, self.host,
23542352
phase=fields.NotificationPhase.ERROR, exception=e,
2355-
bdms=block_device_mapping, tb=tb)
2353+
bdms=block_device_mapping)
23562354
raise exception.RescheduledException(
23572355
instance_uuid=instance.uuid, reason=e.format_message())
23582356
except exception.BuildAbortException as e:
23592357
with excutils.save_and_reraise_exception():
23602358
LOG.debug(e.format_message(), instance=instance)
23612359
self._notify_about_instance_usage(context, instance,
23622360
'create.error', fault=e)
2363-
tb = traceback.format_exc()
23642361
compute_utils.notify_about_instance_create(
23652362
context, instance, self.host,
23662363
phase=fields.NotificationPhase.ERROR, exception=e,
2367-
bdms=block_device_mapping, tb=tb)
2364+
bdms=block_device_mapping)
23682365
except exception.NoMoreFixedIps as e:
23692366
LOG.warning('No more fixed IP to be allocated',
23702367
instance=instance)
23712368
self._notify_about_instance_usage(context, instance,
23722369
'create.error', fault=e)
2373-
tb = traceback.format_exc()
23742370
compute_utils.notify_about_instance_create(
23752371
context, instance, self.host,
23762372
phase=fields.NotificationPhase.ERROR, exception=e,
2377-
bdms=block_device_mapping, tb=tb)
2373+
bdms=block_device_mapping)
23782374
msg = _('Failed to allocate the network(s) with error %s, '
23792375
'not rescheduling.') % e.format_message()
23802376
raise exception.BuildAbortException(instance_uuid=instance.uuid,
@@ -2389,11 +2385,10 @@ def _build_and_run_instance(self, context, instance, image, injected_files,
23892385
instance=instance)
23902386
self._notify_about_instance_usage(context, instance,
23912387
'create.error', fault=e)
2392-
tb = traceback.format_exc()
23932388
compute_utils.notify_about_instance_create(
23942389
context, instance, self.host,
23952390
phase=fields.NotificationPhase.ERROR, exception=e,
2396-
bdms=block_device_mapping, tb=tb)
2391+
bdms=block_device_mapping)
23972392
msg = _('Failed to allocate the network(s), not rescheduling.')
23982393
raise exception.BuildAbortException(instance_uuid=instance.uuid,
23992394
reason=msg)
@@ -2412,23 +2407,21 @@ def _build_and_run_instance(self, context, instance, image, injected_files,
24122407
exception.RequestedVRamTooHigh) as e:
24132408
self._notify_about_instance_usage(context, instance,
24142409
'create.error', fault=e)
2415-
tb = traceback.format_exc()
24162410
compute_utils.notify_about_instance_create(
24172411
context, instance, self.host,
24182412
phase=fields.NotificationPhase.ERROR, exception=e,
2419-
bdms=block_device_mapping, tb=tb)
2413+
bdms=block_device_mapping)
24202414
raise exception.BuildAbortException(instance_uuid=instance.uuid,
24212415
reason=e.format_message())
24222416
except Exception as e:
24232417
LOG.exception('Failed to build and run instance',
24242418
instance=instance)
24252419
self._notify_about_instance_usage(context, instance,
24262420
'create.error', fault=e)
2427-
tb = traceback.format_exc()
24282421
compute_utils.notify_about_instance_create(
24292422
context, instance, self.host,
24302423
phase=fields.NotificationPhase.ERROR, exception=e,
2431-
bdms=block_device_mapping, tb=tb)
2424+
bdms=block_device_mapping)
24322425
raise exception.RescheduledException(
24332426
instance_uuid=instance.uuid, reason=six.text_type(e))
24342427

@@ -2460,11 +2453,10 @@ def _build_and_run_instance(self, context, instance, image, injected_files,
24602453
with excutils.save_and_reraise_exception():
24612454
self._notify_about_instance_usage(context, instance,
24622455
'create.error', fault=e)
2463-
tb = traceback.format_exc()
24642456
compute_utils.notify_about_instance_create(
24652457
context, instance, self.host,
24662458
phase=fields.NotificationPhase.ERROR, exception=e,
2467-
bdms=block_device_mapping, tb=tb)
2459+
bdms=block_device_mapping)
24682460

24692461
self._update_scheduler_instance_info(context, instance)
24702462
self._notify_about_instance_usage(context, instance, 'create.end',
@@ -3235,13 +3227,11 @@ def _rebuild_default_impl(self, context, instance, image_meta,
32353227
block_device_info=new_block_device_info)
32363228

32373229
def _notify_instance_rebuild_error(self, context, instance, error, bdms):
3238-
tb = traceback.format_exc()
32393230
self._notify_about_instance_usage(context, instance,
32403231
'rebuild.error', fault=error)
32413232
compute_utils.notify_about_instance_rebuild(
32423233
context, instance, self.host,
3243-
phase=fields.NotificationPhase.ERROR, exception=error, bdms=bdms,
3244-
tb=tb)
3234+
phase=fields.NotificationPhase.ERROR, exception=error, bdms=bdms)
32453235

32463236
@messaging.expected_exceptions(exception.PreserveEphemeralNotSupported)
32473237
@wrap_exception()
@@ -3748,12 +3738,11 @@ def bad_volumes_callback(bad_devices):
37483738
instance, error, exc_info)
37493739
self._notify_about_instance_usage(context, instance,
37503740
'reboot.error', fault=error)
3751-
tb = traceback.format_exc()
37523741
compute_utils.notify_about_instance_action(
37533742
context, instance, self.host,
37543743
action=fields.NotificationAction.REBOOT,
37553744
phase=fields.NotificationPhase.ERROR,
3756-
exception=error, bdms=bdms, tb=tb
3745+
exception=error, bdms=bdms
37573746
)
37583747
ctxt.reraise = False
37593748
else:
@@ -5263,7 +5252,7 @@ def _reschedule_resize_or_reraise(self, context, instance, exc_info,
52635252
action=fields.NotificationAction.RESIZE,
52645253
phase=fields.NotificationPhase.ERROR,
52655254
exception=error,
5266-
tb=','.join(traceback.format_exception(*exc_info)))
5255+
)
52675256

52685257
if rescheduled:
52695258
self._log_original_error(exc_info, instance_uuid)
@@ -5276,7 +5265,7 @@ def _reschedule_resize_or_reraise(self, context, instance, exc_info,
52765265
action=fields.NotificationAction.RESIZE,
52775266
phase=fields.NotificationPhase.ERROR,
52785267
exception=exc_info[1],
5279-
tb=','.join(traceback.format_exception(*exc_info)))
5268+
)
52805269
else:
52815270
# not re-scheduling
52825271
six.reraise(*exc_info)
@@ -6977,13 +6966,12 @@ def _attach_volume(self, context, instance, bdm):
69776966
exc, instance=instance)
69786967
else:
69796968
self.volume_api.unreserve_volume(context, bdm.volume_id)
6980-
tb = traceback.format_exc()
69816969
compute_utils.notify_about_volume_attach_detach(
69826970
context, instance, self.host,
69836971
action=fields.NotificationAction.VOLUME_ATTACH,
69846972
phase=fields.NotificationPhase.ERROR,
69856973
exception=e,
6986-
volume_id=bdm.volume_id, tb=tb)
6974+
volume_id=bdm.volume_id)
69876975

69886976
info = {'volume_id': bdm.volume_id}
69896977
self._notify_about_instance_usage(
@@ -7184,11 +7172,10 @@ def _swap_volume(self, context, instance, bdm, connector,
71847172
except Exception as ex:
71857173
failed = True
71867174
with excutils.save_and_reraise_exception():
7187-
tb = traceback.format_exc()
71887175
compute_utils.notify_about_volume_swap(
71897176
context, instance, self.host,
71907177
fields.NotificationPhase.ERROR,
7191-
old_volume_id, new_volume_id, ex, tb)
7178+
old_volume_id, new_volume_id, ex)
71927179
if new_cinfo:
71937180
msg = ("Failed to swap volume %(old_volume_id)s "
71947181
"for %(new_volume_id)s")
@@ -7497,12 +7484,11 @@ def attach_interface(self, context, instance, network_id, port_id,
74977484
instance=instance)
74987485
self._deallocate_port_for_instance(context, instance, port_id)
74997486

7500-
tb = traceback.format_exc()
75017487
compute_utils.notify_about_instance_action(
75027488
context, instance, self.host,
75037489
action=fields.NotificationAction.INTERFACE_ATTACH,
75047490
phase=fields.NotificationPhase.ERROR,
7505-
exception=ex, tb=tb)
7491+
exception=ex)
75067492

75077493
raise exception.InterfaceAttachFailed(
75087494
instance_uuid=instance.uuid)

nova/compute/utils.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -452,22 +452,23 @@ def notify_about_instance_usage(notifier, context, instance, event_suffix,
452452
method(context, 'compute.instance.%s' % event_suffix, usage_info)
453453

454454

455-
def _get_fault_and_priority_from_exc_and_tb(exception, tb):
455+
def _get_fault_and_priority_from_exception(exception: Exception):
456456
fault = None
457457
priority = fields.NotificationPriority.INFO
458458

459-
if exception:
460-
priority = fields.NotificationPriority.ERROR
461-
fault = notification_exception.ExceptionPayload.from_exc_and_traceback(
462-
exception, tb)
459+
if not exception:
460+
return fault, priority
461+
462+
fault = notification_exception.ExceptionPayload.from_exception(exception)
463+
priority = fields.NotificationPriority.ERROR
463464

464465
return fault, priority
465466

466467

467468
@rpc.if_notifications_enabled
468469
def notify_about_instance_action(context, instance, host, action, phase=None,
469470
source=fields.NotificationSource.COMPUTE,
470-
exception=None, bdms=None, tb=None):
471+
exception=None, bdms=None):
471472
"""Send versioned notification about the action made on the instance
472473
:param instance: the instance which the action performed on
473474
:param host: the host emitting the notification
@@ -476,10 +477,9 @@ def notify_about_instance_action(context, instance, host, action, phase=None,
476477
:param source: the source of the notification
477478
:param exception: the thrown exception (used in error notifications)
478479
:param bdms: BlockDeviceMappingList object for the instance. If it is not
479-
provided then we will load it from the db if so configured
480-
:param tb: the traceback (used in error notifications)
480+
provided then we will load it from the db if so configured
481481
"""
482-
fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
482+
fault, priority = _get_fault_and_priority_from_exception(exception)
483483
payload = instance_notification.InstanceActionPayload(
484484
context=context,
485485
instance=instance,
@@ -500,7 +500,7 @@ def notify_about_instance_action(context, instance, host, action, phase=None,
500500

501501
@rpc.if_notifications_enabled
502502
def notify_about_instance_create(context, instance, host, phase=None,
503-
exception=None, bdms=None, tb=None):
503+
exception=None, bdms=None):
504504
"""Send versioned notification about instance creation
505505
506506
:param context: the request context
@@ -510,9 +510,8 @@ def notify_about_instance_create(context, instance, host, phase=None,
510510
:param exception: the thrown exception (used in error notifications)
511511
:param bdms: BlockDeviceMappingList object for the instance. If it is not
512512
provided then we will load it from the db if so configured
513-
:param tb: the traceback (used in error notifications)
514513
"""
515-
fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
514+
fault, priority = _get_fault_and_priority_from_exception(exception)
516515
payload = instance_notification.InstanceCreatePayload(
517516
context=context,
518517
instance=instance,
@@ -558,17 +557,16 @@ def notify_about_scheduler_action(context, request_spec, action, phase=None,
558557

559558
@rpc.if_notifications_enabled
560559
def notify_about_volume_attach_detach(context, instance, host, action, phase,
561-
volume_id=None, exception=None, tb=None):
560+
volume_id=None, exception=None):
562561
"""Send versioned notification about the action made on the instance
563562
:param instance: the instance which the action performed on
564563
:param host: the host emitting the notification
565564
:param action: the name of the action
566565
:param phase: the phase of the action
567566
:param volume_id: id of the volume will be attached
568567
:param exception: the thrown exception (used in error notifications)
569-
:param tb: the traceback (used in error notifications)
570568
"""
571-
fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
569+
fault, priority = _get_fault_and_priority_from_exception(exception)
572570
payload = instance_notification.InstanceActionVolumePayload(
573571
context=context,
574572
instance=instance,
@@ -590,17 +588,16 @@ def notify_about_volume_attach_detach(context, instance, host, action, phase,
590588
@rpc.if_notifications_enabled
591589
def notify_about_instance_rescue_action(context, instance, host,
592590
rescue_image_ref, phase=None,
593-
exception=None, tb=None):
591+
exception=None):
594592
"""Send versioned notification about the action made on the instance
595593
596594
:param instance: the instance which the action performed on
597595
:param host: the host emitting the notification
598596
:param rescue_image_ref: the rescue image ref
599597
:param phase: the phase of the action
600598
:param exception: the thrown exception (used in error notifications)
601-
:param tb: the traceback (used in error notifications)
602599
"""
603-
fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
600+
fault, priority = _get_fault_and_priority_from_exception(exception)
604601
payload = instance_notification.InstanceActionRescuePayload(
605602
context=context,
606603
instance=instance,
@@ -644,8 +641,7 @@ def notify_about_keypair_action(context, keypair, action, phase):
644641

645642
@rpc.if_notifications_enabled
646643
def notify_about_volume_swap(context, instance, host, phase,
647-
old_volume_id, new_volume_id, exception=None,
648-
tb=None):
644+
old_volume_id, new_volume_id, exception=None):
649645
"""Send versioned notification about the volume swap action
650646
on the instance
651647
@@ -656,9 +652,8 @@ def notify_about_volume_swap(context, instance, host, phase,
656652
:param old_volume_id: the ID of the volume that is copied from and detached
657653
:param new_volume_id: the ID of the volume that is copied to and attached
658654
:param exception: an exception
659-
:param tb: the traceback (used in error notifications)
660655
"""
661-
fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
656+
fault, priority = _get_fault_and_priority_from_exception(exception)
662657
payload = instance_notification.InstanceActionVolumeSwapPayload(
663658
context=context,
664659
instance=instance,
@@ -877,7 +872,7 @@ def notify_about_instance_rebuild(context, instance, host,
877872
action=fields.NotificationAction.REBUILD,
878873
phase=None,
879874
source=fields.NotificationSource.COMPUTE,
880-
exception=None, bdms=None, tb=None):
875+
exception=None, bdms=None):
881876
"""Send versioned notification about instance rebuild
882877
883878
:param instance: the instance which the action performed on
@@ -888,9 +883,8 @@ def notify_about_instance_rebuild(context, instance, host,
888883
:param exception: the thrown exception (used in error notifications)
889884
:param bdms: BlockDeviceMappingList object for the instance. If it is not
890885
provided then we will load it from the db if so configured
891-
:param tb: the traceback (used in error notifications)
892886
"""
893-
fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
887+
fault, priority = _get_fault_and_priority_from_exception(exception)
894888
payload = instance_notification.InstanceActionRebuildPayload(
895889
context=context,
896890
instance=instance,
@@ -938,15 +932,14 @@ def notify_about_metrics_update(context, host, host_ip, nodename,
938932

939933

940934
@rpc.if_notifications_enabled
941-
def notify_about_libvirt_connect_error(context, ip, exception, tb):
935+
def notify_about_libvirt_connect_error(context, ip, exception):
942936
"""Send a versioned notification about libvirt connect error.
943937
944938
:param context: the request context
945939
:param ip: the IP address of the host
946940
:param exception: the thrown exception
947-
:param tb: the traceback
948941
"""
949-
fault, _ = _get_fault_and_priority_from_exc_and_tb(exception, tb)
942+
fault, _ = _get_fault_and_priority_from_exception(exception)
950943
payload = libvirt_notification.LibvirtErrorPayload(ip=ip, reason=fault)
951944
notification = libvirt_notification.LibvirtErrorNotification(
952945
priority=fields.NotificationPriority.ERROR,
@@ -984,7 +977,7 @@ def notify_about_volume_usage(context, vol_usage, host):
984977

985978
@rpc.if_notifications_enabled
986979
def notify_about_compute_task_error(context, action, instance_uuid,
987-
request_spec, state, exception, tb):
980+
request_spec, state, exception):
988981
"""Send a versioned notification about compute task error.
989982
990983
:param context: the request context
@@ -1001,7 +994,7 @@ def notify_about_compute_task_error(context, action, instance_uuid,
1001994
request_spec = objects.RequestSpec.from_primitives(
1002995
context, request_spec, {})
1003996

1004-
fault, _ = _get_fault_and_priority_from_exc_and_tb(exception, tb)
997+
fault, _ = _get_fault_and_priority_from_exception(exception)
1005998
payload = task_notification.ComputeTaskPayload(
1006999
instance_uuid=instance_uuid, request_spec=request_spec, state=state,
10071000
reason=fault)

0 commit comments

Comments
 (0)