Centralize config option: cluster section

Centralize config option of Cluster section.
Replace oslo_conf cfg to magnum.conf.

Change-Id: I2f7e796c08b4b2a97e4644cb6aa9dc7a4a4e692d
Implements: blueprint centralize-config-magnum
This commit is contained in:
Hieu LE 2016-08-17 13:16:25 +07:00
parent 44cca296f9
commit 494cb2198c
7 changed files with 75 additions and 45 deletions

View File

@ -17,12 +17,12 @@ import sys
from cliff import app
from cliff import commandmanager
from cliff import lister
from oslo_config import cfg
import magnum.conf
from magnum.drivers.common import template_def as tdef
from magnum import version
CONF = cfg.CONF
CONF = magnum.conf.CONF
def is_enabled(name):

View File

@ -19,7 +19,7 @@ from magnum.conf import api
from magnum.conf import barbican
# from magnum.conf import certificates
from magnum.conf import cinder
# from magnum.conf import cluster
from magnum.conf import cluster
# from magnum.conf import cluster_templates
# from magnum.conf import conductor
# from magnum.conf import database
@ -36,7 +36,7 @@ CONF = cfg.CONF
api.register_opts(CONF)
barbican.register_opts(CONF)
# cluster.register_opts(CONF)
cluster.register_opts(CONF)
# cluster_templates.register_opts(CONF)
# certificates.register_opts(CONF)
cinder.register_opts(CONF)

42
magnum/conf/cluster.py Normal file
View File

@ -0,0 +1,42 @@
# 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 _
cluster_group = cfg.OptGroup(name='cluster',
title='Options for Cluster configuration')
cluster_def_opts = [
cfg.StrOpt('etcd_discovery_service_endpoint_format',
default='https://discovery.etcd.io/new?size=%(size)d',
help=_('Url for etcd public discovery endpoint.'),
deprecated_group='bay'),
cfg.ListOpt('enabled_definitions',
default=['magnum_vm_atomic_k8s', 'magnum_bm_fedora_k8s',
'magnum_vm_coreos_k8s', 'magnum_vm_atomic_swarm',
'magnum_vm_ubuntu_mesos'],
help=_('Enabled cluster definition entry points.'),
deprecated_group='bay'),
]
def register_opts(conf):
conf.register_group(cluster_group)
conf.register_opts(cluster_def_opts, group=cluster_group)
def list_opts():
return {
cluster_group: cluster_def_opts
}

View File

@ -22,30 +22,17 @@ 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
LOG = logging.getLogger(__name__)
COMMON_TEMPLATES_PATH = "../../common/templates/"
COMMON_ENV_PATH = COMMON_TEMPLATES_PATH + "environments/"
template_def_opts = [
cfg.StrOpt('etcd_discovery_service_endpoint_format',
default='https://discovery.etcd.io/new?size=%(size)d',
help=_('Url for etcd public discovery endpoint.'),
deprecated_group='bay'),
cfg.ListOpt('enabled_definitions',
default=['magnum_vm_atomic_k8s', 'magnum_bm_fedora_k8s',
'magnum_vm_coreos_k8s', 'magnum_vm_atomic_swarm',
'magnum_vm_ubuntu_mesos'],
help=_('Enabled cluster definition entry points.'),
deprecated_group='bay'),
]
docker_registry_opts = [
cfg.StrOpt('swift_region',
help=_('Region name of Swift')),
@ -55,8 +42,7 @@ docker_registry_opts = [
'stores images in'))
]
CONF = cfg.CONF
CONF.register_opts(template_def_opts, group='cluster')
CONF = magnum.conf.CONF
CONF.register_opts(docker_registry_opts, group='docker_registry')
CONF.import_opt('trustee_domain_id', 'magnum.common.keystone', group='trust')
@ -246,7 +232,7 @@ class TemplateDefinition(object):
coe=coe)
type_definitions = definition_map[cluster_type]
for name in cfg.CONF.cluster.enabled_definitions:
for name in CONF.cluster.enabled_definitions:
if name in type_definitions:
return type_definitions[name]()

View File

@ -25,7 +25,6 @@ import magnum.common.x509.config
import magnum.conductor.config
import magnum.conductor.handlers.cluster_conductor
import magnum.db
import magnum.drivers.common.template_def
def list_opts():
@ -36,7 +35,6 @@ def list_opts():
magnum.common.rpc_service.periodic_opts,
magnum.common.service.service_opts,
)),
('cluster', magnum.drivers.common.template_def.template_def_opts),
('conductor', magnum.conductor.config.SERVICE_OPTS),
('database', magnum.db.sql_opts),
('docker', magnum.common.docker_utils.docker_opts),

