diff options
author | Vladyslav Drok <vdrok@mirantis.com> | 2019-11-26 12:51:40 +0100 |
---|---|---|
committer | Riccardo Pittau <elfosardo@gmail.com> | 2019-11-28 09:39:08 +0000 |
commit | a364ceb615d6ade13a4fc12ea32251fb343ee855 (patch) | |
tree | 882a272cdb9820ed35211aecca2c79cad85d42ce | |
parent | 1a65a657cd6eeec8054c1c0f3cbacd8ffe79d707 (diff) | |
download | ironic-a364ceb615d6ade13a4fc12ea32251fb343ee855.tar.gz |
Add timeout when querying agent's command statuses
Otherwise the node can get locked up for a significant amount of time.
It conforms to the behaviour of all other (POST) HTTP requests done to
agent.
Story: 2006946
Task: 37626
Change-Id: I968606a300bc43675d7bd07f73de37967ef80c26
(cherry picked from commit 33a84d94eb4d495312e3ba750b194213737a8933)
-rw-r--r-- | ironic/drivers/modules/agent_client.py | 2 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/test_agent_client.py | 10 | ||||
-rw-r--r-- | releasenotes/notes/get-commands-status-timeout-ecbac91ea149e755.yaml | 6 |
3 files changed, 17 insertions, 1 deletions
diff --git a/ironic/drivers/modules/agent_client.py b/ironic/drivers/modules/agent_client.py index 545a6aea4..0e3fcb57b 100644 --- a/ironic/drivers/modules/agent_client.py +++ b/ironic/drivers/modules/agent_client.py @@ -162,7 +162,7 @@ class AgentClient(object): """ url = self._get_command_url(node) LOG.debug('Fetching status of agent commands for node %s', node.uuid) - resp = self.session.get(url) + resp = self.session.get(url, timeout=CONF.agent.command_timeout) result = resp.json()['commands'] status = '; '.join('%(cmd)s: result "%(res)s", error "%(err)s"' % {'cmd': r.get('command_name'), diff --git a/ironic/tests/unit/drivers/modules/test_agent_client.py b/ironic/tests/unit/drivers/modules/test_agent_client.py index 1c563f7fd..4a5d6f89f 100644 --- a/ironic/tests/unit/drivers/modules/test_agent_client.py +++ b/ironic/tests/unit/drivers/modules/test_agent_client.py @@ -21,10 +21,14 @@ import six from six.moves import http_client from ironic.common import exception +from ironic import conf from ironic.drivers.modules import agent_client from ironic.tests import base +CONF = conf.CONF + + class MockResponse(object): def __init__(self, text, status_code=http_client.OK): assert isinstance(text, six.string_types) @@ -181,6 +185,12 @@ class TestAgentClient(base.TestCase): res.json.return_value = {'commands': []} mock_get.return_value = res self.assertEqual([], self.client.get_commands_status(self.node)) + agent_url = self.node.driver_internal_info.get('agent_url') + mock_get.assert_called_once_with( + '%(agent_url)s/%(api_version)s/commands' % { + 'agent_url': agent_url, + 'api_version': CONF.agent.agent_api_version}, + timeout=CONF.agent.command_timeout) def test_prepare_image(self): self.client._command = mock.MagicMock(spec_set=[]) diff --git a/releasenotes/notes/get-commands-status-timeout-ecbac91ea149e755.yaml b/releasenotes/notes/get-commands-status-timeout-ecbac91ea149e755.yaml new file mode 100644 index 000000000..4d77dfd92 --- /dev/null +++ b/releasenotes/notes/get-commands-status-timeout-ecbac91ea149e755.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Add timeout when querying agent for commands status. Without it, + node can lock up for a quite long time and ironic will not allow + to perform any operations with it. |