Make IP address of socat console configurable

When ironic supports VLAN, the management network is usually not
the same as provision network, where TFTP server resides.

This patch adds a new configuration for socat address, namely
[console]/socat_address, and defaults to $my_ip for backward
compatibility.

Change-Id: I329a1707c74dc187d890231376e8ddf9eb36390b
Closes-Bug: #1691344
This commit is contained in:
wangkf 2017-06-12 11:29:32 +08:00
parent 99ba58172c
commit 3901e0b921
5 changed files with 34 additions and 2 deletions

View File

@ -1180,6 +1180,10 @@
# start. (integer value)
#subprocess_timeout = 10
# IP address of Socat service running on the host of ironic
# conductor. Used only by Socat console. (IP address value)
#socat_address = $my_ip
[cors]

View File

@ -45,6 +45,10 @@ opts = [
default=10,
help=_('Time (in seconds) to wait for the console subprocess '
'to start.')),
cfg.IPOpt('socat_address',
default='$my_ip',
help=_('IP address of Socat service running on the host of '
'ironic conductor. Used only by Socat console.')),
]

View File

@ -251,7 +251,7 @@ def get_socat_console_url(port):
:param port: the terminal port (integer) for the node
:return: an access URL to the socat console of the node
"""
console_host = CONF.my_ip
console_host = CONF.console.socat_address
if netutils.is_valid_ipv6(console_host):
console_host = '[%s]' % console_host
@ -289,7 +289,7 @@ def start_socat_console(node_uuid, port, console_cmd):
args.append('-T%d' % CONF.console.terminal_timeout)
args.append('-L%s' % pid_file)
console_host = CONF.my_ip
console_host = CONF.console.socat_address
if netutils.is_valid_ipv6(console_host):
arg = 'TCP6-LISTEN:%(port)s,bind=[%(host)s],reuseaddr'
else:

View File

@ -402,6 +402,11 @@ class ConsoleUtilsTestCase(db_base.DbTestCase):
url = console_utils.get_socat_console_url(self.info['port'])
self.assertEqual("tcp://[::1]:%s" % self.info['port'], url)
def test_get_socat_console_url_tcp_with_address_conf(self):
self.config(socat_address="10.0.0.1", group='console')
url = console_utils.get_socat_console_url(self.info['port'])
self.assertEqual("tcp://10.0.0.1:%s" % self.info['port'], url)
@mock.patch.object(subprocess, 'Popen', autospec=True)
@mock.patch.object(console_utils, '_get_console_pid_file', autospec=True)
@mock.patch.object(console_utils, '_ensure_console_pid_dir_exists',
@ -440,6 +445,18 @@ class ConsoleUtilsTestCase(db_base.DbTestCase):
args = self._test_start_socat_console_check_arg()
self.assertNotIn('-T0', args)
def test_start_socat_console_check_arg_bind_addr_default_ipv4(self):
self.config(my_ip='10.0.0.1')
args = self._test_start_socat_console_check_arg()
self.assertIn('TCP4-LISTEN:%s,bind=10.0.0.1,reuseaddr' %
self.info['port'], args)
def test_start_socat_console_check_arg_bind_addr_ipv4(self):
self.config(socat_address='10.0.0.1', group='console')
args = self._test_start_socat_console_check_arg()
self.assertIn('TCP4-LISTEN:%s,bind=10.0.0.1,reuseaddr' %
self.info['port'], args)
@mock.patch.object(os.path, 'exists', autospec=True)
@mock.patch.object(subprocess, 'Popen', autospec=True)
@mock.patch.object(psutil, 'pid_exists', autospec=True)

View File

@ -0,0 +1,7 @@
---
features:
- |
Adds configuration option ``[console]/socat_address`` so
that the binding address of socat based console can be
configured independently. The option is backward compatible
by keeping $my_ip as the default value.