Skip to content

Commit 18d1dc9

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "zuul: new variable to easily populate TEMPEST_PLUGINS"
2 parents d52b2f5 + 70d043d commit 18d1dc9

5 files changed

Lines changed: 96 additions & 43 deletions

File tree

doc/source/zuul_ci_jobs_migration.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ job.parent.
102102
tox_envlist: 'all'
103103
devstack_localrc:
104104
KURYR_K8S_API_PORT: 8080
105-
TEMPEST_PLUGINS: '/opt/stack/kuryr-tempest-plugin'
106105
devstack_services:
107106
kubernetes-api: true
108107
kubernetes-controller-manager: true
@@ -114,6 +113,8 @@ job.parent.
114113
kuryr-kubernetes: https://git.openstack.org/openstack/kuryr
115114
devstack-plugin-container: https://git.openstack.org/openstack/devstack-plugin-container
116115
neutron-lbaas: https://git.openstack.org/openstack/neutron-lbaas
116+
tempest_plugins:
117+
- kuryr-tempest-plugin
117118
(...)
118119
119120
Job variables

roles/write-devstack-local-conf/README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,12 @@ Write the local.conf file for use by devstack
8888
If a plugin declares a dependency on another plugin (via
8989
``plugin_requires`` in the plugin's settings file), this role will
9090
automatically emit ``enable_plugin`` lines in the correct order.
91+
92+
.. zuul:rolevar:: tempest_plugins
93+
:type: list
94+
95+
A list of tempest plugins which are installed alongside tempest.
96+
97+
The list of values will be combined with the base devstack directory
98+
and used to populate the ``TEMPEST_PLUGINS`` variable. If the variable
99+
already exists, its value is *not* changed.

roles/write-devstack-local-conf/library/devstack_local_conf.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,15 @@ def getPlugins(self):
207207
class LocalConf(object):
208208

209209
def __init__(self, localrc, localconf, base_services, services, plugins,
210-
base_dir, projects, project):
210+
base_dir, projects, project, tempest_plugins):
211211
self.localrc = []
212+
self.warnings = []
212213
self.meta_sections = {}
213214
self.plugin_deps = {}
214215
self.base_dir = base_dir
215216
self.projects = projects
216217
self.project = project
218+
self.tempest_plugins = tempest_plugins
217219
if services or base_services:
218220
self.handle_services(base_services, services or {})
219221
self.handle_localrc(localrc)
@@ -246,12 +248,15 @@ def handle_services(self, base_services, services):
246248

247249
def handle_localrc(self, localrc):
248250
lfg = False
251+
tp = False
249252
if localrc:
250253
vg = VarGraph(localrc)
251254
for k, v in vg.getVars():
252255
self.localrc.append('{}={}'.format(k, v))
253256
if k == 'LIBS_FROM_GIT':
254257
lfg = True
258+
elif k == 'TEMPEST_PLUGINS':
259+
tp = True
255260

256261
if not lfg and (self.projects or self.project):
257262
required_projects = []
@@ -266,6 +271,19 @@ def handle_localrc(self, localrc):
266271
self.localrc.append('LIBS_FROM_GIT={}'.format(
267272
','.join(required_projects)))
268273

274+
if self.tempest_plugins:
275+
if not tp:
276+
tp_dirs = []
277+
for tempest_plugin in self.tempest_plugins:
278+
tp_dirs.append(os.path.join(self.base_dir, tempest_plugin))
279+
self.localrc.append('TEMPEST_PLUGINS="{}"'.format(
280+
' '.join(tp_dirs)))
281+
else:
282+
self.warnings.append('TEMPEST_PLUGINS already defined ({}),'
283+
'requested value {} ignored'.format(
284+
tp, self.tempest_plugins))
285+
286+
269287
def handle_localconf(self, localconf):
270288
for phase, phase_data in localconf.items():
271289
for fn, fn_data in phase_data.items():
@@ -300,6 +318,7 @@ def main():
300318
path=dict(type='str'),
301319
projects=dict(type='dict'),
302320
project=dict(type='dict'),
321+
tempest_plugins=dict(type='list'),
303322
)
304323
)
305324

@@ -311,10 +330,11 @@ def main():
311330
p.get('plugins'),
312331
p.get('base_dir'),
313332
p.get('projects'),
314-
p.get('project'))
333+
p.get('project'),
334+
p.get('tempest_plugins'))
315335
lc.write(p['path'])
316336

317-
module.exit_json()
337+
module.exit_json(warnings=lc.warnings)
318338

319339

320340
try:

roles/write-devstack-local-conf/library/test.py

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
from collections import OrderedDict
2424

2525
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+
2640
def setUp(self):
2741
self.tmpdir = tempfile.mkdtemp()
2842

@@ -51,14 +65,7 @@ def test_plugins(self):
5165
plugins=plugins,
5266
base_dir='./test',
5367
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)
6269
lc.write(p['path'])
6370

6471
plugins = []
@@ -104,14 +111,7 @@ def test_plugin_deps(self):
104111
plugins=plugins,
105112
base_dir=self.tmpdir,
106113
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)
115115
lc.write(p['path'])
116116

117117
plugins = []
@@ -145,14 +145,7 @@ def test_libs_from_git(self):
145145
path=os.path.join(self.tmpdir, 'test.local.conf'),
146146
projects=projects,
147147
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)
156149
lc.write(p['path'])
157150

158151
lfg = None
@@ -184,14 +177,7 @@ def test_overridelibs_from_git(self):
184177
base_dir='./test',
185178
path=os.path.join(self.tmpdir, 'test.local.conf'),
186179
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)
195181
lc.write(p['path'])
196182

197183
lfg = None
@@ -238,14 +224,50 @@ def test_plugin_circular_deps(self):
238224
base_dir=self.tmpdir,
239225
path=os.path.join(self.tmpdir, 'test.local.conf'))
240226
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)
247228
lc.write(p['path'])
248229

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+
249271

250272
if __name__ == '__main__':
251273
unittest.main()

roles/write-devstack-local-conf/tasks/main.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
local_conf: "{{ devstack_local_conf|default(omit) }}"
1111
base_dir: "{{ devstack_base_dir|default(omit) }}"
1212
projects: "{{ zuul.projects }}"
13-
project: "{{ zuul.project }}"
13+
project: "{{ zuul.project }}"
14+
tempest_plugins: "{{ tempest_plugins|default(omit) }}"

0 commit comments

Comments
 (0)