Make error notifications more consistent.
The error notifications sent by wrap_exception are a good source of information when tracking down errors in the system. It is easy to spot patterns in the errors by looking at similarities in the exceptions raised. This change looks at making the in-line error notifications follow the same format, so they become equally useful. Closes-Bug: #1251602 Change-Id: I1cd64a90ecefc64d12af05487eb6e45aa0362d69
This commit is contained in:
		 John Garbutt
					John Garbutt
				
			
				
					committed by
					
						 John Garbutt
						John Garbutt
					
				
			
			
				
	
			
			
			 John Garbutt
						John Garbutt
					
				
			
						parent
						
							cb31014353
						
					
				
				
					commit
					f35c63df24
				
			| @@ -39,12 +39,11 @@ CONF.import_opt('host', 'nova.netconf') | ||||
| LOG = log.getLogger(__name__) | ||||
|  | ||||
|  | ||||
| def add_instance_fault_from_exc(context, conductor, | ||||
|                                 instance, fault, exc_info=None): | ||||
|     """Adds the specified fault to the database.""" | ||||
| def exception_to_dict(fault): | ||||
|     """Converts exceptions to a dict for use in notifications.""" | ||||
|     #TODO(johngarbutt) move to nova/exception.py to share with wrap_exception | ||||
|  | ||||
|     code = 500 | ||||
|  | ||||
|     if hasattr(fault, "kwargs"): | ||||
|         code = fault.kwargs.get('code', 500) | ||||
|  | ||||
| @@ -65,17 +64,35 @@ def add_instance_fault_from_exc(context, conductor, | ||||
|     # MySQL silently truncates overly long messages, but PostgreSQL throws an | ||||
|     # error if we don't truncate it. | ||||
|     u_message = unicode(message)[:255] | ||||
|     details = '' | ||||
|  | ||||
|     if exc_info and code == 500: | ||||
|     fault_dict = dict(exception=fault) | ||||
|     fault_dict["message"] = u_message | ||||
|     fault_dict["code"] = code | ||||
|     return fault_dict | ||||
|  | ||||
|  | ||||
| def _get_fault_details(exc_info, error_code): | ||||
|     details = '' | ||||
|     if exc_info and error_code == 500: | ||||
|         tb = exc_info[2] | ||||
|         details += ''.join(traceback.format_tb(tb)) | ||||
|         if tb: | ||||
|             details = ''.join(traceback.format_tb(tb)) | ||||
|     return unicode(details) | ||||
|  | ||||
|  | ||||
| def add_instance_fault_from_exc(context, conductor, | ||||
|                                 instance, fault, exc_info=None): | ||||
|     """Adds the specified fault to the database.""" | ||||
|  | ||||
|     fault_dict = exception_to_dict(fault) | ||||
|     code = fault_dict["code"] | ||||
|     details = _get_fault_details(exc_info, code) | ||||
|  | ||||
|     values = { | ||||
|         'instance_uuid': instance['uuid'], | ||||
|         'code': code, | ||||
|         'message': u_message, | ||||
|         'details': unicode(details), | ||||
|         'message': fault_dict["message"], | ||||
|         'details': details, | ||||
|         'host': CONF.host | ||||
|     } | ||||
|     conductor.instance_fault_create(context, values) | ||||
| @@ -294,7 +311,7 @@ def notify_usage_exists(notifier, context, instance_ref, current_period=False, | ||||
|  | ||||
| def notify_about_instance_usage(notifier, context, instance, event_suffix, | ||||
|                                 network_info=None, system_metadata=None, | ||||
|                                 extra_usage_info=None): | ||||
|                                 extra_usage_info=None, fault=None): | ||||
|     """Send a notification about an instance. | ||||
|  | ||||
|     :param notifier: a messaging.Notifier | ||||
| @@ -311,6 +328,13 @@ def notify_about_instance_usage(notifier, context, instance, event_suffix, | ||||
|     usage_info = notifications.info_from_instance(context, instance, | ||||
|             network_info, system_metadata, **extra_usage_info) | ||||
|  | ||||
|     if fault: | ||||
|         # NOTE(johngarbutt) mirrors the format in wrap_exception | ||||
|         fault_payload = exception_to_dict(fault) | ||||
|         LOG.debug(fault_payload["message"], instance=instance, | ||||
|                   exc_info=True) | ||||
|         usage_info.update(fault_payload) | ||||
|  | ||||
|     if event_suffix.endswith("error"): | ||||
|         method = notifier.error | ||||
|     else: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user