From 1384ec992db4ea1692e66427dfa56edfe9a75528 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 19 Jan 2017 09:18:11 -0500 Subject: [PATCH] add tests for merging lines beyond a=b Change-Id: Id2af3b86e19c02fee4058d61e15eb6dd462c6e73 --- devstack/dsconf.py | 4 +-- devstack/tests/test_localconf_merge.py | 34 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/devstack/dsconf.py b/devstack/dsconf.py index 253d812..72b8d6d 100644 --- a/devstack/dsconf.py +++ b/devstack/dsconf.py @@ -233,11 +233,11 @@ class LocalConf(object): if not os.path.exists(self.fname): with open(self.fname, "w+") as writer: writer.write("[[local|localrc]]\n") - writer.write("%s\n" % line.lstrip()) + writer.write("%s\n" % line.rstrip()) return def _do_set(writer, no_line): - writer.write("%s\n" % line.lstrip()) + writer.write("%s\n" % line.rstrip()) self._at_insert_point_local(line, _do_set) def _at_insert_point(self, group, conf, section, name, func): diff --git a/devstack/tests/test_localconf_merge.py b/devstack/tests/test_localconf_merge.py index a6d9424..d1ad75f 100644 --- a/devstack/tests/test_localconf_merge.py +++ b/devstack/tests/test_localconf_merge.py @@ -48,6 +48,13 @@ global_physnet_mtu=1400 compute = auto """ +LC2 = """ +[[local|localrc]] +# some other comment +enable_plugin ironic https://github.com/openstack/ironic +TEMPEST_PLUGINS+=" /opt/stack/new/ironic" +""" + RESULT1 = """ [[local|localrc]] a=5 @@ -65,6 +72,21 @@ compute = auto compute = auto """ +RESULT2 = """ +[[local|localrc]] +a=b +c=d +f=1 +enable_plugin ironic https://github.com/openstack/ironic +TEMPEST_PLUGINS+=" /opt/stack/new/ironic" +[[post-config|$NEUTRON_CONF]] +[DEFAULT] +global_physnet_mtu=1450 +[[post-config|$NOVA_CONF]] +[upgrade_levels] +compute = auto +""" + class TestLcMerge(testtools.TestCase): @@ -86,3 +108,15 @@ class TestLcMerge(testtools.TestCase): with open(self._path) as f: content = f.read() self.assertEqual(content, RESULT1) + + def test_merge_lc2(self): + dirname = self.useFixture(fixtures.TempDir()).path + lc2 = os.path.join(dirname, "local2.conf") + with open(lc2, "w+") as f: + f.write(LC2) + conf = dsconf.LocalConf(self._path) + conf.merge_lc(lc2) + + with open(self._path) as f: + content = f.read() + self.assertEqual(content, RESULT2)