summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2017-02-10 16:57:34 -0500
committerSean Dague <sean@dague.net>2017-02-10 16:57:34 -0500
commitde46354ed3eb8ef7489e368d0995c36e218a8d33 (patch)
treeed1cde7277dac071eac1f6903920af6b8260b548
parente0098fc212a9d6f19c2f65b9d1965066b190814e (diff)
new localrc set strategy
the localrc is really just executable shell, which means there are tons of edgecases where you can't treat it the same as simple assignment a=b. Instead of trying to be smart about things and reduce duplication in the localrc files, just do the naive thing and stack up all the shell declarations in order. When evaluated in shell they will end up stacking up as expected. Change-Id: I231d130b24b02cdd79618f85472cee21905884e0
Notes
Notes (review): Code-Review+2: Sean Dague <sean@dague.net> Workflow+1: Sean Dague <sean@dague.net> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 13 Feb 2017 12:19:51 +0000 Reviewed-on: https://review.openstack.org/432475 Project: openstack/devstack-tools Branch: refs/heads/master
-rw-r--r--devstack/dsconf.py59
-rw-r--r--devstack/tests/test_localconf_merge.py4
-rw-r--r--devstack/tests/test_localconf_set_local.py7
3 files changed, 27 insertions, 43 deletions
diff --git a/devstack/dsconf.py b/devstack/dsconf.py
index 72b8d6d..8b4d6f3 100644
--- a/devstack/dsconf.py
+++ b/devstack/dsconf.py
@@ -199,36 +199,16 @@ class LocalConf(object):
199 199
200 if re.match(re.escape("[[local|localrc]]"), line): 200 if re.match(re.escape("[[local|localrc]]"), line):
201 in_meta = True 201 in_meta = True
202 writer.write(line) 202 elif in_meta and re.match(re.escape("[["), line):
203 elif re.match("\[\[.*\|.*\]\]", line): 203 func(writer, None)
204 # if we're not done yet, we
205 if in_meta:
206 func(writer, None)
207 writer.write(line)
208 done = True
209 in_meta = False
210 continue
211 elif re.match("\s*%s\s*\=" % re.escape(name), line):
212 # we found our key, pass to the writer func
213 func(writer, line)
214 done = True 204 done = True
215 else: 205 in_meta = False
216 # write out whatever we find 206
217 writer.write(line) 207 # otherwise, just write what we found
208 writer.write(line)
218 if not done: 209 if not done:
219 func(writer, None) 210 func(writer, None)
220 211
221 def set_local(self, name, value):
222 if not os.path.exists(self.fname):
223 with open(self.fname, "w+") as writer:
224 writer.write("[[local|localrc]]\n")
225 writer.write("%s=%s\n" % (name, value))
226 return
227
228 def _do_set(writer, line):
229 writer.write("%s=%s\n" % (name, value))
230 self._at_insert_point_local(name, _do_set)
231
232 def set_local_raw(self, line): 212 def set_local_raw(self, line):
233 if not os.path.exists(self.fname): 213 if not os.path.exists(self.fname):
234 with open(self.fname, "w+") as writer: 214 with open(self.fname, "w+") as writer:
@@ -312,19 +292,20 @@ class LocalConf(object):
312 for group, conf in groups: 292 for group, conf in groups:
313 if group == "local": 293 if group == "local":
314 for line in lc._section(group, conf): 294 for line in lc._section(group, conf):
315 if line.startswith('#'): 295 self.set_local_raw(line)
316 continue 296 # if line.startswith('#'):
317 m = re.match(r"([^#=\s]+)\s*\=\s*(.+)", line) 297 # continue
318 298 # m = re.match(r"([^#=\s]+)\s*\=\s*(.+)", line)
319 if m: 299
320 self.set_local(m.group(1), m.group(2)) 300 # if m:
321 elif re.match("(enable|disable)", line): 301 # self.set_local(m.group(1), m.group(2))
322 # special case appending enable* disable* 302 # elif re.match("(enable|disable)", line):
323 # function lines 303 # # special case appending enable* disable*
324 self.set_local_raw(line) 304 # # function lines
325 else: 305 # self.set_local_raw(line)
326 print("SKIPPING ``%s`` from '%s'" % 306 # else:
327 (line.lstrip(), lcfile)) 307 # print("SKIPPING ``%s`` from '%s'" %
308 # (line.lstrip(), lcfile))
328 else: 309 else:
329 for section, name, value in lc._conf(group, conf): 310 for section, name, value in lc._conf(group, conf):
330 self.set(group, conf, section, name, value) 311 self.set(group, conf, section, name, value)
diff --git a/devstack/tests/test_localconf_merge.py b/devstack/tests/test_localconf_merge.py
index d1ad75f..a89e36c 100644
--- a/devstack/tests/test_localconf_merge.py
+++ b/devstack/tests/test_localconf_merge.py
@@ -57,9 +57,10 @@ TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
57 57
58RESULT1 = """ 58RESULT1 = """
59[[local|localrc]] 59[[local|localrc]]
60a=5 60a=b
61c=d 61c=d
62f=1 62f=1
63a=5
63g=2 64g=2
64[[post-config|$NEUTRON_CONF]] 65[[post-config|$NEUTRON_CONF]]
65[DEFAULT] 66[DEFAULT]
@@ -77,6 +78,7 @@ RESULT2 = """
77a=b 78a=b
78c=d 79c=d
79f=1 80f=1
81# some other comment
80enable_plugin ironic https://github.com/openstack/ironic 82enable_plugin ironic https://github.com/openstack/ironic
81TEMPEST_PLUGINS+=" /opt/stack/new/ironic" 83TEMPEST_PLUGINS+=" /opt/stack/new/ironic"
82[[post-config|$NEUTRON_CONF]] 84[[post-config|$NEUTRON_CONF]]
diff --git a/devstack/tests/test_localconf_set_local.py b/devstack/tests/test_localconf_set_local.py
index daf6c59..8e9f019 100644
--- a/devstack/tests/test_localconf_set_local.py
+++ b/devstack/tests/test_localconf_set_local.py
@@ -51,9 +51,10 @@ compute = auto
51 51
52RESULT2 = """ 52RESULT2 = """
53[[local|localrc]] 53[[local|localrc]]
54a=2 54a=b
55c=d 55c=d
56f=1 56f=1
57a=2
57[[post-config|$NEUTRON_CONF]] 58[[post-config|$NEUTRON_CONF]]
58[DEFAULT] 59[DEFAULT]
59global_physnet_mtu=1450 60global_physnet_mtu=1450
@@ -89,14 +90,14 @@ class TestLcSet(testtools.TestCase):
89 90
90 def test_set_new(self): 91 def test_set_new(self):
91 conf = dsconf.LocalConf(self._path) 92 conf = dsconf.LocalConf(self._path)
92 conf.set_local("g", "2") 93 conf.set_local_raw("g=2")
93 with open(self._path) as f: 94 with open(self._path) as f:
94 content = f.read() 95 content = f.read()
95 self.assertEqual(content, RESULT1) 96 self.assertEqual(content, RESULT1)
96 97
97 def test_set_existing(self): 98 def test_set_existing(self):
98 conf = dsconf.LocalConf(self._path) 99 conf = dsconf.LocalConf(self._path)
99 conf.set_local("a", "2") 100 conf.set_local_raw("a=2")
100 with open(self._path) as f: 101 with open(self._path) as f:
101 content = f.read() 102 content = f.read()
102 self.assertEqual(content, RESULT2) 103 self.assertEqual(content, RESULT2)