diff --git a/ironic_python_agent/api/app.py b/ironic_python_agent/api/app.py index 28ed03b25..a4575ce7b 100644 --- a/ironic_python_agent/api/app.py +++ b/ironic_python_agent/api/app.py @@ -23,7 +23,6 @@ from werkzeug import routing from werkzeug.wrappers import json as http_json from ironic_python_agent import encoding -from ironic_python_agent import netutils LOG = log.getLogger(__name__) @@ -86,8 +85,6 @@ def format_exception(value): class Application(object): - PORT = 9999 - def __init__(self, agent, conf): """Set up the API app. @@ -132,10 +129,11 @@ class Application(object): def start(self): """Start the API service in the background.""" self.service = wsgi.Server(self._conf, 'ironic-python-agent', app=self, - host=netutils.get_wildcard_address(), - port=self.PORT) + host=self.agent.listen_address.hostname, + port=self.agent.listen_address.port) self.service.start() - LOG.info('Started API service on port %s', self.PORT) + LOG.info('Started API service on port %s', + self.agent.listen_address.port) def stop(self): """Stop the API service.""" @@ -144,7 +142,8 @@ class Application(object): return self.service.stop() self.service = None - LOG.info('Stopped API service on port %s', self.PORT) + LOG.info('Stopped API service on port %s', + self.agent.listen_address.port) def handle_exception(self, environ, exc): """Handle an exception during request processing.""" diff --git a/ironic_python_agent/tests/unit/test_agent.py b/ironic_python_agent/tests/unit/test_agent.py index 6c461ab4c..74719b10b 100644 --- a/ironic_python_agent/tests/unit/test_agent.py +++ b/ironic_python_agent/tests/unit/test_agent.py @@ -375,6 +375,51 @@ class TestBaseAgent(ironic_agent_base.IronicAgentTest): self.assertEqual('1' * 128, self.agent.agent_token) self.assertEqual('1' * 128, self.agent.api_client.agent_token) + @mock.patch( + 'ironic_python_agent.hardware_managers.cna._detect_cna_card', + mock.Mock()) + @mock.patch.object(hardware, 'dispatch_to_managers', autospec=True) + @mock.patch.object(agent.IronicPythonAgent, + '_wait_for_interface', autospec=True) + @mock.patch('oslo_service.wsgi.Server', autospec=True) + @mock.patch.object(hardware, 'get_managers', autospec=True) + def test_run_listen_host_port(self, mock_get_managers, mock_wsgi, + mock_wait, mock_dispatch): + CONF.set_override('inspection_callback_url', '') + + wsgi_server = mock_wsgi.return_value + + def set_serve_api(): + self.agent.serve_api = False + + wsgi_server.start.side_effect = set_serve_api + self.agent.heartbeater = mock.Mock() + self.agent.listen_address = mock.Mock() + self.agent.listen_address.hostname = '2001:db8:dead:beef::cafe' + self.agent.listen_address.port = 9998 + self.agent.api_client.lookup_node = mock.Mock() + self.agent.api_client.lookup_node.return_value = { + 'node': { + 'uuid': 'deadbeef-dabb-ad00-b105-f00d00bab10c' + }, + 'config': { + 'heartbeat_timeout': 300 + } + } + + self.agent.run() + + mock_wsgi.assert_called_once_with(CONF, 'ironic-python-agent', + app=self.agent.api, + host='2001:db8:dead:beef::cafe', + port=9998) + wsgi_server.start.assert_called_once_with() + mock_wait.assert_called_once_with(mock.ANY) + self.assertEqual([mock.call('list_hardware_info'), + mock.call('wait_for_disks')], + mock_dispatch.call_args_list) + self.agent.heartbeater.start.assert_called_once_with() + @mock.patch('eventlet.sleep', autospec=True) @mock.patch( 'ironic_python_agent.hardware_managers.cna._detect_cna_card', diff --git a/releasenotes/notes/respect-listen-directives-94fb863c5b692c07.yaml b/releasenotes/notes/respect-listen-directives-94fb863c5b692c07.yaml new file mode 100644 index 000000000..3350f9425 --- /dev/null +++ b/releasenotes/notes/respect-listen-directives-94fb863c5b692c07.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Since the Ussuri release, IPA has ignored the listen_host and listen_port + directives. This fixes the behavior and restores those configuration + values to working status. + https://storyboard.openstack.org/#!/story/2008016