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): execute_mock):
utils.execute('foo', use_standard_locale=True) utils.execute('foo', use_standard_locale=True)
execute_mock.assert_called_once_with('foo', execute_mock.assert_called_once_with('foo',
env_variables={'LC_ALL': 'C'}, env_variables={'LC_ALL': 'C'})
run_as_root=False)
@mock.patch.object(processutils, 'execute') @mock.patch.object(processutils, 'execute')
def test_execute_use_standard_locale_with_env_variables(self, def test_execute_use_standard_locale_with_env_variables(self,
@ -156,16 +155,14 @@ grep foo
env_variables={'foo': 'bar'}) env_variables={'foo': 'bar'})
execute_mock.assert_called_once_with('foo', execute_mock.assert_called_once_with('foo',
env_variables={'LC_ALL': 'C', env_variables={'LC_ALL': 'C',
'foo': 'bar'}, 'foo': 'bar'})
run_as_root=False)
@mock.patch.object(processutils, 'execute') @mock.patch.object(processutils, 'execute')
def test_execute_not_use_standard_locale(self, execute_mock): def test_execute_not_use_standard_locale(self, execute_mock):
utils.execute('foo', use_standard_locale=False, utils.execute('foo', use_standard_locale=False,
env_variables={'foo': 'bar'}) env_variables={'foo': 'bar'})
execute_mock.assert_called_once_with('foo', execute_mock.assert_called_once_with('foo',
env_variables={'foo': 'bar'}, env_variables={'foo': 'bar'})
run_as_root=False)
def test_execute_without_root_helper(self): def test_execute_without_root_helper(self):
CONF.set_override('root_helper', None, group='ironic_lib') 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) execute_mock.assert_called_once_with('foo', run_as_root=False)
def test_execute_with_root_helper(self): 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: with mock.patch.object(processutils, 'execute') as execute_mock:
utils.execute('foo', run_as_root=True) utils.execute('foo', run_as_root=True)
execute_mock.assert_called_once_with('foo', run_as_root=True, execute_mock.assert_called_once_with(
root_helper='sudo') 'foo', run_as_root=True,
root_helper=CONF.ironic_lib.root_helper)
class MkfsTestCase(test_base.BaseTestCase): class MkfsTestCase(test_base.BaseTestCase):

View File

@ -32,7 +32,7 @@ from ironic_lib import exception
utils_opts = [ utils_opts = [
cfg.StrOpt('root_helper', 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 ' help='Command that is prefixed to commands that are run as '
'root. If not specified, no commands are run as root.'), 'root. If not specified, no commands are run as root.'),
] ]
@ -62,10 +62,12 @@ def execute(*cmd, **kwargs):
kwargs['env_variables'] = env kwargs['env_variables'] = env
# If root_helper config is not specified, no commands are run as root. # If root_helper config is not specified, no commands are run as root.
if not CONF.ironic_lib.root_helper: run_as_root = kwargs.get('run_as_root', False)
kwargs['run_as_root'] = False if run_as_root:
else: if not CONF.ironic_lib.root_helper:
kwargs['root_helper'] = CONF.ironic_lib.root_helper kwargs['run_as_root'] = False
else:
kwargs['root_helper'] = CONF.ironic_lib.root_helper
result = processutils.execute(*cmd, **kwargs) result = processutils.execute(*cmd, **kwargs)
LOG.debug('Execution completed, command line is "%s"', LOG.debug('Execution completed, command line is "%s"',