Translate requests exception to IronicException
This patch is just adding an exception handler around the post() method from the requests library so we can: Translate it into an IronicException and log a better error message. Closes-Bug: #1559209 Change-Id: I17f181fa759246313d36c183a8bd8f9b3d519669
This commit is contained in:
parent
8e81b964a5
commit
ea238dcffa
@ -67,9 +67,15 @@ class AgentClient(object):
|
||||
}
|
||||
LOG.debug('Executing agent command %(method)s for node %(node)s',
|
||||
{'node': node.uuid, 'method': method})
|
||||
response = self.session.post(url,
|
||||
params=request_params,
|
||||
data=body)
|
||||
|
||||
try:
|
||||
response = self.session.post(url, params=request_params, data=body)
|
||||
except requests.RequestException as e:
|
||||
msg = (_('Error invoking agent command %(method)s for node '
|
||||
'%(node)s. Error: %(error)s') %
|
||||
{'method': method, 'node': node.uuid, 'error': e})
|
||||
LOG.error(msg)
|
||||
raise exception.IronicException(msg)
|
||||
|
||||
# TODO(russellhaering): real error handling
|
||||
try:
|
||||
|
@ -118,6 +118,23 @@ class TestAgentClient(base.TestCase):
|
||||
data=body,
|
||||
params={'wait': 'false'})
|
||||
|
||||
def test__command_fail_post(self):
|
||||
error = 'Boom'
|
||||
self.client.session.post.side_effect = requests.RequestException(error)
|
||||
method = 'foo.bar'
|
||||
params = {}
|
||||
|
||||
self.client._get_command_url(self.node)
|
||||
self.client._get_command_body(method, params)
|
||||
|
||||
e = self.assertRaises(exception.IronicException,
|
||||
self.client._command,
|
||||
self.node, method, params)
|
||||
self.assertEqual('Error invoking agent command %(method)s for node '
|
||||
'%(node)s. Error: %(error)s' %
|
||||
{'method': method, 'node': self.node.uuid,
|
||||
'error': error}, str(e))
|
||||
|
||||
def test_get_commands_status(self):
|
||||
with mock.patch.object(self.client.session, 'get',
|
||||
autospec=True) as mock_get:
|
||||
|
Loading…
x
Reference in New Issue
Block a user