Keep old opts "behavior" and be explicit on which options dict is used

This commit is contained in:
Pedro Algarvio 2016-01-21 14:29:37 +00:00
parent 7ffb4e5dad
commit b06aa1e335

View File

@ -176,40 +176,46 @@ class Pillar(object):
'''
Read over the pillar top files and render the pillar data
'''
def __init__(self, opts, grains, minion_id, saltenv, ext=None, functions=None,
pillar=None, pillarenv=None):
def __init__(self, opts, grains, minion_id, saltenv, ext=None,
functions=None, pillar=None, pillarenv=None):
# Keep a copy of the incoming master opts. Any changes made to it won't change
# the passed dictionary, they are local to this class
self.master_opts = copy.deepcopy(opts)
self.minion_id = minion_id
# Store the file_roots path so we can restore later. Issue 5449
self.actual_file_roots = opts['file_roots']
# use the local file client
self.opts = self.__gen_opts(opts, grains, saltenv=saltenv, ext=ext, pillarenv=pillarenv)
minion_opts = copy.deepcopy(self.opts)
minion_opts['id'] = minion_id
self.minion_opts = minion_opts
self.client = salt.fileclient.get_file_client(self.minion_opts, True)
self.opts = self.__gen_opts(self.master_opts,
grains,
saltenv=saltenv,
ext=ext,
pillarenv=pillarenv)
self.client = salt.fileclient.get_file_client(self.opts, True)
if opts.get('file_client', '') == 'local':
opts['grains'] = grains
if self.master_opts.get('file_client', '') == 'local':
self.master_opts['grains'] = grains
# if we didn't pass in functions, lets load them
if functions is None:
utils = salt.loader.utils(opts)
if opts.get('file_client', '') == 'local':
self.functions = salt.loader.minion_mods(opts, utils=utils)
utils = salt.loader.utils(self.master_opts)
if self.master_opts.get('file_client', '') == 'local':
self.functions = salt.loader.minion_mods(self.master_opts, utils=utils)
else:
self.functions = salt.loader.minion_mods(self.minion_opts, utils=utils)
self.functions = salt.loader.minion_mods(self.opts, utils=utils)
else:
self.functions = functions
self.matcher = salt.minion.Matcher(self.minion_opts, self.functions)
self.rend = salt.loader.render(self.minion_opts, self.functions)
self.matcher = salt.minion.Matcher(self.opts, self.functions)
self.rend = salt.loader.render(self.opts, self.functions)
# Fix self.opts['file_roots'] so that ext_pillars know the real
# location of file_roots. Issue 5951
ext_pillar_opts = dict(self.opts)
# Additionally, pass the master options in order not to loose
# the master id under __opts__
ext_pillar_opts = copy.deepcopy(self.master_opts)
ext_pillar_opts['file_roots'] = self.actual_file_roots
self.merge_strategy = 'smart'
if opts.get('pillar_source_merging_strategy'):
self.merge_strategy = opts['pillar_source_merging_strategy']
if self.master_opts.get('pillar_source_merging_strategy'):
self.merge_strategy = self.master_opts['pillar_source_merging_strategy']
self.ext_pillars = salt.loader.pillars(ext_pillar_opts, self.functions)
self.ignored_pillars = {}
@ -244,7 +250,7 @@ class Pillar(object):
)
# Backwards compatibility
saltenv = env
opts = dict(opts_in)
opts = copy.deepcopy(opts_in)
opts['file_roots'] = opts['pillar_roots']
opts['file_client'] = 'local'
if not grains:
@ -266,6 +272,7 @@ class Pillar(object):
opts['ext_pillar'].append(ext)
else:
opts['ext_pillar'] = [ext]
opts['id'] = self.minion_id
return opts
def _get_envs(self):