Merge "Default for root_helper config"

This commit is contained in:
Jenkins 2015-11-25 19:28:23 +00:00 committed by Gerrit Code Review
commit e816b12a7b
2 changed files with 18 additions and 14 deletions

View File

@ -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):

View File

@ -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"',