diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-07-28 10:34:31 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-07-28 10:34:31 -0400 |
commit | c6e7fb1752a93ed534080adf0588e4c7cdd99071 (patch) | |
tree | 48c3def00df21141210f6425061c1e5e9f899218 | |
parent | f61a62434b36ab873b2b82a5ba69eda826755bfc (diff) | |
download | vyos-cloud-init-c6e7fb1752a93ed534080adf0588e4c7cdd99071.tar.gz vyos-cloud-init-c6e7fb1752a93ed534080adf0588e4c7cdd99071.zip |
add trailing newline only if necessary
-rw-r--r-- | cloudinit/config/cc_rsyslog.py | 9 | ||||
-rw-r--r-- | tests/unittests/test_handler/test_handler_rsyslog.py | 2 |
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) |