diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-02-17 18:38:41 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-02-17 18:38:41 +0000 |
commit | 2f510962abb88a688975065c05297fb6d3f6890c (patch) | |
tree | 83f26334332c0391fc2f14b77785087f8726f090 | |
parent | cf64a1d7b8d9fd46e7d7b8bcf16fc1d0cf978157 (diff) | |
parent | c20a86d550c22a8d4bf7b4f413d14d96eccb43ef (diff) | |
download | oslo-concurrency-2f510962abb88a688975065c05297fb6d3f6890c.tar.gz |
Merge "processutils: execute(): fix option incompatibility"
-rw-r--r-- | oslo_concurrency/processutils.py | 7 | ||||
-rw-r--r-- | tests/test_processutils.py | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/oslo_concurrency/processutils.py b/oslo_concurrency/processutils.py index a981dc9..ba61cba 100644 --- a/oslo_concurrency/processutils.py +++ b/oslo_concurrency/processutils.py @@ -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)) diff --git a/tests/test_processutils.py b/tests/test_processutils.py index 179a5e3..b86e962 100644 --- a/tests/test_processutils.py +++ b/tests/test_processutils.py @@ -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", |