Improve detection of multipathd running
There is a case where `multipathd show status` should fail, yet it doesn't exit with an error code. Instead it returns 0. Error is printed to stdout as "error receiving packet". This means that enforce will not work as expected. The multipathd error got fixed here: https://www.redhat.com/archives/dm-devel/2015-March/msg00136.html But that patch is missing in some packages, so this patch adds a workaround to detect the error base on the stdout of the multipathd show status command. Closes-Bug: #1789699 Change-Id: I1cb29782541e3fe53b0b1744ab36f56464cd2135
This commit is contained in:
parent
716ca5e5f1
commit
028af871de
|
@ -157,8 +157,13 @@ class LinuxSCSI(executor.Executor):
|
||||||
try:
|
try:
|
||||||
if execute is None:
|
if execute is None:
|
||||||
execute = priv_rootwrap.execute
|
execute = priv_rootwrap.execute
|
||||||
execute('multipathd', 'show', 'status',
|
cmd = ('multipathd', 'show', 'status')
|
||||||
run_as_root=True, root_helper=root_helper)
|
out, _err = execute(*cmd, run_as_root=True,
|
||||||
|
root_helper=root_helper)
|
||||||
|
# There was a bug in multipathd where it didn't return an error
|
||||||
|
# code and just printed the error message in stdout.
|
||||||
|
if out and out.startswith('error receiving packet'):
|
||||||
|
raise putils.ProcessExecutionError('', out, 1, cmd, None)
|
||||||
except putils.ProcessExecutionError as err:
|
except putils.ProcessExecutionError as err:
|
||||||
LOG.error('multipathd is not running: exit code %(err)s',
|
LOG.error('multipathd is not running: exit code %(err)s',
|
||||||
{'err': err.exit_code})
|
{'err': err.exit_code})
|
||||||
|
|
|
@ -89,7 +89,7 @@ class ConnectorUtilsTestCase(test_base.TestCase):
|
||||||
def test_brick_get_connector_properties(self):
|
def test_brick_get_connector_properties(self):
|
||||||
self._test_brick_get_connector_properties(False, False, False)
|
self._test_brick_get_connector_properties(False, False, False)
|
||||||
|
|
||||||
@mock.patch.object(priv_rootwrap, 'execute')
|
@mock.patch.object(priv_rootwrap, 'execute', return_value=('', ''))
|
||||||
def test_brick_get_connector_properties_multipath(self, mock_execute):
|
def test_brick_get_connector_properties_multipath(self, mock_execute):
|
||||||
self._test_brick_get_connector_properties(True, True, True)
|
self._test_brick_get_connector_properties(True, True, True)
|
||||||
mock_execute.assert_called_once_with('multipathd', 'show', 'status',
|
mock_execute.assert_called_once_with('multipathd', 'show', 'status',
|
||||||
|
@ -149,7 +149,7 @@ class ConnectorTestCase(test_base.TestCase):
|
||||||
|
|
||||||
def test_get_connector_properties(self):
|
def test_get_connector_properties(self):
|
||||||
with mock.patch.object(priv_rootwrap, 'execute') as mock_exec:
|
with mock.patch.object(priv_rootwrap, 'execute') as mock_exec:
|
||||||
mock_exec.return_value = True
|
mock_exec.return_value = ('', '')
|
||||||
multipath = True
|
multipath = True
|
||||||
enforce_multipath = True
|
enforce_multipath = True
|
||||||
props = base.BaseLinuxConnector.get_connector_properties(
|
props = base.BaseLinuxConnector.get_connector_properties(
|
||||||
|
|
|
@ -19,6 +19,7 @@ import time
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
import mock
|
import mock
|
||||||
|
from oslo_concurrency import processutils as putils
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from os_brick import exception
|
from os_brick import exception
|
||||||
|
@ -829,12 +830,20 @@ loop0 0"""
|
||||||
expected = 13
|
expected = 13
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
@mock.patch('os_brick.privileged.rootwrap')
|
@mock.patch('os_brick.privileged.rootwrap.execute', return_value=('', ''))
|
||||||
def test_is_multipath_running_default_executor(self, mock_rootwrap):
|
def test_is_multipath_running_default_executor(self, mock_exec):
|
||||||
self.assertTrue(
|
res = linuxscsi.LinuxSCSI.is_multipath_running(False, None, mock_exec)
|
||||||
linuxscsi.LinuxSCSI.is_multipath_running(
|
self.assertTrue(res)
|
||||||
False, None, mock_rootwrap.execute))
|
mock_exec.assert_called_once_with(
|
||||||
mock_rootwrap.execute.assert_called_once_with(
|
'multipathd', 'show', 'status', run_as_root=True, root_helper=None)
|
||||||
|
|
||||||
|
@mock.patch('os_brick.privileged.rootwrap.execute')
|
||||||
|
def test_is_multipath_running_failure_exit_code_0(self, mock_exec):
|
||||||
|
mock_exec.return_value = ('error receiving packet', '')
|
||||||
|
self.assertRaises(putils.ProcessExecutionError,
|
||||||
|
linuxscsi.LinuxSCSI.is_multipath_running,
|
||||||
|
True, None, mock_exec)
|
||||||
|
mock_exec.assert_called_once_with(
|
||||||
'multipathd', 'show', 'status', run_as_root=True, root_helper=None)
|
'multipathd', 'show', 'status', run_as_root=True, root_helper=None)
|
||||||
|
|
||||||
@mock.patch('glob.glob')
|
@mock.patch('glob.glob')
|
||||||
|
|
Loading…
Reference in New Issue