summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-03-07 19:33:41 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-03-07 19:33:41 -0800
commitb740568ddfe6194af7c2c5d7123b3cc2a07fa7f7 (patch)
treef3f271cb36e109b51b3105e287e3148f3aff51aa /cloudinit/templater.py
parentcc79c859115ceb520877c0afaece4c28d6031499 (diff)
downloadvyos-cloud-init-b740568ddfe6194af7c2c5d7123b3cc2a07fa7f7.tar.gz
vyos-cloud-init-b740568ddfe6194af7c2c5d7123b3cc2a07fa7f7.zip
Add some basic template tests
Diffstat (limited to 'cloudinit/templater.py')
-rw-r--r--cloudinit/templater.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index 915b188e..9922c633 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -44,21 +44,21 @@ TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I)
def detect_template(text):
- try:
+ if text.find("\n") != -1:
ident, rest = text.split("\n", 1)
- except ValueError:
+ else:
+ ident = text
+ rest = ''
+ type_match = TYPE_MATCHER.match(ident)
+ if not type_match:
return (DEF_RENDERER, text)
+ template_type = type_match.group(1).lower().strip()
+ if template_type not in RENDERERS:
+ raise ValueError("Unknown template type '%s' requested"
+ % template_type)
else:
- type_match = TYPE_MATCHER.match(ident)
- if not type_match:
- return (DEF_RENDERER, text)
- template_type = type_match.group(1).lower().strip()
- if template_type not in RENDERERS:
- raise ValueError("Unknown template type '%s' requested"
- % template_type)
- else:
- return (template_type, rest)
-
+ return (template_type, rest)
+
def render_from_file(fn, params):
return render_string(util.load_file(fn), params)
@@ -74,7 +74,8 @@ def render_string(content, params):
params = {}
try:
renderer, content = detect_template(content)
- except ValueError:
+ except ValueError as e:
renderer = DEF_RENDERER
+ LOG.warn("%s, using renderer %s", e, renderer)
LOG.debug("Rendering %s using renderer '%s'", content, renderer)
return RENDERERS[renderer](content, params)