2017-11-21 17:05:43 -08:00
|
|
|
# Copyright (C) 2017 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
# implied.
|
|
|
|
#
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from devstack_local_conf import LocalConf
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
class TestDevstackLocalConf(unittest.TestCase):
|
2019-03-12 22:25:44 +01:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _init_localconf(p):
|
|
|
|
lc = LocalConf(p.get('localrc'),
|
|
|
|
p.get('local_conf'),
|
|
|
|
p.get('base_services'),
|
|
|
|
p.get('services'),
|
|
|
|
p.get('plugins'),
|
|
|
|
p.get('base_dir'),
|
|
|
|
p.get('projects'),
|
|
|
|
p.get('project'),
|
|
|
|
p.get('tempest_plugins'))
|
|
|
|
return lc
|
|
|
|
|
2017-11-21 17:05:43 -08:00
|
|
|
def setUp(self):
|
|
|
|
self.tmpdir = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
shutil.rmtree(self.tmpdir)
|
|
|
|
|
|
|
|
def test_plugins(self):
|
|
|
|
"Test that plugins without dependencies work"
|
|
|
|
localrc = {'test_localrc': '1'}
|
|
|
|
local_conf = {'install':
|
|
|
|
{'nova.conf':
|
|
|
|
{'main':
|
|
|
|
{'test_conf': '2'}}}}
|
|
|
|
services = {'cinder': True}
|
|
|
|
# We use ordereddict here to make sure the plugins are in the
|
|
|
|
# *wrong* order for testing.
|
|
|
|
plugins = OrderedDict([
|
2019-03-04 16:50:42 +11:00
|
|
|
('bar', 'https://git.openstack.org/openstack/bar-plugin'),
|
|
|
|
('foo', 'https://git.openstack.org/openstack/foo-plugin'),
|
|
|
|
('baz', 'https://git.openstack.org/openstack/baz-plugin'),
|
2017-11-21 17:05:43 -08:00
|
|
|
])
|
|
|
|
p = dict(localrc=localrc,
|
|
|
|
local_conf=local_conf,
|
|
|
|
base_services=[],
|
|
|
|
services=services,
|
|
|
|
plugins=plugins,
|
|
|
|
base_dir='./test',
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'))
|
2019-03-12 22:25:44 +01:00
|
|
|
lc = self._init_localconf(p)
|
2017-11-21 17:05:43 -08:00
|
|
|
lc.write(p['path'])
|
|
|
|
|
|
|
|
plugins = []
|
|
|
|
with open(p['path']) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('enable_plugin'):
|
|
|
|
plugins.append(line.split()[1])
|
|
|
|
self.assertEqual(['bar', 'baz', 'foo'], plugins)
|
|
|
|
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
|
2017-11-21 17:05:43 -08:00
|
|
|
def test_plugin_deps(self):
|
|
|
|
"Test that plugins with dependencies work"
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'foo-plugin', 'devstack'))
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'foo-plugin', '.git'))
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'bar-plugin', 'devstack'))
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'bar-plugin', '.git'))
|
|
|
|
with open(os.path.join(
|
|
|
|
self.tmpdir,
|
|
|
|
'foo-plugin', 'devstack', 'settings'), 'w') as f:
|
2018-12-19 12:20:51 +00:00
|
|
|
f.write('define_plugin foo-plugin\n')
|
2017-11-21 17:05:43 -08:00
|
|
|
with open(os.path.join(
|
|
|
|
self.tmpdir,
|
|
|
|
'bar-plugin', 'devstack', 'settings'), 'w') as f:
|
2018-12-19 12:20:51 +00:00
|
|
|
f.write('define_plugin bar-plugin\n')
|
|
|
|
f.write('plugin_requires bar-plugin foo-plugin\n')
|
2017-11-21 17:05:43 -08:00
|
|
|
|
|
|
|
localrc = {'test_localrc': '1'}
|
|
|
|
local_conf = {'install':
|
|
|
|
{'nova.conf':
|
|
|
|
{'main':
|
|
|
|
{'test_conf': '2'}}}}
|
|
|
|
services = {'cinder': True}
|
|
|
|
# We use ordereddict here to make sure the plugins are in the
|
|
|
|
# *wrong* order for testing.
|
|
|
|
plugins = OrderedDict([
|
2019-03-04 16:50:42 +11:00
|
|
|
('bar-plugin', 'https://git.openstack.org/openstack/bar-plugin'),
|
|
|
|
('foo-plugin', 'https://git.openstack.org/openstack/foo-plugin'),
|
2017-11-21 17:05:43 -08:00
|
|
|
])
|
|
|
|
p = dict(localrc=localrc,
|
|
|
|
local_conf=local_conf,
|
|
|
|
base_services=[],
|
|
|
|
services=services,
|
|
|
|
plugins=plugins,
|
|
|
|
base_dir=self.tmpdir,
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'))
|
2019-03-12 22:25:44 +01:00
|
|
|
lc = self._init_localconf(p)
|
2018-12-19 11:53:16 +00:00
|
|
|
lc.write(p['path'])
|
|
|
|
|
|
|
|
plugins = []
|
|
|
|
with open(p['path']) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('enable_plugin'):
|
|
|
|
plugins.append(line.split()[1])
|
2018-12-19 12:20:51 +00:00
|
|
|
self.assertEqual(['foo-plugin', 'bar-plugin'], plugins)
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
|
|
|
|
def test_libs_from_git(self):
|
|
|
|
"Test that LIBS_FROM_GIT is auto-generated"
|
|
|
|
projects = {
|
|
|
|
'git.openstack.org/openstack/nova': {
|
|
|
|
'required': True,
|
|
|
|
'short_name': 'nova',
|
|
|
|
},
|
|
|
|
'git.openstack.org/openstack/oslo.messaging': {
|
|
|
|
'required': True,
|
|
|
|
'short_name': 'oslo.messaging',
|
|
|
|
},
|
|
|
|
'git.openstack.org/openstack/devstack-plugin': {
|
|
|
|
'required': False,
|
|
|
|
'short_name': 'devstack-plugin',
|
|
|
|
},
|
|
|
|
}
|
2018-06-15 10:10:35 -07:00
|
|
|
project = {
|
|
|
|
'short_name': 'glance',
|
|
|
|
}
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
p = dict(base_services=[],
|
|
|
|
base_dir='./test',
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'),
|
2018-06-15 10:10:35 -07:00
|
|
|
projects=projects,
|
|
|
|
project=project)
|
2019-03-12 22:25:44 +01:00
|
|
|
lc = self._init_localconf(p)
|
2017-11-21 17:05:43 -08:00
|
|
|
lc.write(p['path'])
|
|
|
|
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
lfg = None
|
2017-11-21 17:05:43 -08:00
|
|
|
with open(p['path']) as f:
|
|
|
|
for line in f:
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
if line.startswith('LIBS_FROM_GIT'):
|
|
|
|
lfg = line.strip().split('=')[1]
|
2018-06-15 10:10:35 -07:00
|
|
|
self.assertEqual('nova,oslo.messaging,glance', lfg)
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
|
|
|
|
def test_overridelibs_from_git(self):
|
|
|
|
"Test that LIBS_FROM_GIT can be overridden"
|
|
|
|
localrc = {'LIBS_FROM_GIT': 'oslo.db'}
|
|
|
|
projects = {
|
|
|
|
'git.openstack.org/openstack/nova': {
|
|
|
|
'required': True,
|
|
|
|
'short_name': 'nova',
|
|
|
|
},
|
|
|
|
'git.openstack.org/openstack/oslo.messaging': {
|
|
|
|
'required': True,
|
|
|
|
'short_name': 'oslo.messaging',
|
|
|
|
},
|
|
|
|
'git.openstack.org/openstack/devstack-plugin': {
|
|
|
|
'required': False,
|
|
|
|
'short_name': 'devstack-plugin',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
p = dict(localrc=localrc,
|
|
|
|
base_services=[],
|
|
|
|
base_dir='./test',
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'),
|
|
|
|
projects=projects)
|
2019-03-12 22:25:44 +01:00
|
|
|
lc = self._init_localconf(p)
|
Automatically set LIBS_FROM_GIT based on required projects
If a project shows up in zuul's required-projects list, add it
to LIBS_FROM_GIT automatically. This way, when a user specifies
that a job requires a zuul-project, it gets used in testing, but
otherwise, it doesn't (pypi is used instead).
Also add information about what happens behind the scenes for both
LIBS_FROM_GIT and plugin dependencies.
This moves the check performed in check_libs_from_git to
a helper function which is installed for most kinds of
installations. This means that if someone sets LIBS_FROM_GIT to
"foobar", devstack won't error anymore, as nothing is going to
try to install foobar, therefore the check won't run on that.
However, as we move to automated generation of the local config,
that error is not likely to happen. This check was originally
added due to an error in the upper-constraints file (where a
constraint name did not match a package name). This location of
the check would still catch that type of error.
Change-Id: Ifcf3ad008cf42d3d4762cfb3b6c31c93cfeb40db
2018-03-02 15:05:14 +00:00
|
|
|
lc.write(p['path'])
|
|
|
|
|
|
|
|
lfg = None
|
|
|
|
with open(p['path']) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('LIBS_FROM_GIT'):
|
|
|
|
lfg = line.strip().split('=')[1]
|
2019-02-11 12:26:03 +11:00
|
|
|
self.assertEqual('"oslo.db"', lfg)
|
2017-11-21 17:05:43 -08:00
|
|
|
|
2019-04-01 11:43:28 +00:00
|
|
|
def test_avoid_double_quote(self):
|
|
|
|
"Test that there a no duplicated quotes"
|
|
|
|
localrc = {'TESTVAR': '"quoted value"'}
|
|
|
|
p = dict(localrc=localrc,
|
|
|
|
base_services=[],
|
|
|
|
base_dir='./test',
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'),
|
|
|
|
projects={})
|
|
|
|
lc = self._init_localconf(p)
|
|
|
|
lc.write(p['path'])
|
|
|
|
|
|
|
|
testvar = None
|
|
|
|
with open(p['path']) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('TESTVAR'):
|
|
|
|
testvar = line.strip().split('=')[1]
|
|
|
|
self.assertEqual('"quoted value"', testvar)
|
|
|
|
|
2017-11-21 17:05:43 -08:00
|
|
|
def test_plugin_circular_deps(self):
|
|
|
|
"Test that plugins with circular dependencies fail"
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'foo-plugin', 'devstack'))
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'foo-plugin', '.git'))
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'bar-plugin', 'devstack'))
|
|
|
|
os.makedirs(os.path.join(self.tmpdir, 'bar-plugin', '.git'))
|
|
|
|
with open(os.path.join(
|
|
|
|
self.tmpdir,
|
|
|
|
'foo-plugin', 'devstack', 'settings'), 'w') as f:
|
|
|
|
f.write('define_plugin foo\n')
|
|
|
|
f.write('plugin_requires foo bar\n')
|
|
|
|
with open(os.path.join(
|
|
|
|
self.tmpdir,
|
|
|
|
'bar-plugin', 'devstack', 'settings'), 'w') as f:
|
|
|
|
f.write('define_plugin bar\n')
|
|
|
|
f.write('plugin_requires bar foo\n')
|
|
|
|
|
|
|
|
localrc = {'test_localrc': '1'}
|
|
|
|
local_conf = {'install':
|
|
|
|
{'nova.conf':
|
|
|
|
{'main':
|
|
|
|
{'test_conf': '2'}}}}
|
|
|
|
services = {'cinder': True}
|
|
|
|
# We use ordereddict here to make sure the plugins are in the
|
|
|
|
# *wrong* order for testing.
|
|
|
|
plugins = OrderedDict([
|
2019-03-04 16:50:42 +11:00
|
|
|
('bar', 'https://git.openstack.org/openstack/bar-plugin'),
|
|
|
|
('foo', 'https://git.openstack.org/openstack/foo-plugin'),
|
2017-11-21 17:05:43 -08:00
|
|
|
])
|
|
|
|
p = dict(localrc=localrc,
|
|
|
|
local_conf=local_conf,
|
|
|
|
base_services=[],
|
|
|
|
services=services,
|
|
|
|
plugins=plugins,
|
|
|
|
base_dir=self.tmpdir,
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'))
|
|
|
|
with self.assertRaises(Exception):
|
2019-03-12 22:25:44 +01:00
|
|
|
lc = self._init_localconf(p)
|
2017-11-21 17:05:43 -08:00
|
|
|
lc.write(p['path'])
|
|
|
|
|
2019-03-12 22:25:44 +01:00
|
|
|
def _find_tempest_plugins_value(self, file_path):
|
|
|
|
tp = None
|
|
|
|
with open(file_path) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('TEMPEST_PLUGINS'):
|
|
|
|
found = line.strip().split('=')[1]
|
|
|
|
self.assertIsNone(tp,
|
|
|
|
"TEMPEST_PLUGIN ({}) found again ({})".format(
|
|
|
|
tp, found))
|
|
|
|
tp = found
|
|
|
|
return tp
|
|
|
|
|
|
|
|
def test_tempest_plugins(self):
|
|
|
|
"Test that TEMPEST_PLUGINS is correctly populated."
|
|
|
|
p = dict(base_services=[],
|
|
|
|
base_dir='./test',
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'),
|
|
|
|
tempest_plugins=['heat-tempest-plugin', 'sahara-tests'])
|
|
|
|
lc = self._init_localconf(p)
|
|
|
|
lc.write(p['path'])
|
|
|
|
|
|
|
|
tp = self._find_tempest_plugins_value(p['path'])
|
|
|
|
self.assertEqual('"./test/heat-tempest-plugin ./test/sahara-tests"', tp)
|
|
|
|
self.assertEqual(len(lc.warnings), 0)
|
|
|
|
|
|
|
|
def test_tempest_plugins_not_overridden(self):
|
|
|
|
"""Test that the existing value of TEMPEST_PLUGINS is not overridden
|
|
|
|
by the user-provided value, but a warning is emitted."""
|
|
|
|
localrc = {'TEMPEST_PLUGINS': 'someplugin'}
|
|
|
|
p = dict(localrc=localrc,
|
|
|
|
base_services=[],
|
|
|
|
base_dir='./test',
|
|
|
|
path=os.path.join(self.tmpdir, 'test.local.conf'),
|
|
|
|
tempest_plugins=['heat-tempest-plugin', 'sahara-tests'])
|
|
|
|
lc = self._init_localconf(p)
|
|
|
|
lc.write(p['path'])
|
|
|
|
|
|
|
|
tp = self._find_tempest_plugins_value(p['path'])
|
2019-02-11 12:26:03 +11:00
|
|
|
self.assertEqual('"someplugin"', tp)
|
2019-03-12 22:25:44 +01:00
|
|
|
self.assertEqual(len(lc.warnings), 1)
|
|
|
|
|
2017-11-21 17:05:43 -08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|