diff options
author | Christian Breunig <christian@breunig.cc> | 2025-05-04 11:23:54 +0200 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2025-05-04 11:23:54 +0200 |
commit | aff2835d7b6226e4b89f51e3f6133da26f3a07bf (patch) | |
tree | ee2185f629ccf46f127d3cf37d65422cc8696cff /src | |
parent | d85256bae1757c5c6ecbb685ce4311b0cc89962a (diff) | |
download | vyos-1x-aff2835d7b6226e4b89f51e3f6133da26f3a07bf.tar.gz vyos-1x-aff2835d7b6226e4b89f51e3f6133da26f3a07bf.zip |
vyos.template: T7122: add Jinja2 clever function helper to read vyos.defaults
Add a new category if Jinja2 operands. We already have filters and tests, but
sometimes we would like to call a Python function without and data "|" piped
to it - that's what they call a clever-function.
{{ get_default_port(NAME) }} can be used to retrieve the value from
vyos.defaults.internal_ports[NAME] within Jinja2. We no longer need to extend
the dictionary with arbitrary data retrieved from vyos.defaults, we can now
simply register another clever-function to the Jinja2 backend.
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_template.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/tests/test_template.py b/src/tests/test_template.py index 6377f6da5..7cae867a0 100644 --- a/src/tests/test_template.py +++ b/src/tests/test_template.py @@ -190,3 +190,12 @@ class TestVyOSTemplate(TestCase): for group_name, group_config in data['ike_group'].items(): ciphers = vyos.template.get_esp_ike_cipher(group_config) self.assertIn(IKEv2_DEFAULT, ','.join(ciphers)) + + def test_get_default_port(self): + from vyos.defaults import internal_ports + + with self.assertRaises(RuntimeError): + vyos.template.get_default_port('UNKNOWN') + + self.assertEqual(vyos.template.get_default_port('certbot_haproxy'), + internal_ports['certbot_haproxy']) |