Browse Source

add tests for merging lines beyond a=b

Change-Id: Id2af3b86e19c02fee4058d61e15eb6dd462c6e73
Sean Dague 2 years ago
parent
commit
1384ec992d
2 changed files with 36 additions and 2 deletions
  1. 2
    2
      devstack/dsconf.py
  2. 34
    0
      devstack/tests/test_localconf_merge.py

+ 2
- 2
devstack/dsconf.py View File

@@ -233,11 +233,11 @@ class LocalConf(object):
233 233
         if not os.path.exists(self.fname):
234 234
             with open(self.fname, "w+") as writer:
235 235
                 writer.write("[[local|localrc]]\n")
236
-                writer.write("%s\n" % line.lstrip())
236
+                writer.write("%s\n" % line.rstrip())
237 237
                 return
238 238
 
239 239
         def _do_set(writer, no_line):
240
-            writer.write("%s\n" % line.lstrip())
240
+            writer.write("%s\n" % line.rstrip())
241 241
         self._at_insert_point_local(line, _do_set)
242 242
 
243 243
     def _at_insert_point(self, group, conf, section, name, func):

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

@@ -48,6 +48,13 @@ global_physnet_mtu=1400
48 48
 compute = auto
49 49
 """
50 50
 
51
+LC2 = """
52
+[[local|localrc]]
53
+# some other comment
54
+enable_plugin ironic https://github.com/openstack/ironic
55
+TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
56
+"""
57
+
51 58
 RESULT1 = """
52 59
 [[local|localrc]]
53 60
 a=5
@@ -65,6 +72,21 @@ compute = auto
65 72
 compute = auto
66 73
 """
67 74
 
75
+RESULT2 = """
76
+[[local|localrc]]
77
+a=b
78
+c=d
79
+f=1
80
+enable_plugin ironic https://github.com/openstack/ironic
81
+TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
82
+[[post-config|$NEUTRON_CONF]]
83
+[DEFAULT]
84
+global_physnet_mtu=1450
85
+[[post-config|$NOVA_CONF]]
86
+[upgrade_levels]
87
+compute = auto
88
+"""
89
+
68 90
 
69 91
 class TestLcMerge(testtools.TestCase):
70 92
 
@@ -86,3 +108,15 @@ class TestLcMerge(testtools.TestCase):
86 108
         with open(self._path) as f:
87 109
             content = f.read()
88 110
             self.assertEqual(content, RESULT1)
111
+
112
+    def test_merge_lc2(self):
113
+        dirname = self.useFixture(fixtures.TempDir()).path
114
+        lc2 = os.path.join(dirname, "local2.conf")
115
+        with open(lc2, "w+") as f:
116
+            f.write(LC2)
117
+        conf = dsconf.LocalConf(self._path)
118
+        conf.merge_lc(lc2)
119
+
120
+        with open(self._path) as f:
121
+            content = f.read()
122
+            self.assertEqual(content, RESULT2)

Loading…
Cancel
Save