Improve last_error for async exceptions

This sets the last_error to have a more informative message when errors
occur in agent vendor asyncronous tasks.

Change-Id: I1a0962224c84725329ee834a67dbe9da8c417fb1
This commit is contained in:
Josh Gachnang 2014-07-20 10:33:04 -07:00 committed by John L. Villalovos
parent 389f201892
commit 591f3f2e34
2 changed files with 14 additions and 7 deletions

View File

@ -164,11 +164,12 @@ class BaseAgentVendor(base.VendorInterface):
self.deploy_is_done(task)):
msg = _('Node failed to move to active state.')
self.reboot_to_instance(task, **kwargs)
except Exception:
LOG.exception(_LE('Async exception for %(node)s: %(msg)s'),
{'node': node.uuid,
'msg': msg})
deploy_utils.set_failed_state(task, msg)
except Exception as e:
err_info = {'node': node.uuid, 'msg': msg, 'e': e}
last_error = _('Asynchronous exception for node %(node)s: '
'%(msg)s exception: %(e)s') % err_info
LOG.exception(last_error)
deploy_utils.set_failed_state(task, last_error)
@base.driver_passthru(['POST'], async=False)
def lookup(self, context, **kwargs):

View File

@ -263,17 +263,23 @@ class TestBaseAgentVendor(db_base.DbTestCase):
@mock.patch.object(deploy_utils, 'set_failed_state')
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'deploy_is_done')
def test_heartbeat_deploy_done_fails(self, done_mock, failed_mock):
@mock.patch.object(agent_base_vendor.LOG, 'exception')
def test_heartbeat_deploy_done_fails(self, log_mock, done_mock,
failed_mock):
kwargs = {
'agent_url': 'http://127.0.0.1:9999/bar'
}
done_mock.side_effect = Exception
done_mock.side_effect = Exception('LlamaException')
with task_manager.acquire(
self.context, self.node['uuid'], shared=True) as task:
task.node.provision_state = states.DEPLOYING
task.node.target_provision_state = states.ACTIVE
self.passthru.heartbeat(task, **kwargs)
failed_mock.assert_called_once_with(task, mock.ANY)
log_mock.assert_called_once_with(
'Asynchronous exception for node '
'1be26c0b-03f2-4d2e-ae87-c02d7f33c123: Failed checking if deploy '
'is done. exception: LlamaException')
def test_vendor_passthru_vendor_routes(self):
expected = ['heartbeat']