summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2017-01-16 12:45:37 -0500
committerSean Dague <sean@dague.net>2017-01-16 12:45:37 -0500
commita0f574ab9784e25963d42dee3c29ebbd54ea8f72 (patch)
tree6ec21901122f33f6c71e0318b6a2d3f5d0823216
parentedd7cc1bcc14980594ee7a7be80bff5f193c68b2 (diff)
add localrc extraction
-rw-r--r--devstack/dsconf.py29
-rw-r--r--devstack/tests/test_localconf_extract.py24
2 files changed, 43 insertions, 10 deletions
diff --git a/devstack/dsconf.py b/devstack/dsconf.py
index 8173420..4b1d4dc 100644
--- a/devstack/dsconf.py
+++ b/devstack/dsconf.py
@@ -134,8 +134,20 @@ class LocalConf(object):
134 self.fname = fname 134 self.fname = fname
135 135
136 def _conf(self, group, conf): 136 def _conf(self, group, conf):
137 in_section = False
138 current_section = "" 137 current_section = ""
138 for line in self._section(group, conf):
139 m = re.match("\[([^\[\]]+)\]", line)
140 if m:
141 current_section = m.group(1)
142 continue
143 else:
144 m2 = re.match(r"(\w+)\s*\=\s*(.+)", line)
145 if m2:
146 yield current_section, m2.group(1), m2.group(2)
147
148 def _section(self, group, conf):
149 """Yield all the lines out of a meta section."""
150 in_section = False
139 with open(self.fname) as reader: 151 with open(self.fname) as reader:
140 for line in reader.readlines(): 152 for line in reader.readlines():
141 if re.match(r"\[\[%s\|%s\]\]" % ( 153 if re.match(r"\[\[%s\|%s\]\]" % (
@@ -149,18 +161,15 @@ class LocalConf(object):
149 elif re.match("\[\[.*\|.*\]\]", line): 161 elif re.match("\[\[.*\|.*\]\]", line):
150 in_section = False 162 in_section = False
151 continue 163 continue
152
153 if in_section: 164 if in_section:
154 m = re.match("\[([^\[\]]+)\]", line) 165 yield line
155 if m:
156 current_section = m.group(1)
157 continue
158 else:
159 m2 = re.match(r"(\w+)\s*\=\s*(.+)", line)
160 if m2:
161 yield current_section, m2.group(1), m2.group(2)
162 166
163 def extract(self, group, conf, target): 167 def extract(self, group, conf, target):
164 ini_file = IniFile(target) 168 ini_file = IniFile(target)
165 for section, name, value in self._conf(group, conf): 169 for section, name, value in self._conf(group, conf):
166 ini_file.set(section, name, value) 170 ini_file.set(section, name, value)
171
172 def extract_localrc(self, target):
173 with open(target, "a+") as f:
174 for line in self._section("local", "localrc"):
175 f.write(line)
diff --git a/devstack/tests/test_localconf_extract.py b/devstack/tests/test_localconf_extract.py
index 499a381..bb38cc3 100644
--- a/devstack/tests/test_localconf_extract.py
+++ b/devstack/tests/test_localconf_extract.py
@@ -36,6 +36,17 @@ global_physnet_mtu=1450
36compute = auto 36compute = auto
37""" 37"""
38 38
39LOCALRC = """a = 1
40c = b
41"""
42
43LOCALRC_RES = """a = 1
44c = b
45a = b
46c = d
47f = 1
48"""
49
39NOVA = """[upgrade_levels] 50NOVA = """[upgrade_levels]
40compute = auto 51compute = auto
41""" 52"""
@@ -114,3 +125,16 @@ class TestLcExtract(testtools.TestCase):
114 with open(neutron) as f: 125 with open(neutron) as f:
115 content = f.read() 126 content = f.read()
116 self.assertEqual(content, NEUTRON_BASE2_RES) 127 self.assertEqual(content, NEUTRON_BASE2_RES)
128
129 def test_extract_localrc(self):
130 dirname = self.useFixture(fixtures.TempDir()).path
131 localrc = os.path.join(dirname, "localrc")
132 with open(localrc, "w+") as f:
133 f.write(LOCALRC)
134
135 conf = dsconf.LocalConf(self._path)
136 conf.extract_localrc(localrc)
137
138 with open(localrc) as f:
139 content = f.read()
140 self.assertEqual(content, LOCALRC_RES)