diff options
-rw-r--r-- | oslo_concurrency/processutils.py | 4 | ||||
-rw-r--r-- | oslo_concurrency/tests/unit/test_processutils.py | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/oslo_concurrency/processutils.py b/oslo_concurrency/processutils.py index 78d99c4..a981dc9 100644 --- a/oslo_concurrency/processutils.py +++ b/oslo_concurrency/processutils.py @@ -103,6 +103,8 @@ def execute(*cmd, **kwargs): :param cmd: Passed to subprocess.Popen. :type cmd: string + :param cwd: Set the current working directory + :type cwd: string :param process_input: Send to opened process. :type process_input: string :param env_variables: Environment variables and their values that @@ -149,6 +151,7 @@ def execute(*cmd, **kwargs): :raises: :class:`OSError` """ + cwd = kwargs.pop('cwd', None) process_input = kwargs.pop('process_input', None) env_variables = kwargs.pop('env_variables', None) check_exit_code = kwargs.pop('check_exit_code', [0]) @@ -205,6 +208,7 @@ def execute(*cmd, **kwargs): close_fds=close_fds, preexec_fn=preexec_fn, shell=shell, + cwd=cwd, env=env_variables) result = obj.communicate(process_input) diff --git a/oslo_concurrency/tests/unit/test_processutils.py b/oslo_concurrency/tests/unit/test_processutils.py index 50ea611..8d723c7 100644 --- a/oslo_concurrency/tests/unit/test_processutils.py +++ b/oslo_concurrency/tests/unit/test_processutils.py @@ -168,6 +168,13 @@ exit 1 processutils.execute, '/usr/bin/env', 'false', check_exit_code=True) + def test_check_cwd(self): + tmpdir = tempfile.mkdtemp() + out, err = processutils.execute('/usr/bin/env', + 'sh', '-c', 'pwd', + cwd=tmpdir) + self.assertIn(six.b(tmpdir), out) + def test_check_exit_code_list(self): processutils.execute('/usr/bin/env', 'sh', '-c', 'exit 101', check_exit_code=(101, 102)) |