Skip to content

Commit

Permalink
Merge "Fix to include error message in instance faults" into stable/f…
Browse files Browse the repository at this point in the history
…olsom
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 29, 2013
2 parents f6081d0 + 6241f91 commit 747fb95
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nova/compute/utils.py
Expand Up @@ -39,8 +39,13 @@ def add_instance_fault_from_exc(context, instance_uuid, fault, exc_info=None):
"""Adds the specified fault to the database."""

code = 500
message = fault.__class__.__name__

if hasattr(fault, "kwargs"):
code = fault.kwargs.get('code', 500)
# get the message from the exception that was thrown
# if that does not exist, use the name of the exception class itself
message = fault.kwargs.get('value', message)

details = unicode(fault)
if exc_info and code == 500:
Expand All @@ -50,7 +55,7 @@ def add_instance_fault_from_exc(context, instance_uuid, fault, exc_info=None):
values = {
'instance_uuid': instance_uuid,
'code': code,
'message': fault.__class__.__name__,
'message': unicode(message),
'details': unicode(details),
}
db.instance_fault_create(context, values)
Expand Down
29 changes: 29 additions & 0 deletions nova/tests/compute/test_compute.py
Expand Up @@ -2343,6 +2343,35 @@ def fake_db_fault_create(ctxt, values):
NotImplementedError('test'),
exc_info)

def test_add_instance_fault_with_remote_error(self):
exc_info = None
instance_uuid = str(utils.gen_uuid())

def fake_db_fault_create(ctxt, values):
self.assertTrue(values['details'].startswith('Remote error'))
self.assertTrue('raise rpc_common.RemoteError'
in values['details'])
del values['details']

expected = {
'code': 500,
'instance_uuid': instance_uuid,
'message': 'My Test Message'
}
self.assertEquals(expected, values)

try:
raise rpc_common.RemoteError('test', 'My Test Message')
except rpc_common.RemoteError as exc:
exc_info = sys.exc_info()

self.stubs.Set(nova.db, 'instance_fault_create', fake_db_fault_create)

ctxt = context.get_admin_context()
compute_utils.add_instance_fault_from_exc(ctxt, instance_uuid,
exc,
exc_info)

def test_add_instance_fault_user_error(self):
exc_info = None
instance_uuid = str(utils.gen_uuid())
Expand Down

0 comments on commit 747fb95

Please sign in to comment.