]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/cephadm/tests/test_template.py
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / cephadm / tests / test_template.py
CommitLineData
e306af50
TL
1import pathlib
2
3import pytest
4
5from cephadm.template import TemplateMgr, UndefinedError, TemplateNotFoundError
6
7
f91f0fd5 8def test_render(cephadm_module, fs):
e306af50
TL
9 template_base = (pathlib.Path(__file__).parent / '../templates').resolve()
10 fake_template = template_base / 'foo/bar'
11 fs.create_file(fake_template, contents='{{ cephadm_managed }}{{ var }}')
12
f91f0fd5 13 template_mgr = TemplateMgr(cephadm_module)
e306af50
TL
14 value = 'test'
15
16 # with base context
17 expected_text = '{}{}'.format(template_mgr.base_context['cephadm_managed'], value)
18 assert template_mgr.render('foo/bar', {'var': value}) == expected_text
19
20 # without base context
21 with pytest.raises(UndefinedError):
22 template_mgr.render('foo/bar', {'var': value}, managed_context=False)
23
24 # override the base context
25 context = {
26 'cephadm_managed': 'abc',
27 'var': value
28 }
29 assert template_mgr.render('foo/bar', context) == 'abc{}'.format(value)
30
31 # template not found
32 with pytest.raises(TemplateNotFoundError):
33 template_mgr.render('foo/bar/2', {})