diff options
author | Zuul <zuul@review.opendev.org> | 2021-03-29 15:13:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2021-03-29 15:13:31 +0000 |
commit | 1caaa0c5075d10810dcd143f1bb41c6a034e3023 (patch) | |
tree | 002b99815f8e73725899d00cd7a320d071d8de67 /ironic/common/utils.py | |
parent | 356734aacaa1da7fd3457f2bb21ce208b71dc151 (diff) | |
parent | 9d3de26fb17f247c3140aaf31839b7cc3589ede0 (diff) | |
download | ironic-1caaa0c5075d10810dcd143f1bb41c6a034e3023.tar.gz |
Merge "Validate the kickstart template and file before use"
Diffstat (limited to 'ironic/common/utils.py')
-rw-r--r-- | ironic/common/utils.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ironic/common/utils.py b/ironic/common/utils.py index ce482f2cc..390fe0305 100644 --- a/ironic/common/utils.py +++ b/ironic/common/utils.py @@ -468,13 +468,15 @@ def validate_network_port(port, port_name="Port"): {'port_name': port_name, 'port': port}) -def render_template(template, params, is_file=True): +def render_template(template, params, is_file=True, strict=False): """Renders Jinja2 template file with given parameters. :param template: full path to the Jinja2 template file :param params: dictionary with parameters to use when rendering :param is_file: whether template is file or string with template itself - :returns: the rendered template as a string + :param strict: Enable strict template rendering. Default is False + :returns: Rendered template + :raises: jinja2.exceptions.UndefinedError """ if is_file: tmpl_path, tmpl_name = os.path.split(template) @@ -486,8 +488,11 @@ def render_template(template, params, is_file=True): # and still complains with B701 for that line # NOTE(pas-ha) not using default_for_string=False as we set the name # of the template above for strings too. - env = jinja2.Environment(loader=loader, # nosec B701 - autoescape=jinja2.select_autoescape()) + env = jinja2.Environment( + loader=loader, + autoescape=jinja2.select_autoescape(), # nosec B701 + undefined=jinja2.StrictUndefined if strict else jinja2.Undefined + ) tmpl = env.get_template(tmpl_name) return tmpl.render(params, enumerate=enumerate) |