From 33a84d94eb4d495312e3ba750b194213737a8933 Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Tue, 26 Nov 2019 12:51:40 +0100 Subject: [PATCH] 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 --- ironic/drivers/modules/agent_client.py | 2 +- ironic/tests/unit/drivers/modules/test_agent_client.py | 10 ++++++++++ .../get-commands-status-timeout-ecbac91ea149e755.yaml | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/get-commands-status-timeout-ecbac91ea149e755.yaml diff --git a/ironic/drivers/modules/agent_client.py b/ironic/drivers/modules/agent_client.py index 545a6aea49..0e3fcb57b8 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 1c563f7fd3..4a5d6f89f3 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 0000000000..4d77dfd92c --- /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.