mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Suppress tracebacks in states which manage files
This captures exceptions encountered in states that run file.get_managed or file.manage_file, suppressing the traceback and instead returning a False result for the state, with a meaningful error message.
This commit is contained in:
parent
8034d126e2
commit
e6e0ce2735
@ -390,7 +390,9 @@ def file(name,
|
||||
env)
|
||||
|
||||
# Gather the source file from the server
|
||||
sfn, source_sum, comment = __salt__['file.get_managed'](cron_path,
|
||||
try:
|
||||
sfn, source_sum, comment = __salt__['file.get_managed'](
|
||||
cron_path,
|
||||
template,
|
||||
source,
|
||||
source_hash,
|
||||
@ -402,13 +404,21 @@ def file(name,
|
||||
defaults,
|
||||
**kwargs
|
||||
)
|
||||
except Exception as exc:
|
||||
ret['result'] = False
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'Unable to manage file: {0}'.format(exc)
|
||||
return ret
|
||||
|
||||
if comment:
|
||||
ret['comment'] = comment
|
||||
ret['result'] = False
|
||||
os.unlink(cron_path)
|
||||
return ret
|
||||
|
||||
ret = __salt__['file.manage_file'](cron_path,
|
||||
try:
|
||||
ret = __salt__['file.manage_file'](
|
||||
cron_path,
|
||||
sfn,
|
||||
ret,
|
||||
source,
|
||||
@ -417,7 +427,14 @@ def file(name,
|
||||
group,
|
||||
mode,
|
||||
env,
|
||||
backup)
|
||||
backup
|
||||
)
|
||||
except Exception as exc:
|
||||
ret['result'] = False
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'Unable to manage file: {0}'.format(exc)
|
||||
return ret
|
||||
|
||||
if ret['changes']:
|
||||
ret['changes'] = {'diff': ret['changes']['diff']}
|
||||
ret['comment'] = 'Crontab for user {0} was updated'.format(user)
|
||||
|
@ -1181,6 +1181,7 @@ def managed(name,
|
||||
)
|
||||
|
||||
# Gather the source file from the server
|
||||
try:
|
||||
sfn, source_sum, comment_ = __salt__['file.get_managed'](
|
||||
name,
|
||||
template,
|
||||
@ -1194,10 +1195,16 @@ def managed(name,
|
||||
defaults,
|
||||
**kwargs
|
||||
)
|
||||
except Exception as exc:
|
||||
ret['changes'] = {}
|
||||
return _error(ret, 'Unable to manage file: {0}'.format(exc))
|
||||
|
||||
if comment_ and contents is None:
|
||||
return _error(ret, comment_)
|
||||
else:
|
||||
return __salt__['file.manage_file'](name,
|
||||
try:
|
||||
return __salt__['file.manage_file'](
|
||||
name,
|
||||
sfn,
|
||||
ret,
|
||||
source,
|
||||
@ -1210,7 +1217,11 @@ def managed(name,
|
||||
template,
|
||||
show_diff,
|
||||
contents,
|
||||
dir_mode)
|
||||
dir_mode
|
||||
)
|
||||
except Exception as exc:
|
||||
ret['changes'] = {}
|
||||
return _error(ret, 'Unable to manage file: {0}'.format(exc))
|
||||
|
||||
|
||||
def directory(name,
|
||||
|
Loading…
Reference in New Issue
Block a user