Merge pull request #6235 from terminalmage/issue6230

Report on cache failures for cmd.script states
This commit is contained in:
Thomas S Hatch 2013-07-19 11:35:15 -07:00
commit 200de9c726
2 changed files with 18 additions and 2 deletions

View File

@ -694,11 +694,23 @@ def script(
path = salt.utils.mkstemp(dir=cwd)
else:
path = __salt__['cp.cache_file'](source, env)
if not path:
return {'pid': 0,
'retcode': 1,
'stdout': '',
'stderr': '',
'cache_error': True}
if template:
__salt__['cp.get_template'](source, path, template, env, **kwargs)
else:
if not salt.utils.is_windows():
fn_ = __salt__['cp.cache_file'](source, env)
if not fn_:
return {'pid': 0,
'retcode': 1,
'stdout': '',
'stderr': '',
'cache_error': True}
shutil.copyfile(fn_, path)
if not salt.utils.is_windows():
os.chmod(path, 320)

View File

@ -641,7 +641,7 @@ def script(name,
# Wow, we passed the test, run this sucker!
try:
cmd_all = __salt__['cmd.script'](source, **cmd_kwargs)
except CommandExecutionError as err:
except (CommandExecutionError, IOError) as err:
ret['comment'] = str(err)
return ret
@ -650,6 +650,10 @@ def script(name,
ret['result'] = not bool(cmd_all)
else:
ret['result'] = not bool(cmd_all['retcode'])
if ret.get('changes', {}).get('cache_error'):
ret['comment'] = 'Unable to cache script {0} from env ' \
'\'{1}\''.format(source, env)
else:
ret['comment'] = 'Command "{0}" run'.format(name)
return _reinterpreted_state(ret) if stateful else ret