summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2017-02-28 09:52:40 -0500
committerSean Dague <sean@dague.net>2017-02-28 10:25:17 -0500
commit8a9057a4e2a854f77f8bee2ea3ed1e006fb0a45a (patch)
tree02eaa291b062200cc694fc95b3de97ef9afe1000
parentc5626f3b4bef206c704f4be871526f1907a6a39a (diff)
Insert the right content at end of files0.4.0
Previously the logic around hitting the end of the file without having found the insertion point didn't account for the fact that you might be in roughly the right area, and would not need to duplicate the meta section or section headers. This takes that into account during the else phase. It will help with the neutron functional jobs that merge a lot of snippets together. Change-Id: Ifaa1176e9fdfbc4fdb43192ed2f85e7306823848
Notes
Notes (review): Code-Review+2: Matthew Treinish <mtreinish@kortar.org> Code-Review+2: Sean Dague <sean@dague.net> Workflow+1: Sean Dague <sean@dague.net> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 28 Feb 2017 15:37:29 +0000 Reviewed-on: https://review.openstack.org/438989 Project: openstack/devstack-tools Branch: refs/heads/master
-rw-r--r--devstack/dsconf.py8
-rw-r--r--devstack/tests/test_localconf_merge.py83
2 files changed, 88 insertions, 3 deletions
diff --git a/devstack/dsconf.py b/devstack/dsconf.py
index 43bf3f4..32da50f 100644
--- a/devstack/dsconf.py
+++ b/devstack/dsconf.py
@@ -300,9 +300,11 @@ class LocalConf(object):
300 # write out whatever we find 300 # write out whatever we find
301 writer.write(line) 301 writer.write(line)
302 if not done: 302 if not done:
303 # we never found meta with a relevant section 303 if not in_meta:
304 writer.write("[[%s|%s]]\n" % (group, conf)) 304 writer.write("[[%s|%s]]\n" % (group, conf))
305 writer.write("[%s]\n" % (section)) 305 in_section = False
306 if not in_section:
307 writer.write("[%s]\n" % (section))
306 func(writer, None) 308 func(writer, None)
307 309
308 def set(self, group, conf, section, name, value): 310 def set(self, group, conf, section, name, value):
diff --git a/devstack/tests/test_localconf_merge.py b/devstack/tests/test_localconf_merge.py
index a89e36c..bdf2a33 100644
--- a/devstack/tests/test_localconf_merge.py
+++ b/devstack/tests/test_localconf_merge.py
@@ -36,6 +36,16 @@ global_physnet_mtu=1450
36compute = auto 36compute = auto
37""" 37"""
38 38
39BASIC2 = """
40[[local|localrc]]
41a=b
42c=d
43f=1
44[[post-config|$NEUTRON_CONF]]
45[quotas]
46quota_network = 100
47"""
48
39LC1 = """ 49LC1 = """
40[[local|localrc]] 50[[local|localrc]]
41a=5 51a=5
@@ -55,6 +65,18 @@ enable_plugin ironic https://github.com/openstack/ironic
55TEMPEST_PLUGINS+=" /opt/stack/new/ironic" 65TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
56""" 66"""
57 67
68LC3 = """
69[[post-config|$NEUTRON_CONF]]
70[quotas]
71quota_port = 500
72"""
73
74LC4 = """
75[[post-config|$NEUTRON_CONF]]
76[DEFAULT]
77global_physnet_mtu=1400
78"""
79
58RESULT1 = """ 80RESULT1 = """
59[[local|localrc]] 81[[local|localrc]]
60a=b 82a=b
@@ -89,6 +111,29 @@ global_physnet_mtu=1450
89compute = auto 111compute = auto
90""" 112"""
91 113
114RESULT3 = """
115[[local|localrc]]
116a=b
117c=d
118f=1
119[[post-config|$NEUTRON_CONF]]
120[quotas]
121quota_network = 100
122quota_port = 500
123"""
124
125RESULT4 = """
126[[local|localrc]]
127a=b
128c=d
129f=1
130[[post-config|$NEUTRON_CONF]]
131[quotas]
132quota_network = 100
133[DEFAULT]
134global_physnet_mtu = 1400
135"""
136
92 137
93class TestLcMerge(testtools.TestCase): 138class TestLcMerge(testtools.TestCase):
94 139
@@ -122,3 +167,41 @@ class TestLcMerge(testtools.TestCase):
122 with open(self._path) as f: 167 with open(self._path) as f:
123 content = f.read() 168 content = f.read()
124 self.assertEqual(content, RESULT2) 169 self.assertEqual(content, RESULT2)
170
171
172class TestLcMergePost(testtools.TestCase):
173
174 def setUp(self):
175 super(TestLcMergePost, self).setUp()
176 self._path = self.useFixture(fixtures.TempDir()).path
177 self._path += "/local.conf"
178 with open(self._path, "w") as f:
179 f.write(BASIC2)
180
181 def test_merge_lc3(self):
182 """Test merging with 2 post-config sections that should overlap."""
183
184 dirname = self.useFixture(fixtures.TempDir()).path
185 lc = os.path.join(dirname, "local.conf")
186 with open(lc, "w+") as f:
187 f.write(LC3)
188 conf = dsconf.LocalConf(self._path)
189 conf.merge_lc(lc)
190
191 with open(self._path) as f:
192 content = f.read()
193 self.assertEqual(content, RESULT3)
194
195 def test_merge_lc4(self):
196 """Test merging with 2 post-config sections that should overlap."""
197
198 dirname = self.useFixture(fixtures.TempDir()).path
199 lc = os.path.join(dirname, "local2.conf")
200 with open(lc, "w+") as f:
201 f.write(LC4)
202 conf = dsconf.LocalConf(self._path)
203 conf.merge_lc(lc)
204
205 with open(self._path) as f:
206 content = f.read()
207 self.assertEqual(content, RESULT4)