Merge "processutils: execute(): fix option incompatibility"

This commit is contained in:
Jenkins 2015-02-17 18:38:41 +00:00 committed by Gerrit Code Review
commit 2f510962ab
2 changed files with 18 additions and 1 deletions

View File

@ -182,7 +182,12 @@ def execute(*cmd, **kwargs):
raise NoRootWrapSpecified(
message=_('Command requested root, but did not '
'specify a root helper.'))
cmd = shlex.split(root_helper) + list(cmd)
if shell:
# root helper has to be injected into the command string
cmd = [' '.join((root_helper, cmd[0]))] + list(cmd[1:])
else:
# root helper has to be tokenized into argument list
cmd = shlex.split(root_helper) + list(cmd)
cmd = [str(c) for c in cmd]
sanitized_cmd = strutils.mask_password(' '.join(cmd))

View File

@ -298,6 +298,18 @@ grep foo
self.assertIn(b'SUPER_UNIQUE_VAR=The answer is 42', out)
def test_as_root(self):
out, err = processutils.execute('a', 'b', 'c', run_as_root=True,
root_helper='echo')
self.assertIn('a b c', six.text_type(out))
def test_as_root_via_shell(self):
out, err = processutils.execute('a b c', run_as_root=True,
root_helper='echo', shell=True)
self.assertIn('a b c', six.text_type(out))
def test_exception_and_masking(self):
tmpfilename = self.create_tempfiles(
[["test_exceptions_and_masking",