summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_rsyslog.py9
-rw-r--r--tests/unittests/test_handler/test_handler_rsyslog.py2
2 files changed, 6 insertions, 5 deletions
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index 915ab420..2bb00728 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -188,8 +188,7 @@ def apply_rsyslog_changes(configs, def_fname, cfg_dir):
LOG.warn("Entry %s has an empty filename", cur_pos + 1)
continue
- if not filename.startswith("/"):
- filename = os.path.join(cfg_dir, filename)
+ filename = os.path.join(cfg_dir, filename)
# Truncate filename first time you see it
omode = "ab"
@@ -198,8 +197,10 @@ def apply_rsyslog_changes(configs, def_fname, cfg_dir):
files.append(filename)
try:
- contents = "%s\n" % (content)
- util.write_file(filename, contents, omode=omode)
+ endl = ""
+ if not content.endswith("\n"):
+ endl = "\n"
+ util.write_file(filename, content + endl, omode=omode)
except Exception:
util.logexc(LOG, "Failed to write to %s", filename)
diff --git a/tests/unittests/test_handler/test_handler_rsyslog.py b/tests/unittests/test_handler/test_handler_rsyslog.py
index 292559c5..e7666615 100644
--- a/tests/unittests/test_handler/test_handler_rsyslog.py
+++ b/tests/unittests/test_handler/test_handler_rsyslog.py
@@ -112,7 +112,7 @@ class TestApplyChanges(t_help.TestCase):
configs=configs, def_fname="default.cfg", cfg_dir=self.tmp)
fname = os.path.join(self.tmp, "default.cfg")
- expected_content = '\n'.join([c for c in configs]) + '\n'
+ expected_content = '\n'.join([c for c in configs])
found_content = util.load_file(fname)
self.assertEqual(expected_content, found_content)