diff --git a/os_brick/executor.py b/os_brick/executor.py index 17701a403..3d2de9693 100644 --- a/os_brick/executor.py +++ b/os_brick/executor.py @@ -18,20 +18,13 @@ and root_helper settings, so this provides that hook. """ -from oslo_concurrency import processutils as putils - from os_brick.privileged import rootwrap as priv_rootwrap class Executor(object): def __init__(self, root_helper, execute=None, *args, **kwargs): - # For backwards compatibility, `putils.execute` is interpreted - # as a sentinel to mean "I want the os-brick default" :-/ - # This can be burnt as soon as we update all the callsites (in - # nova+cinder) to the new default - and then we shall never - # speak of it again. - if execute is None or execute is putils.execute: + if execute is None: execute = priv_rootwrap.execute self.set_execute(execute) self.set_root_helper(root_helper) diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py index 084dfa556..89be5f2ef 100644 --- a/os_brick/initiator/connector.py +++ b/os_brick/initiator/connector.py @@ -108,7 +108,7 @@ connector_list = [ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath, - host=None): + host=None, execute=None): """Get the connection properties for all protocols. When the connector wants to use multipath, multipath=True should be @@ -129,6 +129,8 @@ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath, running? If the daemon isn't running then the return dict will have multipath as False. :type enforce_multipath: bool + :param host: hostname. + :param execute: execute helper. :returns: dict containing all of the collected initiator values. """ props = {} @@ -148,7 +150,8 @@ def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath, root_helper, host=host, multipath=multipath, - enforce_multipath=enforce_multipath)) + enforce_multipath=enforce_multipath, + execute=execute)) return props @@ -445,7 +448,8 @@ class BaseLinuxConnector(InitiatorConnector): props['multipath'] = (multipath and linuxscsi.LinuxSCSI.is_multipath_running( - enforce_multipath, root_helper)) + enforce_multipath, root_helper, + execute=kwargs.get('execute'))) return props @@ -566,7 +570,8 @@ class ISCSIConnector(BaseLinuxConnector): def get_connector_properties(root_helper, *args, **kwargs): """The iSCSI connector properties.""" props = {} - iscsi = ISCSIConnector(root_helper=root_helper) + iscsi = ISCSIConnector(root_helper=root_helper, + execute=kwargs.get('execute')) initiator = iscsi.get_initiator() if initiator: props['initiator'] = initiator @@ -1380,7 +1385,8 @@ class FibreChannelConnector(BaseLinuxConnector): def get_connector_properties(root_helper, *args, **kwargs): """The Fibre Channel connector properties.""" props = {} - fc = linuxfc.LinuxFibreChannel(root_helper) + fc = linuxfc.LinuxFibreChannel(root_helper, + execute=kwargs.get('execute')) wwpns = fc.get_fc_wwpns() if wwpns: diff --git a/os_brick/initiator/linuxscsi.py b/os_brick/initiator/linuxscsi.py index 9feb0943b..055a67fc1 100644 --- a/os_brick/initiator/linuxscsi.py +++ b/os_brick/initiator/linuxscsi.py @@ -113,11 +113,12 @@ class LinuxSCSI(executor.Executor): return out.strip() @staticmethod - def is_multipath_running(enforce_multipath, root_helper): + def is_multipath_running(enforce_multipath, root_helper, execute=None): try: - priv_rootwrap.execute('multipathd', 'show', 'status', - run_as_root=True, - root_helper=root_helper) + if execute is None: + execute = priv_rootwrap.execute + execute('multipathd', 'show', 'status', + run_as_root=True, root_helper=root_helper) except putils.ProcessExecutionError as err: LOG.error(_LE('multipathd is not running: exit code %(err)s'), {'err': err.exit_code}) diff --git a/os_brick/tests/initiator/test_linuxscsi.py b/os_brick/tests/initiator/test_linuxscsi.py index e1c4e2b01..0b45e18b0 100644 --- a/os_brick/tests/initiator/test_linuxscsi.py +++ b/os_brick/tests/initiator/test_linuxscsi.py @@ -657,3 +657,11 @@ loop0 0""" result = self.linuxscsi.process_lun_id(lun_id) expected = 13 self.assertEqual(expected, result) + + @mock.patch('os_brick.privileged.rootwrap') + def test_is_multipath_running_default_executor(self, mock_rootwrap): + self.assertTrue( + linuxscsi.LinuxSCSI.is_multipath_running( + False, None, mock_rootwrap.execute)) + mock_rootwrap.execute.assert_called_once_with( + 'multipathd', 'show', 'status', run_as_root=True, root_helper=None) diff --git a/os_brick/tests/test_executor.py b/os_brick/tests/test_executor.py new file mode 100644 index 000000000..e16be57f7 --- /dev/null +++ b/os_brick/tests/test_executor.py @@ -0,0 +1,37 @@ +# (c) Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# import time + +import mock + +from os_brick import executor as brick_executor +from os_brick.privileged import rootwrap +from os_brick.tests import base + + +class TestExecutor(base.TestCase): + def test_default_execute(self): + executor = brick_executor.Executor(root_helper=None) + self.assertEqual(rootwrap.execute, executor._execute) + + def test_none_execute(self): + executor = brick_executor.Executor(root_helper=None, execute=None) + self.assertEqual(rootwrap.execute, executor._execute) + + def test_fake_execute(self): + mock_execute = mock.Mock() + executor = brick_executor.Executor(root_helper=None, + execute=mock_execute) + self.assertEqual(mock_execute, executor._execute)