Skip to content

Commit

Permalink
Bring up ext_pillar rendering errors as well
Browse files Browse the repository at this point in the history
  • Loading branch information
kiorky committed Feb 20, 2016
1 parent 174ee10 commit e3e97a4
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions salt/pillar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,14 @@ def render_pstate(self, sls, saltenv, mods, defaults=None):
errors += err
return state, mods, errors

def render_pillar(self, matches):
def render_pillar(self, matches, errors=None):
'''
Extract the sls pillar files from the matches and render them into the
pillar
'''
pillar = copy.copy(self.pillar_override)
errors = []
if errors is None:
errors = []
for saltenv, pstates in six.iteritems(matches):
mods = set()
for sls in pstates:
Expand Down Expand Up @@ -708,22 +709,26 @@ def _external_pillar_data(self, pillar, val, pillar_dirs, key):
val)
return ext

def ext_pillar(self, pillar, pillar_dirs):
def ext_pillar(self, pillar, pillar_dirs, errors=None):
'''
Render the external pillar data
'''
if errors is None:
errors = []
if 'ext_pillar' not in self.opts:
return pillar
return pillar, errors
if not isinstance(self.opts['ext_pillar'], list):
log.critical('The "ext_pillar" option is malformed')
return pillar
errors.append('The "ext_pillar" option is malformed')
log.critical(errors[-1])
return pillar, errors
ext = None
# Bring in CLI pillar data
pillar.update(self.pillar_override)
for run in self.opts['ext_pillar']:
if not isinstance(run, dict):
log.critical('The "ext_pillar" option is malformed')
return {}
errors.append('The "ext_pillar" option is malformed')
log.critical(errors[-1])
return {}, errors
for key, val in six.iteritems(run):
if key not in self.ext_pillars:
err = ('Specified ext_pillar interface {0} is '
Expand All @@ -749,12 +754,8 @@ def ext_pillar(self, pillar, pillar_dirs):
pillar_dirs,
key)
except Exception as exc:
log.exception(
'Failed to load ext_pillar {0}: {1}'.format(
key,
exc
)
)
errors.append('Failed to load ext_pillar {0}: {1}'.format(
key, exc))
if ext:
pillar = merge(
pillar,
Expand All @@ -763,7 +764,7 @@ def ext_pillar(self, pillar, pillar_dirs):
self.opts.get('renderer', 'yaml'),
self.opts.get('pillar_merge_lists', False))
ext = None
return pillar
return pillar, errors

def compile_pillar(self, ext=True, pillar_dirs=None):
'''
Expand All @@ -772,9 +773,9 @@ def compile_pillar(self, ext=True, pillar_dirs=None):
top, top_errors = self.get_top()
if ext:
if self.opts.get('ext_pillar_first', False):
self.opts['pillar'] = self.ext_pillar({}, pillar_dirs)
self.opts['pillar'], errors = self.ext_pillar({}, pillar_dirs)
matches = self.top_matches(top)
pillar, errors = self.render_pillar(matches)
pillar, errors = self.render_pillar(matches, errors=errors)
pillar = merge(pillar,
self.opts['pillar'],
self.merge_strategy,
Expand All @@ -783,7 +784,8 @@ def compile_pillar(self, ext=True, pillar_dirs=None):
else:
matches = self.top_matches(top)
pillar, errors = self.render_pillar(matches)
pillar = self.ext_pillar(pillar, pillar_dirs)
pillar, errors = self.ext_pillar(
pillar, pillar_dirs, errors=errors)
else:
matches = self.top_matches(top)
pillar, errors = self.render_pillar(matches)
Expand Down

0 comments on commit e3e97a4

Please sign in to comment.