Don't render None as "null"

In a config file you never want the string "null" in place of a null
value. Just render an empty string instead.

Change-Id: Ibe145c4929d4944cd8d51c07a64aee6fd5f831f2
Closes-Bug: #1830967
Story: 2005797
(cherry picked from commit 75d527ab8f)
This commit is contained in:
Zane Bitter 2019-05-29 15:57:42 -04:00 committed by Emilien Macchi
parent f822e821f4
commit e817b6d0ca
2 changed files with 7 additions and 0 deletions

View File

@ -38,4 +38,6 @@ class JsonRenderer(pystache.Renderer):
partials, missing_tags)
def str_coerce(self, val):
if val is None:
return b''
return json.dumps(val)

View File

@ -337,6 +337,11 @@ class OSConfigApplierTestCase(testtools.TestCase):
def test_render_moustache_bad_key(self):
self.assertEqual(u'', apply_config.render_moustache("{{badkey}}", {}))
def test_render_moustache_none(self):
self.assertEqual('foo: ',
apply_config.render_moustache("foo: {{foo}}",
{'foo': None}))
def test_render_executable(self):
params = {"x": "foo"}
self.assertEqual("foo\n", apply_config.render_executable(