From 08a48895c4117693cb49d47e59d76cf49f637932 Mon Sep 17 00:00:00 2001 From: Hieu LE Date: Mon, 22 Aug 2016 16:33:11 +0700 Subject: [PATCH] Centralize config option: docker_registry section Centralize config option of docker_registry section. Replace oslo_conf cfg to magnum.conf. Change-Id: I43d3ce068bb6638f71ea14577f34c1df3d7c9d8c Implements: blueprint centralize-config-magnum --- .../drivers/k8s_opensuse_v1/template_def.py | 4 +- etc/magnum/magnum-config-generator.conf | 1 - magnum/conf/__init__.py | 2 + magnum/conf/docker_registry.py | 38 +++++++++++++++++++ magnum/drivers/common/template_def.py | 14 +------ magnum/drivers/k8s_coreos_v1/template_def.py | 4 +- .../k8s_fedora_atomic_v1/template_def.py | 4 +- .../swarm_fedora_atomic_v1/template_def.py | 3 -- magnum/opts.py | 23 ----------- .../handlers/test_swarm_cluster_conductor.py | 10 +++-- magnum/tests/unit/test_opts.py | 28 -------------- 11 files changed, 53 insertions(+), 78 deletions(-) create mode 100644 magnum/conf/docker_registry.py delete mode 100644 magnum/opts.py delete mode 100644 magnum/tests/unit/test_opts.py diff --git a/contrib/drivers/k8s_opensuse_v1/template_def.py b/contrib/drivers/k8s_opensuse_v1/template_def.py index 5fa9a834a2..c828278a49 100644 --- a/contrib/drivers/k8s_opensuse_v1/template_def.py +++ b/contrib/drivers/k8s_opensuse_v1/template_def.py @@ -14,10 +14,10 @@ import os +import magnum.conf from magnum.drivers.common import k8s_template_def -from oslo_config import cfg -CONF = cfg.CONF +CONF = magnum.conf.CONF class JeOSK8sTemplateDefinition(k8s_template_def.K8sTemplateDefinition): diff --git a/etc/magnum/magnum-config-generator.conf b/etc/magnum/magnum-config-generator.conf index a2514810a5..23dc094e76 100644 --- a/etc/magnum/magnum-config-generator.conf +++ b/etc/magnum/magnum-config-generator.conf @@ -2,7 +2,6 @@ output_file = etc/magnum/magnum.conf.sample wrap_width = 79 -namespace = magnum namespace = magnum.conf namespace = oslo.concurrency namespace = oslo.db diff --git a/magnum/conf/__init__.py b/magnum/conf/__init__.py index 72e4d676fe..8c0f6f6c36 100644 --- a/magnum/conf/__init__.py +++ b/magnum/conf/__init__.py @@ -25,6 +25,7 @@ from magnum.conf import cluster_templates from magnum.conf import conductor from magnum.conf import database from magnum.conf import docker +from magnum.conf import docker_registry from magnum.conf import glance from magnum.conf import heat from magnum.conf import keystone @@ -50,6 +51,7 @@ cinder.register_opts(CONF) conductor.register_opts(CONF) database.register_opts(CONF) docker.register_opts(CONF) +docker_registry.register_opts(CONF) glance.register_opts(CONF) heat.register_opts(CONF) keystone.register_opts(CONF) diff --git a/magnum/conf/docker_registry.py b/magnum/conf/docker_registry.py new file mode 100644 index 0000000000..36b27f5506 --- /dev/null +++ b/magnum/conf/docker_registry.py @@ -0,0 +1,38 @@ +# 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. + +from oslo_config import cfg + +from magnum.i18n import _ + +docker_registry_group = cfg.OptGroup(name='docker_registry', + title='Options for Docker Registry') + +docker_registry_opts = [ + cfg.StrOpt('swift_region', + help=_('Region name of Swift')), + cfg.StrOpt('swift_registry_container', + default='docker_registry', + help=_('Name of the container in Swift which docker registry ' + 'stores images in')) +] + + +def register_opts(conf): + conf.register_group(docker_registry_group) + conf.register_opts(docker_registry_opts, group=docker_registry_group) + + +def list_opts(): + return { + docker_registry_group: docker_registry_opts + } diff --git a/magnum/drivers/common/template_def.py b/magnum/drivers/common/template_def.py index 7ac088306e..577c196f89 100644 --- a/magnum/drivers/common/template_def.py +++ b/magnum/drivers/common/template_def.py @@ -14,7 +14,6 @@ import abc import ast -from oslo_config import cfg from oslo_log import log as logging import requests import six @@ -22,7 +21,6 @@ import six from magnum.common import clients from magnum.common import exception import magnum.conf -from magnum.i18n import _ from magnum.i18n import _LW from requests import exceptions as req_exceptions @@ -32,17 +30,7 @@ LOG = logging.getLogger(__name__) COMMON_TEMPLATES_PATH = "../../common/templates/" COMMON_ENV_PATH = COMMON_TEMPLATES_PATH + "environments/" -docker_registry_opts = [ - cfg.StrOpt('swift_region', - help=_('Region name of Swift')), - cfg.StrOpt('swift_registry_container', - default='docker_registry', - help=_('Name of the container in Swift which docker registry ' - 'stores images in')) -] - CONF = magnum.conf.CONF -CONF.register_opts(docker_registry_opts, group='docker_registry') class ParameterMapping(object): @@ -310,7 +298,7 @@ class BaseTemplateDefinition(TemplateDefinition): discovery_url = cluster.discovery_url else: discovery_endpoint = ( - cfg.CONF.cluster.etcd_discovery_service_endpoint_format % + CONF.cluster.etcd_discovery_service_endpoint_format % {'size': cluster.master_count}) try: discovery_url = requests.get(discovery_endpoint).text diff --git a/magnum/drivers/k8s_coreos_v1/template_def.py b/magnum/drivers/k8s_coreos_v1/template_def.py index 11ede6f31d..6d57f370ee 100644 --- a/magnum/drivers/k8s_coreos_v1/template_def.py +++ b/magnum/drivers/k8s_coreos_v1/template_def.py @@ -13,11 +13,11 @@ # under the License. import os +import magnum.conf from magnum.drivers.common import k8s_template_def from magnum.drivers.common import template_def -from oslo_config import cfg -CONF = cfg.CONF +CONF = magnum.conf.CONF class CoreOSK8sTemplateDefinition(k8s_template_def.K8sTemplateDefinition): diff --git a/magnum/drivers/k8s_fedora_atomic_v1/template_def.py b/magnum/drivers/k8s_fedora_atomic_v1/template_def.py index 54e076136f..1f09ce065a 100644 --- a/magnum/drivers/k8s_fedora_atomic_v1/template_def.py +++ b/magnum/drivers/k8s_fedora_atomic_v1/template_def.py @@ -14,10 +14,10 @@ import os +import magnum.conf from magnum.drivers.common import k8s_fedora_template_def as kftd -from oslo_config import cfg -CONF = cfg.CONF +CONF = magnum.conf.CONF class AtomicK8sTemplateDefinition(kftd.K8sFedoraTemplateDefinition): diff --git a/magnum/drivers/swarm_fedora_atomic_v1/template_def.py b/magnum/drivers/swarm_fedora_atomic_v1/template_def.py index bcece57ebb..83276779c0 100644 --- a/magnum/drivers/swarm_fedora_atomic_v1/template_def.py +++ b/magnum/drivers/swarm_fedora_atomic_v1/template_def.py @@ -14,9 +14,6 @@ import os from magnum.drivers.common import swarm_fedora_template_def as sftd -from oslo_config import cfg - -CONF = cfg.CONF class AtomicSwarmTemplateDefinition(sftd.SwarmFedoraTemplateDefinition): diff --git a/magnum/opts.py b/magnum/opts.py deleted file mode 100644 index 4b28fe2bc4..0000000000 --- a/magnum/opts.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2014 -# The Cloudscaling Group, 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 magnum.drivers.common.template_def - - -def list_opts(): - return [ - ('docker_registry', - magnum.drivers.common.template_def.docker_registry_opts) - ] diff --git a/magnum/tests/unit/conductor/handlers/test_swarm_cluster_conductor.py b/magnum/tests/unit/conductor/handlers/test_swarm_cluster_conductor.py index 8d46ddccdf..42c955d079 100644 --- a/magnum/tests/unit/conductor/handlers/test_swarm_cluster_conductor.py +++ b/magnum/tests/unit/conductor/handlers/test_swarm_cluster_conductor.py @@ -14,16 +14,18 @@ import mock from mock import patch -from oslo_config import cfg from oslo_service import loopingcall from magnum.conductor.handlers import cluster_conductor +import magnum.conf from magnum.drivers.common import driver from magnum.drivers.swarm_fedora_atomic_v1 import driver as swarm_dr from magnum import objects from magnum.objects.fields import ClusterStatus as cluster_status from magnum.tests import base +CONF = magnum.conf.CONF + class TestClusterConductorWithSwarm(base.TestCase): def setUp(self): @@ -166,9 +168,9 @@ class TestClusterConductorWithSwarm(base.TestCase): mock_driver.return_value = swarm_dr.Driver() cluster = objects.Cluster(self.context, **self.cluster_dict) - cfg.CONF.set_override('swift_region', - 'RegionOne', - group='docker_registry') + CONF.set_override('swift_region', + 'RegionOne', + group='docker_registry') (template_path, definition, diff --git a/magnum/tests/unit/test_opts.py b/magnum/tests/unit/test_opts.py deleted file mode 100644 index 115631ca45..0000000000 --- a/magnum/tests/unit/test_opts.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# 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. - -from oslo_config import cfg -import six - -from magnum import opts -from magnum.tests import base - - -class OptsTestCase(base.BaseTestCase): - - def test_list_opts(self): - for group_name, opt_list in opts.list_opts(): - self.assertIsInstance(group_name, six.string_types) - for opt in opt_list: - self.assertIsInstance(opt, cfg.Opt)