Default for root_helper config
This sets the default for root_helper config to the value used by ironic: 'sudo ironic-rootwrap /etc/ironic/rootwrap.conf'. The logic was changed a bit so as not to pass root_helper or run_as_root arguments to processutils.execute() unless they had been specified or needed to be passed. Change-Id: I8cf8c07102d0a8bd4fff14afc8c2f9db6beeb949 Fixes-Bug: #1519870
This commit is contained in:
parent
bf8f27bc21
commit
97ce4a6eff
ironic_lib
@ -146,8 +146,7 @@ grep foo
|
||||
execute_mock):
|
||||
utils.execute('foo', use_standard_locale=True)
|
||||
execute_mock.assert_called_once_with('foo',
|
||||
env_variables={'LC_ALL': 'C'},
|
||||
run_as_root=False)
|
||||
env_variables={'LC_ALL': 'C'})
|
||||
|
||||
@mock.patch.object(processutils, 'execute')
|
||||
def test_execute_use_standard_locale_with_env_variables(self,
|
||||
@ -156,16 +155,14 @@ grep foo
|
||||
env_variables={'foo': 'bar'})
|
||||
execute_mock.assert_called_once_with('foo',
|
||||
env_variables={'LC_ALL': 'C',
|
||||
'foo': 'bar'},
|
||||
run_as_root=False)
|
||||
'foo': 'bar'})
|
||||
|
||||
@mock.patch.object(processutils, 'execute')
|
||||
def test_execute_not_use_standard_locale(self, execute_mock):
|
||||
utils.execute('foo', use_standard_locale=False,
|
||||
env_variables={'foo': 'bar'})
|
||||
execute_mock.assert_called_once_with('foo',
|
||||
env_variables={'foo': 'bar'},
|
||||
run_as_root=False)
|
||||
env_variables={'foo': 'bar'})
|
||||
|
||||
def test_execute_without_root_helper(self):
|
||||
CONF.set_override('root_helper', None, group='ironic_lib')
|
||||
@ -180,11 +177,16 @@ grep foo
|
||||
execute_mock.assert_called_once_with('foo', run_as_root=False)
|
||||
|
||||
def test_execute_with_root_helper(self):
|
||||
CONF.set_override('root_helper', 'sudo', group='ironic_lib')
|
||||
with mock.patch.object(processutils, 'execute') as execute_mock:
|
||||
utils.execute('foo', run_as_root=False)
|
||||
execute_mock.assert_called_once_with('foo', run_as_root=False)
|
||||
|
||||
def test_execute_with_root_helper_run_as_root(self):
|
||||
with mock.patch.object(processutils, 'execute') as execute_mock:
|
||||
utils.execute('foo', run_as_root=True)
|
||||
execute_mock.assert_called_once_with('foo', run_as_root=True,
|
||||
root_helper='sudo')
|
||||
execute_mock.assert_called_once_with(
|
||||
'foo', run_as_root=True,
|
||||
root_helper=CONF.ironic_lib.root_helper)
|
||||
|
||||
|
||||
class MkfsTestCase(test_base.BaseTestCase):
|
||||
|
@ -32,7 +32,7 @@ from ironic_lib import exception
|
||||
|
||||
utils_opts = [
|
||||
cfg.StrOpt('root_helper',
|
||||
default=None,
|
||||
default='sudo ironic-rootwrap /etc/ironic/rootwrap.conf',
|
||||
help='Command that is prefixed to commands that are run as '
|
||||
'root. If not specified, no commands are run as root.'),
|
||||
]
|
||||
@ -62,10 +62,12 @@ def execute(*cmd, **kwargs):
|
||||
kwargs['env_variables'] = env
|
||||
|
||||
# If root_helper config is not specified, no commands are run as root.
|
||||
if not CONF.ironic_lib.root_helper:
|
||||
kwargs['run_as_root'] = False
|
||||
else:
|
||||
kwargs['root_helper'] = CONF.ironic_lib.root_helper
|
||||
run_as_root = kwargs.get('run_as_root', False)
|
||||
if run_as_root:
|
||||
if not CONF.ironic_lib.root_helper:
|
||||
kwargs['run_as_root'] = False
|
||||
else:
|
||||
kwargs['root_helper'] = CONF.ironic_lib.root_helper
|
||||
|
||||
result = processutils.execute(*cmd, **kwargs)
|
||||
LOG.debug('Execution completed, command line is "%s"',
|
||||
|
Loading…
x
Reference in New Issue
Block a user