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
This commit is contained in:
Vladyslav Drok 2019-11-26 12:51:40 +01:00
parent 7a8d740c68
commit 33a84d94eb
3 changed files with 17 additions and 1 deletions

View File

@ -162,7 +162,7 @@ class AgentClient(object):
""" """
url = self._get_command_url(node) url = self._get_command_url(node)
LOG.debug('Fetching status of agent commands for node %s', node.uuid) 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'] result = resp.json()['commands']
status = '; '.join('%(cmd)s: result "%(res)s", error "%(err)s"' % status = '; '.join('%(cmd)s: result "%(res)s", error "%(err)s"' %
{'cmd': r.get('command_name'), {'cmd': r.get('command_name'),

View File

@ -21,10 +21,14 @@ import six
from six.moves import http_client from six.moves import http_client
from ironic.common import exception from ironic.common import exception
from ironic import conf
from ironic.drivers.modules import agent_client from ironic.drivers.modules import agent_client
from ironic.tests import base from ironic.tests import base
CONF = conf.CONF
class MockResponse(object): class MockResponse(object):
def __init__(self, text, status_code=http_client.OK): def __init__(self, text, status_code=http_client.OK):
assert isinstance(text, six.string_types) assert isinstance(text, six.string_types)
@ -181,6 +185,12 @@ class TestAgentClient(base.TestCase):
res.json.return_value = {'commands': []} res.json.return_value = {'commands': []}
mock_get.return_value = res mock_get.return_value = res
self.assertEqual([], self.client.get_commands_status(self.node)) 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): def test_prepare_image(self):
self.client._command = mock.MagicMock(spec_set=[]) self.client._command = mock.MagicMock(spec_set=[])

View File

@ -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.