|
23 | 23 | from collections import OrderedDict |
24 | 24 |
|
25 | 25 | class TestDevstackLocalConf(unittest.TestCase): |
| 26 | + |
| 27 | + @staticmethod |
| 28 | + def _init_localconf(p): |
| 29 | + lc = LocalConf(p.get('localrc'), |
| 30 | + p.get('local_conf'), |
| 31 | + p.get('base_services'), |
| 32 | + p.get('services'), |
| 33 | + p.get('plugins'), |
| 34 | + p.get('base_dir'), |
| 35 | + p.get('projects'), |
| 36 | + p.get('project'), |
| 37 | + p.get('tempest_plugins')) |
| 38 | + return lc |
| 39 | + |
26 | 40 | def setUp(self): |
27 | 41 | self.tmpdir = tempfile.mkdtemp() |
28 | 42 |
|
@@ -51,14 +65,7 @@ def test_plugins(self): |
51 | 65 | plugins=plugins, |
52 | 66 | base_dir='./test', |
53 | 67 | path=os.path.join(self.tmpdir, 'test.local.conf')) |
54 | | - lc = LocalConf(p.get('localrc'), |
55 | | - p.get('local_conf'), |
56 | | - p.get('base_services'), |
57 | | - p.get('services'), |
58 | | - p.get('plugins'), |
59 | | - p.get('base_dir'), |
60 | | - p.get('projects'), |
61 | | - p.get('project')) |
| 68 | + lc = self._init_localconf(p) |
62 | 69 | lc.write(p['path']) |
63 | 70 |
|
64 | 71 | plugins = [] |
@@ -104,14 +111,7 @@ def test_plugin_deps(self): |
104 | 111 | plugins=plugins, |
105 | 112 | base_dir=self.tmpdir, |
106 | 113 | path=os.path.join(self.tmpdir, 'test.local.conf')) |
107 | | - lc = LocalConf(p.get('localrc'), |
108 | | - p.get('local_conf'), |
109 | | - p.get('base_services'), |
110 | | - p.get('services'), |
111 | | - p.get('plugins'), |
112 | | - p.get('base_dir'), |
113 | | - p.get('projects'), |
114 | | - p.get('project')) |
| 114 | + lc = self._init_localconf(p) |
115 | 115 | lc.write(p['path']) |
116 | 116 |
|
117 | 117 | plugins = [] |
@@ -145,14 +145,7 @@ def test_libs_from_git(self): |
145 | 145 | path=os.path.join(self.tmpdir, 'test.local.conf'), |
146 | 146 | projects=projects, |
147 | 147 | project=project) |
148 | | - lc = LocalConf(p.get('localrc'), |
149 | | - p.get('local_conf'), |
150 | | - p.get('base_services'), |
151 | | - p.get('services'), |
152 | | - p.get('plugins'), |
153 | | - p.get('base_dir'), |
154 | | - p.get('projects'), |
155 | | - p.get('project')) |
| 148 | + lc = self._init_localconf(p) |
156 | 149 | lc.write(p['path']) |
157 | 150 |
|
158 | 151 | lfg = None |
@@ -184,14 +177,7 @@ def test_overridelibs_from_git(self): |
184 | 177 | base_dir='./test', |
185 | 178 | path=os.path.join(self.tmpdir, 'test.local.conf'), |
186 | 179 | projects=projects) |
187 | | - lc = LocalConf(p.get('localrc'), |
188 | | - p.get('local_conf'), |
189 | | - p.get('base_services'), |
190 | | - p.get('services'), |
191 | | - p.get('plugins'), |
192 | | - p.get('base_dir'), |
193 | | - p.get('projects'), |
194 | | - p.get('project')) |
| 180 | + lc = self._init_localconf(p) |
195 | 181 | lc.write(p['path']) |
196 | 182 |
|
197 | 183 | lfg = None |
@@ -238,14 +224,50 @@ def test_plugin_circular_deps(self): |
238 | 224 | base_dir=self.tmpdir, |
239 | 225 | path=os.path.join(self.tmpdir, 'test.local.conf')) |
240 | 226 | with self.assertRaises(Exception): |
241 | | - lc = LocalConf(p.get('localrc'), |
242 | | - p.get('local_conf'), |
243 | | - p.get('base_services'), |
244 | | - p.get('services'), |
245 | | - p.get('plugins'), |
246 | | - p.get('base_dir')) |
| 227 | + lc = self._init_localconf(p) |
247 | 228 | lc.write(p['path']) |
248 | 229 |
|
| 230 | + def _find_tempest_plugins_value(self, file_path): |
| 231 | + tp = None |
| 232 | + with open(file_path) as f: |
| 233 | + for line in f: |
| 234 | + if line.startswith('TEMPEST_PLUGINS'): |
| 235 | + found = line.strip().split('=')[1] |
| 236 | + self.assertIsNone(tp, |
| 237 | + "TEMPEST_PLUGIN ({}) found again ({})".format( |
| 238 | + tp, found)) |
| 239 | + tp = found |
| 240 | + return tp |
| 241 | + |
| 242 | + def test_tempest_plugins(self): |
| 243 | + "Test that TEMPEST_PLUGINS is correctly populated." |
| 244 | + p = dict(base_services=[], |
| 245 | + base_dir='./test', |
| 246 | + path=os.path.join(self.tmpdir, 'test.local.conf'), |
| 247 | + tempest_plugins=['heat-tempest-plugin', 'sahara-tests']) |
| 248 | + lc = self._init_localconf(p) |
| 249 | + lc.write(p['path']) |
| 250 | + |
| 251 | + tp = self._find_tempest_plugins_value(p['path']) |
| 252 | + self.assertEqual('"./test/heat-tempest-plugin ./test/sahara-tests"', tp) |
| 253 | + self.assertEqual(len(lc.warnings), 0) |
| 254 | + |
| 255 | + def test_tempest_plugins_not_overridden(self): |
| 256 | + """Test that the existing value of TEMPEST_PLUGINS is not overridden |
| 257 | + by the user-provided value, but a warning is emitted.""" |
| 258 | + localrc = {'TEMPEST_PLUGINS': 'someplugin'} |
| 259 | + p = dict(localrc=localrc, |
| 260 | + base_services=[], |
| 261 | + base_dir='./test', |
| 262 | + path=os.path.join(self.tmpdir, 'test.local.conf'), |
| 263 | + tempest_plugins=['heat-tempest-plugin', 'sahara-tests']) |
| 264 | + lc = self._init_localconf(p) |
| 265 | + lc.write(p['path']) |
| 266 | + |
| 267 | + tp = self._find_tempest_plugins_value(p['path']) |
| 268 | + self.assertEqual('someplugin', tp) |
| 269 | + self.assertEqual(len(lc.warnings), 1) |
| 270 | + |
249 | 271 |
|
250 | 272 | if __name__ == '__main__': |
251 | 273 | unittest.main() |
0 commit comments