Merge #32293 with test fixes (#32418)

* Fix issue #11497

* Remove check for working directory presence in tests
This commit is contained in:
Nicole Thomas 2016-04-07 14:55:25 -06:00 committed by Mike Place
parent bbd8260a42
commit 0809126d8e
2 changed files with 30 additions and 39 deletions

View file

@ -675,13 +675,6 @@ def run(name,
'result': False,
'comment': ''}
if cwd and not os.path.isdir(cwd):
ret['comment'] = (
'Desired working directory "{0}" '
'is not available'
).format(cwd)
return ret
# Need the check for None here, if env is not provided then it falls back
# to None and it is assumed that the environment is not being overridden.
if env is not None and not isinstance(env, (list, dict)):
@ -707,22 +700,30 @@ def run(name,
ret.update(cret)
return ret
# Wow, we passed the test, run this sucker!
if not __opts__['test']:
try:
cmd_all = __salt__['cmd.run_all'](
name, timeout=timeout, python_shell=True, **cmd_kwargs
)
except CommandExecutionError as err:
ret['comment'] = str(err)
return ret
ret['changes'] = cmd_all
ret['result'] = not bool(cmd_all['retcode'])
ret['comment'] = 'Command "{0}" run'.format(name)
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Command "{0}" would have been executed'.format(name)
return _reinterpreted_state(ret) if stateful else ret
ret['result'] = None
ret['comment'] = 'Command "{0}" would have been executed'.format(name)
if cwd and not os.path.isdir(cwd):
ret['comment'] = (
'Desired working directory "{0}" '
'is not available'
).format(cwd)
return ret
# Wow, we passed the test, run this sucker!
try:
cmd_all = __salt__['cmd.run_all'](
name, timeout=timeout, python_shell=True, **cmd_kwargs
)
except CommandExecutionError as err:
ret['comment'] = str(err)
return ret
ret['changes'] = cmd_all
ret['result'] = not bool(cmd_all['retcode'])
ret['comment'] = 'Command "{0}" run'.format(name)
return _reinterpreted_state(ret) if stateful else ret
finally:
@ -843,13 +844,6 @@ def script(name,
'result': False,
'comment': ''}
if cwd and not os.path.isdir(cwd):
ret['comment'] = (
'Desired working directory "{0}" '
'is not available'
).format(cwd)
return ret
# Need the check for None here, if env is not provided then it falls back
# to None and it is assumed that the environment is not being overridden.
if env is not None and not isinstance(env, (list, dict)):
@ -904,6 +898,13 @@ def script(name,
'executed'.format(name)
return _reinterpreted_state(ret) if stateful else ret
if cwd and not os.path.isdir(cwd):
ret['comment'] = (
'Desired working directory "{0}" '
'is not available'
).format(cwd)
return ret
# Wow, we passed the test, run this sucker!
try:
cmd_all = __salt__['cmd.script'](source, python_shell=True, **cmd_kwargs)

View file

@ -131,11 +131,6 @@ class CmdTestCase(TestCase):
'changes': {},
'comment': ''}
with patch.object(os.path, 'isdir', MagicMock(return_value=False)):
comt = ('Desired working directory "/tmp/salt" is not available')
ret.update({'comment': comt})
self.assertDictEqual(cmd.run(name, cwd='/tmp/salt'), ret)
comt = ("Invalidly-formatted 'env' parameter. See documentation.")
ret.update({'comment': comt})
self.assertDictEqual(cmd.run(name, env='salt'), ret)
@ -177,11 +172,6 @@ class CmdTestCase(TestCase):
'changes': {},
'comment': ''}
with patch.object(os.path, 'isdir', MagicMock(return_value=False)):
comt = ('Desired working directory "/tmp/salt" is not available')
ret.update({'comment': comt})
self.assertDictEqual(cmd.script(name, cwd='/tmp/salt'), ret)
comt = ("Invalidly-formatted 'env' parameter. See documentation.")
ret.update({'comment': comt})
self.assertDictEqual(cmd.script(name, env='salt'), ret)