summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Holman <bholman.devel@gmail.com>2022-04-29 16:16:42 -0500
committerGitHub <noreply@github.com>2022-04-29 15:16:42 -0600
commitb4746b6aed7660510071395e70b2d6233fbdc3ab (patch)
tree393afa7ac78eb0f49ff0179a782e30690397c608
parentc55534de339980c5bdaa81f0d73a2d7bab77d717 (diff)
downloadcloud-init-git-b4746b6aed7660510071395e70b2d6233fbdc3ab.tar.gz
Remove cheetah from templater (#1416)
Remove cheetah template code - cheetah was dropped as a requirement in 17.1 - we still have cheetah template code - cheetah test fails - no known users - remove rather than fix
-rw-r--r--cloudinit/templater.py42
-rw-r--r--tests/unittests/__init__.py12
-rw-r--r--tests/unittests/test_templating.py30
3 files changed, 5 insertions, 79 deletions
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index d8af5096..298eaf6b 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -15,13 +15,6 @@ import re
import sys
try:
- from Cheetah.Template import Template as CTemplate
-
- CHEETAH_AVAILABLE = True
-except (ImportError, AttributeError):
- CHEETAH_AVAILABLE = False
-
-try:
from jinja2 import DebugUndefined as JUndefined
from jinja2 import Template as JTemplate
@@ -96,9 +89,6 @@ def basic_render(content, params):
def detect_template(text):
- def cheetah_render(content, params):
- return CTemplate(content, searchList=[params]).respond()
-
def jinja_render(content, params):
# keep_trailing_newline is in jinja2 2.7+, not 2.6
add = "\n" if content.endswith("\n") else ""
@@ -119,14 +109,10 @@ def detect_template(text):
rest = ""
type_match = TYPE_MATCHER.match(ident)
if not type_match:
- if CHEETAH_AVAILABLE:
- LOG.debug("Using Cheetah as the renderer for unknown template.")
- return ("cheetah", cheetah_render, text)
- else:
- return ("basic", basic_render, text)
+ return ("basic", basic_render, text)
else:
template_type = type_match.group(1).lower().strip()
- if template_type not in ("jinja", "cheetah", "basic"):
+ if template_type not in ("jinja", "basic"):
raise ValueError(
"Unknown template rendering type '%s' requested"
% template_type
@@ -139,14 +125,6 @@ def detect_template(text):
return ("basic", basic_render, rest)
elif template_type == "jinja" and JINJA_AVAILABLE:
return ("jinja", jinja_render, rest)
- if template_type == "cheetah" and not CHEETAH_AVAILABLE:
- LOG.warning(
- "Cheetah not available as the selected renderer for"
- " desired template, reverting to the basic renderer."
- )
- return ("basic", basic_render, rest)
- elif template_type == "cheetah" and CHEETAH_AVAILABLE:
- return ("cheetah", cheetah_render, rest)
# Only thing left over is the basic renderer (it is always available).
return ("basic", basic_render, rest)
@@ -154,12 +132,7 @@ def detect_template(text):
def render_from_file(fn, params):
if not params:
params = {}
- # jinja in python2 uses unicode internally. All py2 str will be decoded.
- # If it is given a str that has non-ascii then it will raise a
- # UnicodeDecodeError. So we explicitly convert to unicode type here.
- template_type, renderer, content = detect_template(
- util.load_file(fn, decode=False).decode("utf-8")
- )
+ template_type, renderer, content = detect_template(util.load_file(fn))
LOG.debug("Rendering content of '%s' using renderer %s", fn, template_type)
return renderer(content, params)
@@ -170,15 +143,13 @@ def render_to_file(fn, outfn, params, mode=0o644):
def render_string_to_file(content, outfn, params, mode=0o644):
- """Render string (or py2 unicode) to file.
- Warning: py2 str with non-ascii chars will cause UnicodeDecodeError."""
+ """Render string"""
contents = render_string(content, params)
util.write_file(outfn, contents, mode=mode)
def render_string(content, params):
- """Render string (or py2 unicode).
- Warning: py2 str with non-ascii chars will cause UnicodeDecodeError."""
+ """Render string"""
if not params:
params = {}
_template_type, renderer, content = detect_template(content)
@@ -196,6 +167,3 @@ def render_cloudcfg(variant, template, output):
sys.stdout.write(contents)
else:
write_file(output, contents, omode="w")
-
-
-# vi: ts=4 expandtab
diff --git a/tests/unittests/__init__.py b/tests/unittests/__init__.py
index 657cb399..e69de29b 100644
--- a/tests/unittests/__init__.py
+++ b/tests/unittests/__init__.py
@@ -1,12 +0,0 @@
-# This file is part of cloud-init. See LICENSE file for license information.
-
-try:
- # For test cases, avoid the following UserWarning to stderr:
- # You don't have the C version of NameMapper installed ...
- from Cheetah import NameMapper as _nm
-
- _nm.C_VERSION = True
-except ImportError:
- pass
-
-# vi: ts=4 expandtab
diff --git a/tests/unittests/test_templating.py b/tests/unittests/test_templating.py
index 3a0195bf..0cdedbe7 100644
--- a/tests/unittests/test_templating.py
+++ b/tests/unittests/test_templating.py
@@ -10,14 +10,6 @@ from cloudinit import templater
from cloudinit.util import load_file, write_file
from tests.unittests import helpers as test_helpers
-try:
- import Cheetah
-
- HAS_CHEETAH = True
- c = Cheetah # make pyflakes and pylint happy, as Cheetah is not used here
-except ImportError:
- HAS_CHEETAH = False
-
class TestTemplates(test_helpers.CiTestCase):
@@ -52,28 +44,6 @@ class TestTemplates(test_helpers.CiTestCase):
out_data = templater.basic_render(in_data, {"b": 2})
self.assertEqual(expected_data.strip(), out_data)
- @test_helpers.skipIf(not HAS_CHEETAH, "cheetah renderer not available")
- def test_detection(self):
- blob = "## template:cheetah"
-
- (template_type, _renderer, contents) = templater.detect_template(blob)
- self.assertIn("cheetah", template_type)
- self.assertEqual("", contents.strip())
-
- blob = "blahblah $blah"
- (template_type, _renderer, _contents) = templater.detect_template(blob)
- self.assertIn("cheetah", template_type)
- self.assertEqual(blob, contents)
-
- blob = "##template:something-new"
- self.assertRaises(ValueError, templater.detect_template, blob)
-
- def test_render_cheetah(self):
- blob = """## template:cheetah
-$a,$b"""
- c = templater.render_string(blob, {"a": 1, "b": 2})
- self.assertEqual("1,2", c)
-
def test_render_jinja(self):
blob = """## template:jinja
{{a}},{{b}}"""