IPMI command should depend on console type
This change implements _get_impi_cmd method for IPMI consoles. Depends on type of console, ipmi command should contain different arguments. Change-Id: I55e712a1a91aed3d533f636e519f0bae1f9be2d4 Closes-bug: #1611285
This commit is contained in:
parent
a82d657635
commit
0acbf378bb
@ -1163,6 +1163,21 @@ class IPMIConsole(base.ConsoleInterface):
|
||||
"Check the 'ipmi_protocol_version' parameter in "
|
||||
"node's driver_info"))
|
||||
|
||||
def _get_ipmi_cmd(self, driver_info, pw_file):
|
||||
"""Get ipmi command for ipmitool usage.
|
||||
|
||||
:param driver_info: driver info with the ipmitool parameters
|
||||
:param pw_file: password file to be used in ipmitool command
|
||||
:returns: returns a command string for ipmitool
|
||||
"""
|
||||
user = driver_info.get('username')
|
||||
user = ' -U {}'.format(user) if user else ''
|
||||
return ("ipmitool -H %(address)s -I lanplus"
|
||||
"%(user)s -f %(pwfile)s"
|
||||
% {'address': driver_info['address'],
|
||||
'user': user,
|
||||
'pwfile': pw_file})
|
||||
|
||||
def _start_console(self, driver_info, start_method):
|
||||
"""Start a remote console for the node.
|
||||
|
||||
@ -1178,14 +1193,7 @@ class IPMIConsole(base.ConsoleInterface):
|
||||
path = _console_pwfile_path(driver_info['uuid'])
|
||||
pw_file = console_utils.make_persistent_password_file(
|
||||
path, driver_info['password'] or '\0')
|
||||
|
||||
ipmi_cmd = ("/:%(uid)s:%(gid)s:HOME:ipmitool -H %(address)s"
|
||||
" -I lanplus -U %(user)s -f %(pwfile)s"
|
||||
% {'uid': os.getuid(),
|
||||
'gid': os.getgid(),
|
||||
'address': driver_info['address'],
|
||||
'user': driver_info['username'],
|
||||
'pwfile': pw_file})
|
||||
ipmi_cmd = self._get_ipmi_cmd(driver_info, pw_file)
|
||||
|
||||
for name, option in BRIDGING_OPTIONS:
|
||||
if driver_info[name] is not None:
|
||||
@ -1205,6 +1213,20 @@ class IPMIConsole(base.ConsoleInterface):
|
||||
class IPMIShellinaboxConsole(IPMIConsole):
|
||||
"""A ConsoleInterface that uses ipmitool and shellinabox."""
|
||||
|
||||
def _get_ipmi_cmd(self, driver_info, pw_file):
|
||||
"""Get ipmi command for ipmitool usage.
|
||||
|
||||
:param driver_info: driver info with the ipmitool parameters
|
||||
:param pw_file: password file to be used in ipmitool command
|
||||
:returns: returns a command string for ipmitool
|
||||
"""
|
||||
command = super(IPMIShellinaboxConsole, self)._get_ipmi_cmd(
|
||||
driver_info, pw_file)
|
||||
return ("/:%(uid)s:%(gid)s:HOME:%(basic_command)s"
|
||||
% {'uid': os.getuid(),
|
||||
'gid': os.getgid(),
|
||||
'basic_command': command})
|
||||
|
||||
@METRICS.timer('IPMIShellinaboxConsole.start_console')
|
||||
def start_console(self, task):
|
||||
"""Start a remote console for the node.
|
||||
|
@ -1598,6 +1598,34 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
task.driver.console.validate, task)
|
||||
|
||||
def test__get_ipmi_cmd(self):
|
||||
with task_manager.acquire(self.context,
|
||||
self.node.uuid) as task:
|
||||
driver_info = ipmi._parse_driver_info(task.node)
|
||||
ipmi_cmd = self.driver.console._get_ipmi_cmd(driver_info,
|
||||
'pw_file')
|
||||
expected_ipmi_cmd = ("/:%(uid)s:%(gid)s:HOME:ipmitool "
|
||||
"-H %(address)s -I lanplus -U %(user)s "
|
||||
"-f pw_file" %
|
||||
{'uid': os.getuid(), 'gid': os.getgid(),
|
||||
'address': driver_info['address'],
|
||||
'user': driver_info['username']})
|
||||
self.assertEqual(expected_ipmi_cmd, ipmi_cmd)
|
||||
|
||||
def test__get_ipmi_cmd_without_user(self):
|
||||
with task_manager.acquire(self.context,
|
||||
self.node.uuid) as task:
|
||||
driver_info = ipmi._parse_driver_info(task.node)
|
||||
driver_info['username'] = None
|
||||
ipmi_cmd = self.driver.console._get_ipmi_cmd(driver_info,
|
||||
'pw_file')
|
||||
expected_ipmi_cmd = ("/:%(uid)s:%(gid)s:HOME:ipmitool "
|
||||
"-H %(address)s -I lanplus "
|
||||
"-f pw_file" %
|
||||
{'uid': os.getuid(), 'gid': os.getgid(),
|
||||
'address': driver_info['address']})
|
||||
self.assertEqual(expected_ipmi_cmd, ipmi_cmd)
|
||||
|
||||
@mock.patch.object(ipmi.IPMIConsole, '_start_console', autospec=True)
|
||||
def test_start_console(self, mock_start):
|
||||
mock_start.return_value = None
|
||||
@ -1610,9 +1638,10 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
|
||||
self.driver.console, driver_info,
|
||||
console_utils.start_shellinabox_console)
|
||||
|
||||
@mock.patch.object(ipmi.IPMIConsole, '_get_ipmi_cmd', autospec=True)
|
||||
@mock.patch.object(console_utils, 'start_shellinabox_console',
|
||||
autospec=True)
|
||||
def test__start_console(self, mock_start):
|
||||
def test__start_console(self, mock_start, mock_ipmi_cmd):
|
||||
mock_start.return_value = None
|
||||
|
||||
with task_manager.acquire(self.context,
|
||||
@ -1624,6 +1653,8 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
|
||||
mock_start.assert_called_once_with(self.info['uuid'],
|
||||
self.info['port'],
|
||||
mock.ANY)
|
||||
mock_ipmi_cmd.assert_called_once_with(self.driver.console,
|
||||
driver_info, mock.ANY)
|
||||
|
||||
@mock.patch.object(console_utils, 'start_shellinabox_console',
|
||||
autospec=True)
|
||||
@ -2147,6 +2178,30 @@ class IPMIToolSocatDriverTestCase(IPMIToolDriverTestCase):
|
||||
def setUp(self):
|
||||
super(IPMIToolSocatDriverTestCase, self).setUp(terminal="socat")
|
||||
|
||||
def test__get_ipmi_cmd(self):
|
||||
with task_manager.acquire(self.context,
|
||||
self.node.uuid) as task:
|
||||
driver_info = ipmi._parse_driver_info(task.node)
|
||||
ipmi_cmd = self.driver.console._get_ipmi_cmd(driver_info,
|
||||
'pw_file')
|
||||
expected_ipmi_cmd = ("ipmitool -H %(address)s -I lanplus "
|
||||
"-U %(user)s -f pw_file" %
|
||||
{'address': driver_info['address'],
|
||||
'user': driver_info['username']})
|
||||
self.assertEqual(expected_ipmi_cmd, ipmi_cmd)
|
||||
|
||||
def test__get_ipmi_cmd_without_user(self):
|
||||
with task_manager.acquire(self.context,
|
||||
self.node.uuid) as task:
|
||||
driver_info = ipmi._parse_driver_info(task.node)
|
||||
driver_info['username'] = None
|
||||
ipmi_cmd = self.driver.console._get_ipmi_cmd(driver_info,
|
||||
'pw_file')
|
||||
expected_ipmi_cmd = ("ipmitool -H %(address)s -I lanplus "
|
||||
"-f pw_file" %
|
||||
{'address': driver_info['address']})
|
||||
self.assertEqual(expected_ipmi_cmd, ipmi_cmd)
|
||||
|
||||
@mock.patch.object(ipmi.IPMIConsole, '_start_console', autospec=True)
|
||||
@mock.patch.object(ipmi.IPMISocatConsole, '_exec_stop_console',
|
||||
autospec=True)
|
||||
@ -2163,9 +2218,10 @@ class IPMIToolSocatDriverTestCase(IPMIToolDriverTestCase):
|
||||
self.driver.console, driver_info,
|
||||
console_utils.start_socat_console)
|
||||
|
||||
@mock.patch.object(ipmi.IPMISocatConsole, '_get_ipmi_cmd', autospec=True)
|
||||
@mock.patch.object(console_utils, 'start_socat_console',
|
||||
autospec=True)
|
||||
def test__start_console(self, mock_start):
|
||||
def test__start_console(self, mock_start, mock_ipmi_cmd):
|
||||
mock_start.return_value = None
|
||||
|
||||
with task_manager.acquire(self.context,
|
||||
@ -2177,6 +2233,8 @@ class IPMIToolSocatDriverTestCase(IPMIToolDriverTestCase):
|
||||
mock_start.assert_called_once_with(self.info['uuid'],
|
||||
self.info['port'],
|
||||
mock.ANY)
|
||||
mock_ipmi_cmd.assert_called_once_with(self.driver.console,
|
||||
driver_info, mock.ANY)
|
||||
|
||||
@mock.patch.object(console_utils, 'start_socat_console',
|
||||
autospec=True)
|
||||
|
@ -0,0 +1,3 @@
|
||||
fixes:
|
||||
- Fixes a bug with incorrect base socat command,
|
||||
which prevented the usage of console.
|
Loading…
x
Reference in New Issue
Block a user