Fix 'run_as_root' parameter check in utils
Because 'run_as_root' is boolean parameter we need check it value. Change-Id: I18876081f98bcafd89e42b1352c933d7ab87d7cc
This commit is contained in:
parent
f127c934ca
commit
a9ed3102f0
|
@ -61,7 +61,7 @@ def _get_root_helper():
|
|||
|
||||
def execute(*cmd, **kwargs):
|
||||
"""Convenience wrapper around oslo's execute() method."""
|
||||
if 'run_as_root' in kwargs and not 'root_helper' in kwargs:
|
||||
if kwargs.get('run_as_root') and not 'root_helper' in kwargs:
|
||||
kwargs['root_helper'] = _get_root_helper()
|
||||
result = processutils.execute(*cmd, **kwargs)
|
||||
LOG.debug(_('Execution completed, command line is "%s"'), ' '.join(cmd))
|
||||
|
@ -72,7 +72,7 @@ def execute(*cmd, **kwargs):
|
|||
|
||||
def trycmd(*args, **kwargs):
|
||||
"""Convenience wrapper around oslo's trycmd() method."""
|
||||
if 'run_as_root' in kwargs and not 'root_helper' in kwargs:
|
||||
if kwargs.get('run_as_root') and not 'root_helper' in kwargs:
|
||||
kwargs['root_helper'] = _get_root_helper()
|
||||
return processutils.trycmd(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -151,6 +151,18 @@ grep foo
|
|||
os.unlink(tmpfilename)
|
||||
os.unlink(tmpfilename2)
|
||||
|
||||
def test_execute_get_root_helper(self):
|
||||
with mock.patch.object(processutils, 'execute') as execute_mock:
|
||||
helper = utils._get_root_helper()
|
||||
utils.execute('foo', run_as_root=True)
|
||||
execute_mock.assert_called_once_with('foo', run_as_root=True,
|
||||
root_helper=helper)
|
||||
|
||||
def test_execute_without_root_helper(self):
|
||||
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)
|
||||
|
||||
|
||||
class GenericUtilsTestCase(base.TestCase):
|
||||
def test_hostname_unicode_sanitization(self):
|
||||
|
|
Loading…
Reference in New Issue