summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-07-28 10:12:02 -0400
committerScott Moser <smoser@ubuntu.com>2015-07-28 10:12:02 -0400
commitf61a62434b36ab873b2b82a5ba69eda826755bfc (patch)
treefd3eb56a29c24ae28efa2a5f9b412a8b224892e8
parent6dd505fd02e0933d8770c8932a927940f6a0e025 (diff)
downloadvyos-cloud-init-f61a62434b36ab873b2b82a5ba69eda826755bfc.tar.gz
vyos-cloud-init-f61a62434b36ab873b2b82a5ba69eda826755bfc.zip
fix bug in remotes_to_rsyslog_cfg, add test
-rw-r--r--cloudinit/config/cc_rsyslog.py4
-rw-r--r--tests/unittests/test_handler/test_handler_rsyslog.py32
2 files changed, 28 insertions, 8 deletions
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index 8c02e826..915ab420 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -305,12 +305,12 @@ def remotes_to_rsyslog_cfg(remotes, header=None, footer=None):
lines.append(header)
for name, line in remotes.items():
try:
- lines.append(parse_remotes_line(line, name=name))
+ lines.append(str(parse_remotes_line(line, name=name)))
except ValueError as e:
LOG.warn("failed loading remote %s: %s [%s]", name, line, e)
if footer is not None:
lines.append(footer)
- return '\n'.join(str(lines)) + '\n'
+ return '\n'.join(lines) + "\n"
def handle(name, cfg, cloud, log, _args):
diff --git a/tests/unittests/test_handler/test_handler_rsyslog.py b/tests/unittests/test_handler/test_handler_rsyslog.py
index 0bace685..292559c5 100644
--- a/tests/unittests/test_handler/test_handler_rsyslog.py
+++ b/tests/unittests/test_handler/test_handler_rsyslog.py
@@ -4,7 +4,7 @@ import tempfile
from cloudinit.config.cc_rsyslog import (
apply_rsyslog_changes, DEF_DIR, DEF_FILENAME, DEF_RELOAD, load_config,
- parse_remotes_line)
+ parse_remotes_line, remotes_to_rsyslog_cfg)
from cloudinit import util
from .. import helpers as t_help
@@ -80,10 +80,10 @@ class TestApplyChanges(t_help.TestCase):
configs=configs, def_fname="default.cfg", cfg_dir=self.tmp)
expected = [
- (os.path.join(self.tmp, "default.cfg"),
- "*.* foohost\n"),
- (os.path.join(self.tmp, "my.cfg"), "abc\n"),
- (os.path.join(self.tmp, "mydir/mycfg"), "filefoo-content\n"),
+ (os.path.join(self.tmp, "default.cfg"),
+ "*.* foohost\n"),
+ (os.path.join(self.tmp, "my.cfg"), "abc\n"),
+ (os.path.join(self.tmp, "mydir/mycfg"), "filefoo-content\n"),
]
self.assertEqual([f[0] for f in expected], changed)
actual = []
@@ -108,7 +108,7 @@ class TestApplyChanges(t_help.TestCase):
def test_multiline_content(self):
configs = ['line1', 'line2\nline3\n']
- changed = apply_rsyslog_changes(
+ apply_rsyslog_changes(
configs=configs, def_fname="default.cfg", cfg_dir=self.tmp)
fname = os.path.join(self.tmp, "default.cfg")
@@ -143,3 +143,23 @@ class TestParseRemotesLine(t_help.TestCase):
def test_name_in_string(self):
r = parse_remotes_line("syslog.host", name="foobar")
self.assertEqual("*.* syslog.host # foobar", str(r))
+
+
+class TestRemotesToSyslog(t_help.TestCase):
+ def test_simple(self):
+ # str rendered line must appear in remotes_to_ryslog_cfg return
+ mycfg = "*.* myhost"
+ myline = str(parse_remotes_line(mycfg, name="myname"))
+ r = remotes_to_rsyslog_cfg({'myname': mycfg})
+ lines = r.splitlines()
+ self.assertEqual(1, len(lines))
+ self.assertTrue(myline in r.splitlines())
+
+ def test_header_footer(self):
+ header = "#foo head"
+ footer = "#foo foot"
+ r = remotes_to_rsyslog_cfg(
+ {'myname': "*.* myhost"}, header=header, footer=footer)
+ lines = r.splitlines()
+ self.assertTrue(header, lines[0])
+ self.assertTrue(footer, lines[-1])