summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2017-01-17 09:22:18 -0500
committerSean Dague <sean@dague.net>2017-01-17 09:22:18 -0500
commit3ecd349bfe5127dbd246777c3553c22a09433315 (patch)
tree2ecefe44864491adb4789a2ca554e46ec7c79e38
parent0366529cc9f018fdcce4b2f56e884f332278ef35 (diff)
Fix merge of local.conf add tests0.1.0
-rw-r--r--devstack/dsconf.py2
-rw-r--r--devstack/tests/test_localconf_merge.py88
2 files changed, 89 insertions, 1 deletions
diff --git a/devstack/dsconf.py b/devstack/dsconf.py
index 66071cd..f02478a 100644
--- a/devstack/dsconf.py
+++ b/devstack/dsconf.py
@@ -306,4 +306,4 @@ class LocalConf(object):
306 self.set_local(m.group(1), m.group(2)) 306 self.set_local(m.group(1), m.group(2))
307 else: 307 else:
308 for section, name, value in lc._conf(group, conf): 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)
diff --git a/devstack/tests/test_localconf_merge.py b/devstack/tests/test_localconf_merge.py
new file mode 100644
index 0000000..50d4b74
--- /dev/null
+++ b/devstack/tests/test_localconf_merge.py
@@ -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
19import fixtures
20import os.path
21import testtools
22
23from devstack import dsconf
24
25
26BASIC = """
27[[local|localrc]]
28a = b
29c = d
30f = 1
31[[post-config|$NEUTRON_CONF]]
32[DEFAULT]
33global_physnet_mtu=1450
34[[post-config|$NOVA_CONF]]
35[upgrade_levels]
36compute = auto
37"""
38
39LC1 = """
40[[local|localrc]]
41a = 5
42g = 2
43[[post-config|$NEUTRON_CONF]]
44[DEFAULT]
45global_physnet_mtu=1400
46[[post-config|$GLANCE_CONF]]
47[upgrade_levels]
48compute = auto
49"""
50
51RESULT1 = """
52[[local|localrc]]
53a = 5
54c = d
55f = 1
56g = 2
57[[post-config|$NEUTRON_CONF]]
58[DEFAULT]
59global_physnet_mtu = 1400
60[[post-config|$NOVA_CONF]]
61[upgrade_levels]
62compute = auto
63[[post-config|$GLANCE_CONF]]
64[upgrade_levels]
65compute = auto
66"""
67
68
69class 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)