From 73b1bb1f7665216053494717de27d7daf445d751 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Fri, 14 Jan 2022 11:09:30 -0700 Subject: Test Optimization Proposal (SC-736) (#1188) Reduce template rendering test runtime --- cloudinit/templater.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cloudinit') diff --git a/cloudinit/templater.py b/cloudinit/templater.py index c215bbbb..1e147d4a 100644 --- a/cloudinit/templater.py +++ b/cloudinit/templater.py @@ -12,6 +12,7 @@ import collections import re +import sys try: from Cheetah.Template import Template as CTemplate @@ -32,6 +33,7 @@ except (ImportError, AttributeError): from cloudinit import log as logging from cloudinit import type_utils as tu from cloudinit import util +from cloudinit.atomic_helper import write_file LOG = logging.getLogger(__name__) TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I) @@ -180,4 +182,17 @@ def render_string(content, params): return renderer(content, params) +def render_cloudcfg(variant, template, output): + + with open(template, "r") as fh: + contents = fh.read() + tpl_params = {"variant": variant} + contents = (render_string(contents, tpl_params)).rstrip() + "\n" + util.load_yaml(contents) + if output == "-": + sys.stdout.write(contents) + else: + write_file(output, contents, omode="w") + + # vi: ts=4 expandtab -- cgit v1.2.3