diff --git a/etc/ironic/ironic.conf.sample b/etc/ironic/ironic.conf.sample index c71d0e8516..dd31ebdadb 100644 --- a/etc/ironic/ironic.conf.sample +++ b/etc/ironic/ironic.conf.sample @@ -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] diff --git a/ironic/conf/console.py b/ironic/conf/console.py index 9a9999664d..2713511132 100644 --- a/ironic/conf/console.py +++ b/ironic/conf/console.py @@ -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.')), ] diff --git a/ironic/drivers/modules/console_utils.py b/ironic/drivers/modules/console_utils.py index 2b41a2f8fc..2967be523d 100644 --- a/ironic/drivers/modules/console_utils.py +++ b/ironic/drivers/modules/console_utils.py @@ -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: diff --git a/ironic/tests/unit/drivers/modules/test_console_utils.py b/ironic/tests/unit/drivers/modules/test_console_utils.py index 1282eab0f3..d9f0e67199 100644 --- a/ironic/tests/unit/drivers/modules/test_console_utils.py +++ b/ironic/tests/unit/drivers/modules/test_console_utils.py @@ -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) diff --git a/releasenotes/notes/socat-address-conf-5cf043fabb10bd76.yaml b/releasenotes/notes/socat-address-conf-5cf043fabb10bd76.yaml new file mode 100644 index 0000000000..266aecdfa6 --- /dev/null +++ b/releasenotes/notes/socat-address-conf-5cf043fabb10bd76.yaml @@ -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.