fix mako renderer mixing up state and pillar data

Fixes #29942
This commit is contained in:
Andrew Colin Kissa 2015-12-22 18:03:17 +02:00
parent f056efc1c9
commit 4d29438233
2 changed files with 17 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class SaltMakoTemplateLookup(TemplateCollection):
"""
def __init__(self, opts, saltenv='base', env=None):
def __init__(self, opts, saltenv='base', env=None, pillar_rend=False):
if env is not None:
salt.utils.warn_until(
'Boron',
@ -56,10 +56,20 @@ class SaltMakoTemplateLookup(TemplateCollection):
saltenv = env
self.opts = opts
self.saltenv = saltenv
self.file_client = salt.fileclient.get_file_client(self.opts)
self._file_client = None
self.pillar_rend = pillar_rend
self.lookup = TemplateLookup(directories='/')
self.cache = {}
def file_client(self):
'''
Setup and return file_client
'''
if not self._file_client:
self._file_client = salt.fileclient.get_file_client(
self.opts, self.pillar_rend)
return self._file_client
def adjust_uri(self, uri, filename):
scheme = urlparse(uri).scheme
if scheme in ('salt', 'file'):
@ -93,7 +103,7 @@ class SaltMakoTemplateLookup(TemplateCollection):
def cache_file(self, fpath):
if fpath not in self.cache:
self.cache[fpath] = self.file_client.get_file(fpath,
self.cache[fpath] = self.file_client().get_file(fpath,
'',
True,
self.saltenv)

View File

@ -435,7 +435,10 @@ def render_mako_tmpl(tmplstr, context, tmplpath=None):
from mako.lookup import TemplateLookup
lookup = TemplateLookup(directories=[os.path.dirname(tmplpath)])
else:
lookup = SaltMakoTemplateLookup(context['opts'], saltenv)
lookup = SaltMakoTemplateLookup(
context['opts'],
saltenv,
pillar_rend=context.get('_pillar_rend', False))
try:
return Template(
tmplstr,