mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Fix file.managed traceback when source is a list
If file.managed state has a source param which is a list, and none of the URIs in that list are found, a traceback occurs. This commit modifies salt.modules.file.source_list to raise an exception when source is a list and no matches are found, and then catches that exception in the file.managed state so that Salt can return gracefully with a False result and meaningful error message.
This commit is contained in:
parent
8a5b4ae780
commit
fa7e9fc6b3
@ -1967,6 +1967,7 @@ def source_list(source, source_hash, saltenv):
|
||||
mdirs += ['{0}?saltenv={1}'.format(d, senv)
|
||||
for d in __salt__['cp.list_master_dirs'](senv)]
|
||||
|
||||
ret = None
|
||||
for single in source:
|
||||
if isinstance(single, dict):
|
||||
# check the proto, if it is http or ftp then download the file
|
||||
@ -1985,14 +1986,21 @@ def source_list(source, source_hash, saltenv):
|
||||
fn_ = __salt__['cp.get_url'](single_src, dest)
|
||||
os.remove(fn_)
|
||||
if fn_:
|
||||
source = single_src
|
||||
source_hash = single_hash
|
||||
ret = (single_src, single_hash)
|
||||
break
|
||||
elif isinstance(single, salt._compat.string_types):
|
||||
if single[7:] in mfiles or single[7:] in mdirs:
|
||||
source = single
|
||||
ret = (single, source_hash)
|
||||
break
|
||||
return source, source_hash
|
||||
if ret is None:
|
||||
# None of the list items matched
|
||||
raise CommandExecutionError(
|
||||
'none of the specified sources were found'
|
||||
)
|
||||
else:
|
||||
return ret
|
||||
else:
|
||||
return source, source_hash
|
||||
|
||||
|
||||
def get_managed(
|
||||
@ -2016,8 +2024,7 @@ def get_managed(
|
||||
|
||||
salt '*' file.get_managed /etc/httpd/conf.d/httpd.conf jinja salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root root '755' base None None
|
||||
'''
|
||||
# If the file is a template and the contents is managed
|
||||
# then make sure to copy it down and templatize things.
|
||||
# Copy the file to the minion and templatize it
|
||||
sfn = ''
|
||||
source_sum = {}
|
||||
if template and source:
|
||||
|
@ -1186,31 +1186,36 @@ def managed(name,
|
||||
context = {}
|
||||
context['accumulator'] = _ACCUMULATORS[name]
|
||||
|
||||
if __opts__['test']:
|
||||
ret['result'], ret['comment'] = __salt__['file.check_managed'](
|
||||
name,
|
||||
try:
|
||||
if __opts__['test']:
|
||||
ret['result'], ret['comment'] = __salt__['file.check_managed'](
|
||||
name,
|
||||
source,
|
||||
source_hash,
|
||||
user,
|
||||
group,
|
||||
mode,
|
||||
template,
|
||||
makedirs,
|
||||
context,
|
||||
defaults,
|
||||
__env__,
|
||||
contents,
|
||||
**kwargs
|
||||
)
|
||||
return ret
|
||||
|
||||
# If the source is a list then find which file exists
|
||||
source, source_hash = __salt__['file.source_list'](
|
||||
source,
|
||||
source_hash,
|
||||
user,
|
||||
group,
|
||||
mode,
|
||||
template,
|
||||
makedirs,
|
||||
context,
|
||||
defaults,
|
||||
__env__,
|
||||
contents,
|
||||
**kwargs
|
||||
__env__
|
||||
)
|
||||
except CommandExecutionError as exc:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Unable to manage file: {0}'.format(exc)
|
||||
return ret
|
||||
|
||||
# If the source is a list then find which file exists
|
||||
source, source_hash = __salt__['file.source_list'](
|
||||
source,
|
||||
source_hash,
|
||||
__env__
|
||||
)
|
||||
|
||||
# Gather the source file from the server
|
||||
try:
|
||||
sfn, source_sum, comment_ = __salt__['file.get_managed'](
|
||||
|
Loading…
Reference in New Issue
Block a user