From 477fc18bd0febb2d53c0c5053ccff76ae1589d25 Mon Sep 17 00:00:00 2001 From: Paul Bourke Date: Fri, 15 Jan 2016 15:48:28 +0000 Subject: [PATCH] Fix image plugin functionality for oslo.config The new oslo.config style parsing for kolla-build.conf stopped plugins from working. This patch fixes it and adds a unit test. Co-Authored-By: Jeffrey Zhang Closes-Bug: 1534556 Change-Id: I135797c733ae0cae040a009c364073769b19e4eb --- kolla/cmd/build.py | 4 +++- kolla/tests/base.py | 8 +++++++ kolla/tests/docker/base/Dockerfile.j2 | 1 + .../tests/docker/neutron-server/Dockerfile.j2 | 1 + kolla/tests/etc/default.conf | 5 ++++ kolla/tests/test_build.py | 24 +++++++++++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 kolla/tests/docker/base/Dockerfile.j2 create mode 100644 kolla/tests/docker/neutron-server/Dockerfile.j2 diff --git a/kolla/cmd/build.py b/kolla/cmd/build.py index a127f02c8c..1202203310 100755 --- a/kolla/cmd/build.py +++ b/kolla/cmd/build.py @@ -604,7 +604,9 @@ class KollaWorker(object): for plugin in [match.group(0) for match in (re.search('{}-plugin-.+'.format(image['name']), section) for section in - self.conf._groups) if match]: + self.conf.list_all_sections()) if match]: + self.conf.register_opts(common_config.get_source_opts(), + plugin) image['plugins'].append( process_source_installation(image, plugin)) diff --git a/kolla/tests/base.py b/kolla/tests/base.py index e08adc39ba..0ac1467cce 100644 --- a/kolla/tests/base.py +++ b/kolla/tests/base.py @@ -11,6 +11,9 @@ # limitations under the License. import os + +import fixtures +import mock from oslo_config import cfg from oslotest import base as oslotest_base @@ -30,6 +33,11 @@ class TestCase(oslotest_base.BaseTestCase): default_config_files = self.get_default_config_files() common_config.parse(self.conf, [], default_config_files=default_config_files) + # NOTE(jeffrey4l): mock the _get_image_dir method to return a fake + # docker images dir + self.useFixture(fixtures.MockPatch( + 'kolla.cmd.build.KollaWorker._get_images_dir', + mock.Mock(return_value=os.path.join(TESTS_ROOT, 'docker')))) def get_default_config_files(self): if self.config_file: diff --git a/kolla/tests/docker/base/Dockerfile.j2 b/kolla/tests/docker/base/Dockerfile.j2 new file mode 100644 index 0000000000..ef5d2105a1 --- /dev/null +++ b/kolla/tests/docker/base/Dockerfile.j2 @@ -0,0 +1 @@ +FROM {{ base_distro }}:{{ base_distro_tag }} diff --git a/kolla/tests/docker/neutron-server/Dockerfile.j2 b/kolla/tests/docker/neutron-server/Dockerfile.j2 new file mode 100644 index 0000000000..ae637eec48 --- /dev/null +++ b/kolla/tests/docker/neutron-server/Dockerfile.j2 @@ -0,0 +1 @@ +FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }} diff --git a/kolla/tests/etc/default.conf b/kolla/tests/etc/default.conf index cbdb487c3f..234b5448eb 100644 --- a/kolla/tests/etc/default.conf +++ b/kolla/tests/etc/default.conf @@ -1,2 +1,7 @@ [DEFAULT] debug=True + +[neutron-server-plugin-networking-arista] +reference = master +location = https://github.com/openstack/networking-arista +type = git diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index 634fa3abbb..b014bc3b1f 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -107,6 +107,8 @@ class WorkerThreadTest(base.TestCase): class KollaWorkerTest(base.TestCase): + config_file = 'default.conf' + def test_supported_base_type(self): rh_base = ['fedora', 'centos', 'oraclelinux', 'rhel'] rh_type = ['source', 'binary', 'rdo', 'rhos'] @@ -128,3 +130,25 @@ class KollaWorkerTest(base.TestCase): self.conf.set_override('install_type', install_type) self.assertRaises(build.KollaMismatchBaseTypeException, build.KollaWorker, self.conf) + + def test_build_image_list_adds_plugins(self): + + self.conf.set_override('install_type', 'source') + + kolla = build.KollaWorker(self.conf) + kolla.setup_working_dir() + kolla.find_dockerfiles() + kolla.create_dockerfiles() + kolla.build_image_list() + expected_plugin = { + 'name': 'neutron-server-plugin-networking-arista', + 'reference': 'master', + 'source': 'https://github.com/openstack/networking-arista', + 'type': 'git' + } + for image in kolla.images: + if image['name'] == 'neutron-server': + self.assertEqual(image['plugins'][0], expected_plugin) + break + else: + self.fail('Can not find the expected neutron arista plugin')