Skip to content

Commit 7d0ad36

Browse files
author
Jay Faulkner
committed
Make WSGI server respect listen_* directives
The listen_port and listen_host directives are intended to allow deployers of IPA to change the port and host IPA listens on. These configs have not been obeyed since the migration to the oslo.service wsgi server. Story: 2008016 Task: 40668 Change-Id: I76235a6e6ffdf80a0f5476f577b055223cdf1585
1 parent cfede0c commit 7d0ad36

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

ironic_python_agent/api/app.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from werkzeug.wrappers import json as http_json
2424

2525
from ironic_python_agent import encoding
26-
from ironic_python_agent import netutils
2726

2827

2928
LOG = log.getLogger(__name__)
@@ -86,8 +85,6 @@ def format_exception(value):
8685

8786
class Application(object):
8887

89-
PORT = 9999
90-
9188
def __init__(self, agent, conf):
9289
"""Set up the API app.
9390
@@ -132,10 +129,11 @@ def __call__(self, environ, start_response):
132129
def start(self):
133130
"""Start the API service in the background."""
134131
self.service = wsgi.Server(self._conf, 'ironic-python-agent', app=self,
135-
host=netutils.get_wildcard_address(),
136-
port=self.PORT)
132+
host=self.agent.listen_address.hostname,
133+
port=self.agent.listen_address.port)
137134
self.service.start()
138-
LOG.info('Started API service on port %s', self.PORT)
135+
LOG.info('Started API service on port %s',
136+
self.agent.listen_address.port)
139137

140138
def stop(self):
141139
"""Stop the API service."""
@@ -144,7 +142,8 @@ def stop(self):
144142
return
145143
self.service.stop()
146144
self.service = None
147-
LOG.info('Stopped API service on port %s', self.PORT)
145+
LOG.info('Stopped API service on port %s',
146+
self.agent.listen_address.port)
148147

149148
def handle_exception(self, environ, exc):
150149
"""Handle an exception during request processing."""

ironic_python_agent/tests/unit/test_agent.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,51 @@ def set_serve_api():
375375
self.assertEqual('1' * 128, self.agent.agent_token)
376376
self.assertEqual('1' * 128, self.agent.api_client.agent_token)
377377

378+
@mock.patch(
379+
'ironic_python_agent.hardware_managers.cna._detect_cna_card',
380+
mock.Mock())
381+
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
382+
@mock.patch.object(agent.IronicPythonAgent,
383+
'_wait_for_interface', autospec=True)
384+
@mock.patch('oslo_service.wsgi.Server', autospec=True)
385+
@mock.patch.object(hardware, 'get_managers', autospec=True)
386+
def test_run_listen_host_port(self, mock_get_managers, mock_wsgi,
387+
mock_wait, mock_dispatch):
388+
CONF.set_override('inspection_callback_url', '')
389+
390+
wsgi_server = mock_wsgi.return_value
391+
392+
def set_serve_api():
393+
self.agent.serve_api = False
394+
395+
wsgi_server.start.side_effect = set_serve_api
396+
self.agent.heartbeater = mock.Mock()
397+
self.agent.listen_address = mock.Mock()
398+
self.agent.listen_address.hostname = '2001:db8:dead:beef::cafe'
399+
self.agent.listen_address.port = 9998
400+
self.agent.api_client.lookup_node = mock.Mock()
401+
self.agent.api_client.lookup_node.return_value = {
402+
'node': {
403+
'uuid': 'deadbeef-dabb-ad00-b105-f00d00bab10c'
404+
},
405+
'config': {
406+
'heartbeat_timeout': 300
407+
}
408+
}
409+
410+
self.agent.run()
411+
412+
mock_wsgi.assert_called_once_with(CONF, 'ironic-python-agent',
413+
app=self.agent.api,
414+
host='2001:db8:dead:beef::cafe',
415+
port=9998)
416+
wsgi_server.start.assert_called_once_with()
417+
mock_wait.assert_called_once_with(mock.ANY)
418+
self.assertEqual([mock.call('list_hardware_info'),
419+
mock.call('wait_for_disks')],
420+
mock_dispatch.call_args_list)
421+
self.agent.heartbeater.start.assert_called_once_with()
422+
378423
@mock.patch('eventlet.sleep', autospec=True)
379424
@mock.patch(
380425
'ironic_python_agent.hardware_managers.cna._detect_cna_card',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Since the Ussuri release, IPA has ignored the listen_host and listen_port
5+
directives. This fixes the behavior and restores those configuration
6+
values to working status.
7+
https://storyboard.openstack.org/#!/story/2008016

0 commit comments

Comments
 (0)