2014-04-07 16:13:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2014-04-07 16:13:23 +00:00
|
|
|
from salttesting import skipIf, TestCase
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
|
2014-10-11 03:16:14 +00:00
|
|
|
ensure_in_syspath('../..')
|
2014-04-07 16:13:23 +00:00
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Salt libs
|
2014-04-07 16:13:23 +00:00
|
|
|
import salt.state
|
|
|
|
from salt.config import minion_config
|
|
|
|
from salt.template import compile_template_str
|
2015-05-28 23:48:00 +00:00
|
|
|
from salt.serializers import yamlex
|
2014-04-07 16:13:23 +00:00
|
|
|
|
2014-05-30 15:28:20 +00:00
|
|
|
basic_template = '''#!yamlex
|
2014-04-07 16:13:23 +00:00
|
|
|
foo: bar
|
|
|
|
'''
|
|
|
|
|
2014-05-30 15:28:20 +00:00
|
|
|
complex_template = '''#!yamlex
|
2014-04-07 16:13:23 +00:00
|
|
|
placeholder: {foo: !aggregate {foo: 42}}
|
|
|
|
placeholder: {foo: !aggregate {bar: null}}
|
|
|
|
placeholder: {foo: !aggregate {baz: inga}}
|
|
|
|
'''
|
|
|
|
|
|
|
|
SKIP_MESSAGE = '%s is unavailable, do prerequisites have been met?'
|
|
|
|
|
|
|
|
|
|
|
|
class RendererMixin(object):
|
|
|
|
def render(self, template, opts=None):
|
|
|
|
_config = minion_config(None)
|
|
|
|
_config['file_client'] = 'local'
|
|
|
|
if opts:
|
|
|
|
_config.update(opts)
|
|
|
|
_state = salt.state.State(_config)
|
|
|
|
return compile_template_str(template,
|
|
|
|
_state.rend,
|
2016-05-20 17:41:51 +00:00
|
|
|
_state.opts['renderer'],
|
|
|
|
_state.opts['renderer_blacklist'],
|
|
|
|
_state.opts['renderer_whitelist'])
|
2014-04-07 16:13:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RendererTests(TestCase, RendererMixin):
|
2014-05-30 15:28:20 +00:00
|
|
|
@skipIf(not yamlex.available, SKIP_MESSAGE % 'yamlex')
|
2014-04-07 16:13:23 +00:00
|
|
|
def test_basic(self):
|
|
|
|
sls_obj = self.render(basic_template)
|
|
|
|
assert sls_obj == {'foo': 'bar'}, sls_obj
|
|
|
|
|
2014-05-30 15:28:20 +00:00
|
|
|
@skipIf(not yamlex.available, SKIP_MESSAGE % 'yamlex')
|
2014-04-07 16:13:23 +00:00
|
|
|
def test_complex(self):
|
|
|
|
|
|
|
|
sls_obj = self.render(complex_template)
|
|
|
|
assert sls_obj == {
|
|
|
|
'placeholder': {
|
|
|
|
'foo': {
|
|
|
|
'foo': 42,
|
|
|
|
'bar': None,
|
|
|
|
'baz': 'inga'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, sls_obj
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(RendererTests, needs_daemon=False)
|