Merge "Fix Reopen Web Console Duplicate Sol Session"

This commit is contained in:
Zuul 2024-03-28 21:41:33 +00:00 committed by Gerrit Code Review
commit 565d18f0d5
3 changed files with 32 additions and 2 deletions

View File

@ -1624,6 +1624,14 @@ class IPMIShellinaboxConsole(IPMIConsole):
def get_console(self, task):
"""Get the type and connection information about the console."""
driver_info = _parse_driver_info(task.node)
try:
self._exec_stop_console(driver_info)
except OSError:
# We need to drop any existing sol sessions with sol deactivate.
# OSError is raised when sol session is already deactivated,
# so we can ignore it.
pass
url = console_utils.get_shellinabox_console_url(driver_info['port'])
return {'type': 'shellinabox', 'url': url}
@ -1687,5 +1695,13 @@ class IPMISocatConsole(IPMIConsole):
:param task: a task from TaskManager
"""
driver_info = _parse_driver_info(task.node)
try:
self._exec_stop_console(driver_info)
except OSError:
# We need to drop any existing sol sessions with sol deactivate.
# OSError is raised when sol session is already deactivated,
# so we can ignore it.
pass
url = console_utils.get_socat_console_url(driver_info['port'])
return {'type': 'socat', 'url': url}

View File

@ -3418,7 +3418,9 @@ class IPMIToolShellinaboxTestCase(db_base.DbTestCase):
@mock.patch.object(console_utils, 'get_shellinabox_console_url',
autospec=True)
def test_get_console(self, mock_get):
@mock.patch.object(ipmi.IPMIShellinaboxConsole, "_exec_stop_console",
autospec=True)
def test_get_console(self, mock_exec_stop, mock_get):
url = 'http://localhost:4201'
mock_get.return_value = url
expected = {'type': 'shellinabox', 'url': url}
@ -3426,7 +3428,9 @@ class IPMIToolShellinaboxTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context,
self.node.uuid) as task:
console_info = self.console.get_console(task)
driver_info = ipmi._parse_driver_info(task.node)
mock_exec_stop.assert_called_once_with(self.console, driver_info)
self.assertEqual(expected, console_info)
mock_get.assert_called_once_with(self.info['port'])
@ -3651,7 +3655,9 @@ class IPMIToolSocatDriverTestCase(IPMIToolShellinaboxTestCase):
@mock.patch.object(console_utils, 'get_socat_console_url',
autospec=True)
def test_get_console(self, mock_get_url):
@mock.patch.object(ipmi.IPMISocatConsole, '_exec_stop_console',
autospec=True)
def test_get_console(self, mock_exec_stop, mock_get_url):
url = 'tcp://localhost:4201'
mock_get_url.return_value = url
expected = {'type': 'socat', 'url': url}
@ -3659,6 +3665,8 @@ class IPMIToolSocatDriverTestCase(IPMIToolShellinaboxTestCase):
with task_manager.acquire(self.context,
self.node.uuid) as task:
console_info = self.console.get_console(task)
driver_info = ipmi._parse_driver_info(task.node)
mock_exec_stop.assert_called_once_with(self.console, driver_info)
self.assertEqual(expected, console_info)
mock_get_url.assert_called_once_with(self.info['port'])

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Ironic now stops any active IPMI Serial-Over-LAN console sessions when
initializing a console session. This resolves and issue where console support
would fail if a previous console session was not properly disconnected.