Skip to content

Commit

Permalink
Fix issue saltstack#51008
Browse files Browse the repository at this point in the history
When calling cmd.run with cwd in combination
with runas the working directory was not set on macOS

This commit also adds a test to check the expected behaviour
  • Loading branch information
cdalvaro committed Dec 31, 2018
1 parent 4d2a7f7 commit 8bc79cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion salt/modules/cmdmod.py
Expand Up @@ -413,7 +413,7 @@ def _get_stripped(cmd):
if isinstance(cmd, (list, tuple)):
cmd = ' '.join(map(_cmd_quote, cmd))

cmd = 'su -l {0} -c "{1}"'.format(runas, cmd)
cmd = 'su -l {0} -c "cd {1}; {2}"'.format(runas, cwd, cmd)
# set runas to None, because if you try to run `su -l` as well as
# simulate the environment macOS will prompt for the password of the
# user and will cause salt to hang.
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/modules/test_cmdmod.py
Expand Up @@ -344,6 +344,18 @@ def test_run_cwd_doesnt_exist_issue_7154(self):
else:
raise RuntimeError

def test_run_cwd_in_combination_with_runas(self):
'''
cmd.run executes command in the cwd directory
when the runas parameter is specified
'''
cmd = 'pwd'
cwd = '/tmp'
runas = 'foobar'

stdout = cmdmod._run(cmd, cwd=cwd, runas=runas).get('stdout')
self.assertEqual(stdout, cwd)

def test_run_all_binary_replace(self):
'''
Test for failed decoding of binary data, for instance when doing
Expand Down

0 comments on commit 8bc79cf

Please sign in to comment.