Browse Source

Insert the right content at end of files

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
tags/0.4.0^0
Sean Dague 2 years ago
parent
commit
8a9057a4e2
2 changed files with 88 additions and 3 deletions
  1. 5
    3
      devstack/dsconf.py
  2. 83
    0
      devstack/tests/test_localconf_merge.py

+ 5
- 3
devstack/dsconf.py View File

@@ -300,9 +300,11 @@ class LocalConf(object):
300 300
                         # write out whatever we find
301 301
                         writer.write(line)
302 302
             if not done:
303
-                # we never found meta with a relevant section
304
-                writer.write("[[%s|%s]]\n" % (group, conf))
305
-                writer.write("[%s]\n" % (section))
303
+                if not in_meta:
304
+                    writer.write("[[%s|%s]]\n" % (group, conf))
305
+                    in_section = False
306
+                if not in_section:
307
+                    writer.write("[%s]\n" % (section))
306 308
                 func(writer, None)
307 309
 
308 310
     def set(self, group, conf, section, name, value):

+ 83
- 0
devstack/tests/test_localconf_merge.py View File

@@ -36,6 +36,16 @@ global_physnet_mtu=1450
36 36
 compute = auto
37 37
 """
38 38
 
39
+BASIC2 = """
40
+[[local|localrc]]
41
+a=b
42
+c=d
43
+f=1
44
+[[post-config|$NEUTRON_CONF]]
45
+[quotas]
46
+quota_network = 100
47
+"""
48
+
39 49
 LC1 = """
40 50
 [[local|localrc]]
41 51
 a=5
@@ -55,6 +65,18 @@ enable_plugin ironic https://github.com/openstack/ironic
55 65
 TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
56 66
 """
57 67
 
68
+LC3 = """
69
+[[post-config|$NEUTRON_CONF]]
70
+[quotas]
71
+quota_port = 500
72
+"""
73
+
74
+LC4 = """
75
+[[post-config|$NEUTRON_CONF]]
76
+[DEFAULT]
77
+global_physnet_mtu=1400
78
+"""
79
+
58 80
 RESULT1 = """
59 81
 [[local|localrc]]
60 82
 a=b
@@ -89,6 +111,29 @@ global_physnet_mtu=1450
89 111
 compute = auto
90 112
 """
91 113
 
114
+RESULT3 = """
115
+[[local|localrc]]
116
+a=b
117
+c=d
118
+f=1
119
+[[post-config|$NEUTRON_CONF]]
120
+[quotas]
121
+quota_network = 100
122
+quota_port = 500
123
+"""
124
+
125
+RESULT4 = """
126
+[[local|localrc]]
127
+a=b
128
+c=d
129
+f=1
130
+[[post-config|$NEUTRON_CONF]]
131
+[quotas]
132
+quota_network = 100
133
+[DEFAULT]
134
+global_physnet_mtu = 1400
135
+"""
136
+
92 137
 
93 138
 class TestLcMerge(testtools.TestCase):
94 139
 
@@ -122,3 +167,41 @@ class TestLcMerge(testtools.TestCase):
122 167
         with open(self._path) as f:
123 168
             content = f.read()
124 169
             self.assertEqual(content, RESULT2)
170
+
171
+
172
+class 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)

Loading…
Cancel
Save