Merge pull request #7164 from dlanderson/fix_issue_7154

Fix #7154 - cmd.* should fail when cwd does not exist
This commit is contained in:
Thomas S Hatch 2013-09-10 21:11:30 -07:00
commit e644de7e76
2 changed files with 21 additions and 0 deletions

View File

@ -215,6 +215,11 @@ def _run(cmd,
# munge the cmd and cwd through the template
(cmd, cwd) = _render_cmd(cmd, cwd, template)
if not os.path.isdir(cwd):
# cwd is not a directory - fatal error
msg = 'Working directory {0!r} does not exist'
raise CommandExecutionError(msg.format(cwd))
ret = {}
if not env:

View File

@ -200,6 +200,22 @@ sys.stdout.write('cheese')
'hello' == self.run_function(
'cmd.run', ['sleep 1 && echo hello', 'timeout=2']))
def test_run_cwd_doesnt_exist_issue_7154(self):
'''
cmd.run should fail and raise
salt.exceptions.CommandExecutionError if the cwd dir does not
exist
'''
from salt.exceptions import CommandExecutionError
import salt.modules.cmdmod as cmdmod
cmd = 'echo OHAI'
cwd = '/path/to/nowhere'
try:
cmdmod.run_all(cmd, cwd=cwd)
except CommandExecutionError:
pass
else:
raise RuntimeError
if __name__ == '__main__':
from integration import run_tests