diff options
author | Lucas Alvares Gomes <lucasagomes@gmail.com> | 2016-03-18 16:52:49 +0000 |
---|---|---|
committer | Lucas Alvares Gomes <lucasagomes@gmail.com> | 2016-03-18 16:57:02 +0000 |
commit | ea238dcffa2a415c2ac40ee0f42977b1bfc0b1a1 (patch) | |
tree | 0c4ad4e96a8e89d4f7776af8cd5e22dc4a476ec8 | |
parent | 8e81b964a5fc815a7d42be749331571f4bb56be1 (diff) | |
download | ironic-ea238dcffa2a415c2ac40ee0f42977b1bfc0b1a1.tar.gz |
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
-rw-r--r-- | ironic/drivers/modules/agent_client.py | 12 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/test_agent_client.py | 17 |
2 files changed, 26 insertions, 3 deletions
diff --git a/ironic/drivers/modules/agent_client.py b/ironic/drivers/modules/agent_client.py index 46ca56369..86c985e59 100644 --- a/ironic/drivers/modules/agent_client.py +++ b/ironic/drivers/modules/agent_client.py @@ -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: diff --git a/ironic/tests/unit/drivers/modules/test_agent_client.py b/ironic/tests/unit/drivers/modules/test_agent_client.py index 420040859..fe5be2dba 100644 --- a/ironic/tests/unit/drivers/modules/test_agent_client.py +++ b/ironic/tests/unit/drivers/modules/test_agent_client.py @@ -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: |