Browse Source

Fix merge of local.conf add tests

Sean Dague 2 years ago
parent
commit
3ecd349bfe
2 changed files with 89 additions and 1 deletions
  1. 1
    1
      devstack/dsconf.py
  2. 88
    0
      devstack/tests/test_localconf_merge.py

+ 1
- 1
devstack/dsconf.py View File

@@ -306,4 +306,4 @@ class LocalConf(object):
306 306
                         self.set_local(m.group(1), m.group(2))
307 307
             else:
308 308
                 for section, name, value in lc._conf(group, conf):
309
-                    lc.set(group, conf, section, name, value)
309
+                    self.set(group, conf, section, name, value)

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

@@ -0,0 +1,88 @@
1
+# Copyright 2017 IBM
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#    http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+# Implementation of ini add / remove for devstack. We don't use the
16
+# python ConfigFile parser because that ends up rewriting the entire
17
+# file and doesn't ensure comments remain.
18
+
19
+import fixtures
20
+import os.path
21
+import testtools
22
+
23
+from devstack import dsconf
24
+
25
+
26
+BASIC = """
27
+[[local|localrc]]
28
+a = b
29
+c = d
30
+f = 1
31
+[[post-config|$NEUTRON_CONF]]
32
+[DEFAULT]
33
+global_physnet_mtu=1450
34
+[[post-config|$NOVA_CONF]]
35
+[upgrade_levels]
36
+compute = auto
37
+"""
38
+
39
+LC1 = """
40
+[[local|localrc]]
41
+a = 5
42
+g = 2
43
+[[post-config|$NEUTRON_CONF]]
44
+[DEFAULT]
45
+global_physnet_mtu=1400
46
+[[post-config|$GLANCE_CONF]]
47
+[upgrade_levels]
48
+compute = auto
49
+"""
50
+
51
+RESULT1 = """
52
+[[local|localrc]]
53
+a = 5
54
+c = d
55
+f = 1
56
+g = 2
57
+[[post-config|$NEUTRON_CONF]]
58
+[DEFAULT]
59
+global_physnet_mtu = 1400
60
+[[post-config|$NOVA_CONF]]
61
+[upgrade_levels]
62
+compute = auto
63
+[[post-config|$GLANCE_CONF]]
64
+[upgrade_levels]
65
+compute = auto
66
+"""
67
+
68
+
69
+class TestLcMerge(testtools.TestCase):
70
+
71
+    def setUp(self):
72
+        super(TestLcMerge, self).setUp()
73
+        self._path = self.useFixture(fixtures.TempDir()).path
74
+        self._path += "/local.conf"
75
+        with open(self._path, "w") as f:
76
+            f.write(BASIC)
77
+
78
+    def test_merge_lc1(self):
79
+        dirname = self.useFixture(fixtures.TempDir()).path
80
+        lc1 = os.path.join(dirname, "local1.conf")
81
+        with open(lc1, "w+") as f:
82
+            f.write(LC1)
83
+        conf = dsconf.LocalConf(self._path)
84
+        conf.merge_lc(lc1)
85
+
86
+        with open(self._path) as f:
87
+            content = f.read()
88
+            self.assertEqual(content, RESULT1)

Loading…
Cancel
Save