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
This commit is contained in:
parent
c5626f3b4b
commit
8a9057a4e2
@ -300,9 +300,11 @@ class LocalConf(object):
|
||||
# write out whatever we find
|
||||
writer.write(line)
|
||||
if not done:
|
||||
# we never found meta with a relevant section
|
||||
writer.write("[[%s|%s]]\n" % (group, conf))
|
||||
writer.write("[%s]\n" % (section))
|
||||
if not in_meta:
|
||||
writer.write("[[%s|%s]]\n" % (group, conf))
|
||||
in_section = False
|
||||
if not in_section:
|
||||
writer.write("[%s]\n" % (section))
|
||||
func(writer, None)
|
||||
|
||||
def set(self, group, conf, section, name, value):
|
||||
|
@ -36,6 +36,16 @@ global_physnet_mtu=1450
|
||||
compute = auto
|
||||
"""
|
||||
|
||||
BASIC2 = """
|
||||
[[local|localrc]]
|
||||
a=b
|
||||
c=d
|
||||
f=1
|
||||
[[post-config|$NEUTRON_CONF]]
|
||||
[quotas]
|
||||
quota_network = 100
|
||||
"""
|
||||
|
||||
LC1 = """
|
||||
[[local|localrc]]
|
||||
a=5
|
||||
@ -55,6 +65,18 @@ enable_plugin ironic https://github.com/openstack/ironic
|
||||
TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
|
||||
"""
|
||||
|
||||
LC3 = """
|
||||
[[post-config|$NEUTRON_CONF]]
|
||||
[quotas]
|
||||
quota_port = 500
|
||||
"""
|
||||
|
||||
LC4 = """
|
||||
[[post-config|$NEUTRON_CONF]]
|
||||
[DEFAULT]
|
||||
global_physnet_mtu=1400
|
||||
"""
|
||||
|
||||
RESULT1 = """
|
||||
[[local|localrc]]
|
||||
a=b
|
||||
@ -89,6 +111,29 @@ global_physnet_mtu=1450
|
||||
compute = auto
|
||||
"""
|
||||
|
||||
RESULT3 = """
|
||||
[[local|localrc]]
|
||||
a=b
|
||||
c=d
|
||||
f=1
|
||||
[[post-config|$NEUTRON_CONF]]
|
||||
[quotas]
|
||||
quota_network = 100
|
||||
quota_port = 500
|
||||
"""
|
||||
|
||||
RESULT4 = """
|
||||
[[local|localrc]]
|
||||
a=b
|
||||
c=d
|
||||
f=1
|
||||
[[post-config|$NEUTRON_CONF]]
|
||||
[quotas]
|
||||
quota_network = 100
|
||||
[DEFAULT]
|
||||
global_physnet_mtu = 1400
|
||||
"""
|
||||
|
||||
|
||||
class TestLcMerge(testtools.TestCase):
|
||||
|
||||
@ -122,3 +167,41 @@ class TestLcMerge(testtools.TestCase):
|
||||
with open(self._path) as f:
|
||||
content = f.read()
|
||||
self.assertEqual(content, RESULT2)
|
||||
|
||||
|
||||
class TestLcMergePost(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLcMergePost, self).setUp()
|
||||
self._path = self.useFixture(fixtures.TempDir()).path
|
||||
self._path += "/local.conf"
|
||||
with open(self._path, "w") as f:
|
||||
f.write(BASIC2)
|
||||
|
||||
def test_merge_lc3(self):
|
||||
"""Test merging with 2 post-config sections that should overlap."""
|
||||
|
||||
dirname = self.useFixture(fixtures.TempDir()).path
|
||||
lc = os.path.join(dirname, "local.conf")
|
||||
with open(lc, "w+") as f:
|
||||
f.write(LC3)
|
||||
conf = dsconf.LocalConf(self._path)
|
||||
conf.merge_lc(lc)
|
||||
|
||||
with open(self._path) as f:
|
||||
content = f.read()
|
||||
self.assertEqual(content, RESULT3)
|
||||
|
||||
def test_merge_lc4(self):
|
||||
"""Test merging with 2 post-config sections that should overlap."""
|
||||
|
||||
dirname = self.useFixture(fixtures.TempDir()).path
|
||||
lc = os.path.join(dirname, "local2.conf")
|
||||
with open(lc, "w+") as f:
|
||||
f.write(LC4)
|
||||
conf = dsconf.LocalConf(self._path)
|
||||
conf.merge_lc(lc)
|
||||
|
||||
with open(self._path) as f:
|
||||
content = f.read()
|
||||
self.assertEqual(content, RESULT4)
|
||||
|
Loading…
Reference in New Issue
Block a user