summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorJay Faulkner <jay.faulkner@verizonmedia.com>2020-08-28 15:25:36 -0700
committerJay Faulkner <jay.faulkner@verizonmedia.com>2020-08-31 14:37:38 +0000
commit7d0ad36ebd350a7162bc3c33bbefd26b9e962a78 (patch)
tree09c0caf6f5488ed6f16ba6202245cce3ea4b3220 /ironic_python_agent
parentcfede0c5bc75ea61f42c1a17809586191ebb4edf (diff)
downloadironic-python-agent-7d0ad36ebd350a7162bc3c33bbefd26b9e962a78.tar.gz
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
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/api/app.py13
-rw-r--r--ironic_python_agent/tests/unit/test_agent.py45
2 files changed, 51 insertions, 7 deletions
diff --git a/ironic_python_agent/api/app.py b/ironic_python_agent/api/app.py
index 28ed03b2..a4575ce7 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 1a2b75a8..fdcd1796 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',