From ead9a6ef95544e1e7ccb76a1f7f9a7260b503fb9 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 2 Mar 2022 12:56:21 -0500 Subject: [PATCH 1/2] add support for jinja do statements, add unit test --- cloudinit/templater.py | 5 ++++- tests/unittests/test_templating.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cloudinit/templater.py b/cloudinit/templater.py index 1e147d4ab64..d8af5096062 100644 --- a/cloudinit/templater.py +++ b/cloudinit/templater.py @@ -104,7 +104,10 @@ def jinja_render(content, params): add = "\n" if content.endswith("\n") else "" return ( JTemplate( - content, undefined=UndefinedJinjaVariable, trim_blocks=True + content, + undefined=UndefinedJinjaVariable, + trim_blocks=True, + extensions=["jinja2.ext.do"], ).render(**params) + add ) diff --git a/tests/unittests/test_templating.py b/tests/unittests/test_templating.py index c1fec27c434..3a0195bf292 100644 --- a/tests/unittests/test_templating.py +++ b/tests/unittests/test_templating.py @@ -184,5 +184,19 @@ def test_jinja_warns_on_missing_dep_and_uses_basic_renderer(self): self.logs.getvalue(), ) + def test_jinja_do_extension_render_to_string(self): + """Test jinja render_to_string using do extension.""" + expected_result = "[1, 2, 3]" + jinja_template = ( + "{% set r = [] %} {% set input = [1,2,3] %} " + "{% for i in input %} {% do r.append(i) %} {% endfor %} {{r}}" + ) + self.assertEqual( + templater.render_string( + self.add_header("jinja", jinja_template), {} + ).strip(), + expected_result, + ) + # vi: ts=4 expandtab From 0cb168401655ee6e819d9aa48fb8630a650bcef0 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 2 Mar 2022 13:05:55 -0500 Subject: [PATCH 2/2] add username to github signers --- tools/.github-cla-signers | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index 0567a89dfc3..1aaae7f9a9f 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -79,6 +79,7 @@ steverweber t-8ch TheRealFalcon taoyama +thetoolsmith timothegenzmer tnt-dev tomponline