View File

@ -14,12 +14,14 @@
import mock
from mock import patch
from oslo_config import cfg
from magnum.conductor.handlers import cluster_conductor
import magnum.conf
from magnum import objects
from magnum.tests import base
CONF = magnum.conf.CONF
class TestClusterConductorWithK8s(base.TestCase):
def setUp(self):
@ -205,9 +207,9 @@ class TestClusterConductorWithK8s(base.TestCase):
mock_get.return_value = mock_resp
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,
@ -488,9 +490,9 @@ class TestClusterConductorWithK8s(base.TestCase):
cluster_dict['discovery_url'] = None
cluster = objects.Cluster(self.context, **cluster_dict)
cfg.CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
mock_req = mock.MagicMock(text='https://address/token')
reqget.return_value = mock_req
@ -595,7 +597,7 @@ class TestClusterConductorWithK8s(base.TestCase):
expected_stack_name = 'expected_stack_name-xx-xx-xx-xx'
expected_template_contents = 'template_contents'
dummy_cluster_name = 'expected_stack_name'
expected_timeout = cfg.CONF.cluster_heat.create_timeout
expected_timeout = CONF.cluster_heat.create_timeout
mock_tpl_files = {}
mock_get_template_contents.return_value = [
@ -636,7 +638,7 @@ class TestClusterConductorWithK8s(base.TestCase):
expected_template_contents = 'template_contents'
dummy_cluster_name = 'expected_stack_name'
cluster_timeout = 0
expected_timeout = cfg.CONF.cluster_heat.create_timeout
expected_timeout = CONF.cluster_heat.create_timeout
mock_tpl_files = {}
mock_get_template_contents.return_value = [

View File

@ -15,10 +15,10 @@
import abc
import mock
from neutronclient.common import exceptions as n_exception
from oslo_config import cfg
import six
from magnum.common import exception
import magnum.conf
from magnum.drivers.common import template_def as cmn_tdef
from magnum.drivers.k8s_coreos_v1 import template_def as k8s_coreos_tdef
from magnum.drivers.k8s_fedora_atomic_v1 import template_def as k8sa_tdef
@ -29,6 +29,8 @@ from magnum.tests import base
from requests import exceptions as req_exceptions
CONF = magnum.conf.CONF
class TemplateDefinitionTestCase(base.TestCase):
@ -110,9 +112,9 @@ class TemplateDefinitionTestCase(base.TestCase):
'vm', 'not_supported', 'kubernetes')
def test_get_definition_not_enabled(self):
cfg.CONF.set_override('enabled_definitions',
['magnum_vm_atomic_k8s'],
group='cluster')
CONF.set_override('enabled_definitions',
['magnum_vm_atomic_k8s'],
group='cluster')
self.assertRaises(exception.ClusterTypeNotEnabled,
cmn_tdef.TemplateDefinition.get_template_definition,
'vm', 'coreos', 'kubernetes')
@ -391,9 +393,9 @@ class AtomicK8sTemplateDefinitionTestCase(BaseTemplateDefinitionTestCase):
@mock.patch('requests.get')
def test_k8s_get_discovery_url(self, mock_get):
cfg.CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
expected_discovery_url = 'http://etcd/token'
mock_resp = mock.MagicMock()
mock_resp.text = expected_discovery_url
@ -411,9 +413,9 @@ class AtomicK8sTemplateDefinitionTestCase(BaseTemplateDefinitionTestCase):
@mock.patch('requests.get')
def test_k8s_get_discovery_url_fail(self, mock_get):
cfg.CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
mock_get.side_effect = req_exceptions.RequestException()
mock_cluster = mock.MagicMock()
mock_cluster.master_count = 10
@ -793,9 +795,9 @@ class AtomicSwarmTemplateDefinitionTestCase(base.TestCase):
@mock.patch('requests.get')
def test_swarm_get_discovery_url(self, mock_get):
cfg.CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
CONF.set_override('etcd_discovery_service_endpoint_format',
'http://etcd/test?size=%(size)d',
group='cluster')
expected_discovery_url = 'http://etcd/token'
mock_resp = mock.MagicMock()
mock_resp.text = expected_discovery_url