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
(cherry picked from commit 7d0ad36ebd
)
This commit is contained in:
parent
9ab511c466
commit
665219e774
|
@ -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."""
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue