Make terminal timeout value configurable
Adds configuration parameter ``terminal_timeout`` to section [console] to allow operators to set the timeout value for the Socat console session. Change-Id: I9a83a3e2b2d16117df0f9c01b6c8b6c86639696c Closes-Bug: #1675404
This commit is contained in:
parent
19ced862a7
commit
7bc49c7416
@ -1144,6 +1144,12 @@
|
|||||||
# the temporary directory will be used. (string value)
|
# the temporary directory will be used. (string value)
|
||||||
#terminal_pid_dir = <None>
|
#terminal_pid_dir = <None>
|
||||||
|
|
||||||
|
# Timeout (in seconds) for the terminal session to be closed
|
||||||
|
# on inactivity. Set to 0 to disable timeout. Used only by
|
||||||
|
# Socat console. (integer value)
|
||||||
|
# Minimum value: 0
|
||||||
|
#terminal_timeout = 600
|
||||||
|
|
||||||
# Time interval (in seconds) for checking the status of
|
# Time interval (in seconds) for checking the status of
|
||||||
# console subprocess. (integer value)
|
# console subprocess. (integer value)
|
||||||
#subprocess_checking_interval = 1
|
#subprocess_checking_interval = 1
|
||||||
|
@ -31,6 +31,12 @@ opts = [
|
|||||||
help=_('Directory for holding terminal pid files. '
|
help=_('Directory for holding terminal pid files. '
|
||||||
'If not specified, the temporary directory '
|
'If not specified, the temporary directory '
|
||||||
'will be used.')),
|
'will be used.')),
|
||||||
|
cfg.IntOpt('terminal_timeout',
|
||||||
|
default=600,
|
||||||
|
min=0,
|
||||||
|
help=_('Timeout (in seconds) for the terminal session to be '
|
||||||
|
'closed on inactivity. Set to 0 to disable timeout. '
|
||||||
|
'Used only by Socat console.')),
|
||||||
cfg.IntOpt('subprocess_checking_interval',
|
cfg.IntOpt('subprocess_checking_interval',
|
||||||
default=1,
|
default=1,
|
||||||
help=_('Time interval (in seconds) for checking the status of '
|
help=_('Time interval (in seconds) for checking the status of '
|
||||||
|
@ -282,10 +282,11 @@ def start_socat_console(node_uuid, port, console_cmd):
|
|||||||
|
|
||||||
# put together the command and arguments for invoking the console
|
# put together the command and arguments for invoking the console
|
||||||
args = ['socat']
|
args = ['socat']
|
||||||
# set timeout check for user's connection. After 10min of inactivity
|
# set timeout check for user's connection. If the timeout value
|
||||||
# on client side, connection will be closed.
|
# is not 0, after timeout seconds of inactivity on the client side,
|
||||||
# TODO(ashestakov) Make timeout value configurable
|
# the connection will be closed.
|
||||||
args.append('-T600')
|
if CONF.console.terminal_timeout > 0:
|
||||||
|
args.append('-T%d' % CONF.console.terminal_timeout)
|
||||||
args.append('-L%s' % pid_file)
|
args.append('-L%s' % pid_file)
|
||||||
|
|
||||||
console_host = CONF.my_ip
|
console_host = CONF.my_ip
|
||||||
|
@ -28,6 +28,7 @@ import tempfile
|
|||||||
from ironic_lib import utils as ironic_utils
|
from ironic_lib import utils as ironic_utils
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
from oslo_service import loopingcall
|
||||||
from oslo_utils import netutils
|
from oslo_utils import netutils
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
@ -401,6 +402,44 @@ class ConsoleUtilsTestCase(db_base.DbTestCase):
|
|||||||
url = console_utils.get_socat_console_url(self.info['port'])
|
url = console_utils.get_socat_console_url(self.info['port'])
|
||||||
self.assertEqual("tcp://[::1]:%s" % self.info['port'], url)
|
self.assertEqual("tcp://[::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',
|
||||||
|
autospec=True)
|
||||||
|
@mock.patch.object(console_utils, '_stop_console', autospec=True)
|
||||||
|
@mock.patch.object(loopingcall.FixedIntervalLoopingCall, 'start',
|
||||||
|
autospec=True)
|
||||||
|
def _test_start_socat_console_check_arg(self, mock_timer_start,
|
||||||
|
mock_stop, mock_dir_exists,
|
||||||
|
mock_get_pid, mock_popen):
|
||||||
|
mock_timer_start.return_value = mock.Mock()
|
||||||
|
mock_get_pid.return_value = '/tmp/%s.pid' % self.info['uuid']
|
||||||
|
|
||||||
|
console_utils.start_socat_console(self.info['uuid'],
|
||||||
|
self.info['port'],
|
||||||
|
'ls&')
|
||||||
|
|
||||||
|
mock_stop.assert_called_once_with(self.info['uuid'])
|
||||||
|
mock_dir_exists.assert_called_once_with()
|
||||||
|
mock_get_pid.assert_called_once_with(self.info['uuid'])
|
||||||
|
mock_timer_start.assert_called_once_with(mock.ANY, interval=mock.ANY)
|
||||||
|
mock_popen.assert_called_once_with(mock.ANY, stderr=subprocess.PIPE)
|
||||||
|
return mock_popen.call_args[0][0]
|
||||||
|
|
||||||
|
def test_start_socat_console_check_arg_default_timeout(self):
|
||||||
|
args = self._test_start_socat_console_check_arg()
|
||||||
|
self.assertIn('-T600', args)
|
||||||
|
|
||||||
|
def test_start_socat_console_check_arg_timeout(self):
|
||||||
|
self.config(terminal_timeout=1, group='console')
|
||||||
|
args = self._test_start_socat_console_check_arg()
|
||||||
|
self.assertIn('-T1', args)
|
||||||
|
|
||||||
|
def test_start_socat_console_check_arg_timeout_disabled(self):
|
||||||
|
self.config(terminal_timeout=0, group='console')
|
||||||
|
args = self._test_start_socat_console_check_arg()
|
||||||
|
self.assertNotIn('-T0', args)
|
||||||
|
|
||||||
@mock.patch.object(os.path, 'exists', autospec=True)
|
@mock.patch.object(os.path, 'exists', autospec=True)
|
||||||
@mock.patch.object(subprocess, 'Popen', autospec=True)
|
@mock.patch.object(subprocess, 'Popen', autospec=True)
|
||||||
@mock.patch.object(psutil, 'pid_exists', autospec=True)
|
@mock.patch.object(psutil, 'pid_exists', autospec=True)
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
other:
|
||||||
|
- |
|
||||||
|
Adds configuration parameter ``terminal_timeout`` to section [console]
|
||||||
|
to allow operators to set the timeout value for the Socat console session.
|
||||||
|
It is time of client inactivity, in seconds, after which the connection
|
||||||
|
will be closed.
|
Loading…
Reference in New Issue
Block a user