Refactoring config options for services opts

Refactoring neutron services config opts to be in neutron/conf/services
so that all the configuration options for services reside in a
centralized location. This simplifies the process of looking up the
extension config opts and provides an easy way to import.

Change-Id: Iad255b020910ee54bc6cce25f4f786376dfe3705
Partial-Bug: #1563069
This commit is contained in:
Anindita Das 2016-07-25 21:58:37 +00:00
parent ba3b4638d2
commit 86bf29a45f
12 changed files with 172 additions and 81 deletions

View File

View File

@ -0,0 +1,64 @@
# Copyright (c) 2016 IBM
# 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
from neutron._i18n import _
designate_opts = [
cfg.StrOpt('url',
help=_('URL for connecting to designate')),
cfg.StrOpt('admin_username',
help=_('Username for connecting to designate in admin '
'context')),
cfg.StrOpt('admin_password',
help=_('Password for connecting to designate in admin '
'context'),
secret=True),
cfg.StrOpt('admin_tenant_id',
help=_('Tenant id for connecting to designate in admin '
'context')),
cfg.StrOpt('admin_tenant_name',
help=_('Tenant name for connecting to designate in admin '
'context')),
cfg.StrOpt('admin_auth_url',
help=_('Authorization URL for connecting to designate in admin '
'context')),
cfg.BoolOpt('insecure', default=False,
help=_('Skip cert validation for SSL based admin_auth_url')),
cfg.StrOpt('ca_cert',
help=_('CA certificate file to use to verify '
'connecting clients')),
cfg.BoolOpt('allow_reverse_dns_lookup', default=True,
help=_('Allow the creation of PTR records')),
cfg.IntOpt('ipv4_ptr_zone_prefix_size', default=24,
help=_('Number of bits in an ipv4 PTR zone that will be considered '
'network prefix. It has to align to byte boundary. Minimum '
'value is 8. Maximum value is 24. As a consequence, range '
'of values is 8, 16 and 24')),
cfg.IntOpt('ipv6_ptr_zone_prefix_size', default=120,
help=_('Number of bits in an ipv6 PTR zone that will be considered '
'network prefix. It has to align to nyble boundary. Minimum '
'value is 4. Maximum value is 124. As a consequence, range '
'of values is 4, 8, 12, 16,..., 124')),
cfg.StrOpt('ptr_zone_email', default='',
help=_('The email address to be used when creating PTR zones. '
'If not specified, the email address will be '
'admin@<dns_domain>')),
]
def register_designate_opts(cfg=cfg.CONF):
cfg.register_opts(designate_opts, 'designate')

View File

@ -0,0 +1,32 @@
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# 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 neutron._i18n import _
metering_agent_opts = [
cfg.StrOpt('driver',
default='neutron.services.metering.drivers.noop.'
'noop_driver.NoopMeteringDriver',
help=_("Metering driver")),
cfg.IntOpt('measure_interval', default=30,
help=_("Interval between two metering measures")),
cfg.IntOpt('report_interval', default=300,
help=_("Interval between two metering reports")),
]
def register_metering_agent_opts(cfg=cfg.CONF):
cfg.register_opts(metering_agent_opts)

View File

@ -0,0 +1,29 @@
# Copyright 2013 OpenStack Foundation.
# 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
from neutron._i18n import _
serviceprovider_opts = [
cfg.MultiStrOpt('service_provider', default=[],
help=_('Defines providers for advanced services '
'using the format: '
'<service_type>:<name>:<driver>[:default]'))
]
def register_service_provider_opts(cfg=cfg.CONF):
cfg.register_opts(serviceprovider_opts, 'service_providers')

View File

@ -0,0 +1,24 @@
# 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 neutron._i18n import _
QOS_PLUGIN_OPTS = [
cfg.ListOpt('notification_drivers',
default=['message_queue'],
help=_('Drivers list to use to send the update notification')),
]
def register_qos_plugin_opts(cfg=cfg.CONF):
cfg.register_opts(QOS_PLUGIN_OPTS, "qos")

View File

@ -35,6 +35,8 @@ import neutron.conf.common
import neutron.conf.plugins.ml2.drivers.linuxbridge import neutron.conf.plugins.ml2.drivers.linuxbridge
import neutron.conf.quota import neutron.conf.quota
import neutron.conf.service import neutron.conf.service
import neutron.conf.services.metering_agent
import neutron.conf.services.qos_driver_manager
import neutron.conf.wsgi import neutron.conf.wsgi
import neutron.db.agents_db import neutron.db.agents_db
import neutron.db.agentschedulers_db import neutron.db.agentschedulers_db
@ -59,8 +61,6 @@ import neutron.plugins.ml2.drivers.type_geneve
import neutron.plugins.ml2.drivers.type_gre import neutron.plugins.ml2.drivers.type_gre
import neutron.plugins.ml2.drivers.type_vlan import neutron.plugins.ml2.drivers.type_vlan
import neutron.plugins.ml2.drivers.type_vxlan import neutron.plugins.ml2.drivers.type_vxlan
import neutron.services.metering.agents.metering_agent
import neutron.services.qos.notification_drivers.manager
import neutron.wsgi import neutron.wsgi
@ -148,7 +148,7 @@ def list_opts():
def list_qos_opts(): def list_qos_opts():
return [ return [
('qos', ('qos',
neutron.services.qos.notification_drivers.manager.QOS_PLUGIN_OPTS) neutron.conf.services.qos_driver_manager.QOS_PLUGIN_OPTS)
] ]
@ -233,8 +233,7 @@ def list_metering_agent_opts():
return [ return [
('DEFAULT', ('DEFAULT',
itertools.chain( itertools.chain(
neutron.services.metering.agents.metering_agent.MeteringAgent. neutron.conf.services.metering_agent.metering_agent_opts,
Opts,
neutron.agent.common.config.INTERFACE_DRIVER_OPTS) neutron.agent.common.config.INTERFACE_DRIVER_OPTS)
) )
] ]

View File

@ -23,7 +23,7 @@ from keystoneauth1 import token_endpoint
from neutron_lib import constants from neutron_lib import constants
from oslo_config import cfg from oslo_config import cfg
from neutron._i18n import _ from neutron.conf.services import extdns_designate_driver
from neutron.extensions import dns from neutron.extensions import dns
from neutron.services.externaldns import driver from neutron.services.externaldns import driver
@ -34,52 +34,8 @@ IPV6_PTR_ZONE_PREFIX_MAX_SIZE = 124
_SESSION = None _SESSION = None
designate_opts = [
cfg.StrOpt('url',
help=_('URL for connecting to designate')),
cfg.StrOpt('admin_username',
help=_('Username for connecting to designate in admin '
'context')),
cfg.StrOpt('admin_password',
help=_('Password for connecting to designate in admin '
'context'),
secret=True),
cfg.StrOpt('admin_tenant_id',
help=_('Tenant id for connecting to designate in admin '
'context')),
cfg.StrOpt('admin_tenant_name',
help=_('Tenant name for connecting to designate in admin '
'context')),
cfg.StrOpt('admin_auth_url',
help=_('Authorization URL for connecting to designate in admin '
'context')),
cfg.BoolOpt('insecure', default=False,
help=_('Skip cert validation for SSL based admin_auth_url')),
cfg.StrOpt('ca_cert',
help=_('CA certificate file to use to verify '
'connecting clients')),
cfg.BoolOpt('allow_reverse_dns_lookup', default=True,
help=_('Allow the creation of PTR records')),
cfg.IntOpt('ipv4_ptr_zone_prefix_size', default=24,
help=_('Number of bits in an ipv4 PTR zone that will be considered '
'network prefix. It has to align to byte boundary. Minimum '
'value is 8. Maximum value is 24. As a consequence, range '
'of values is 8, 16 and 24')),
cfg.IntOpt('ipv6_ptr_zone_prefix_size', default=120,
help=_('Number of bits in an ipv6 PTR zone that will be considered '
'network prefix. It has to align to nyble boundary. Minimum '
'value is 4. Maximum value is 124. As a consequence, range '
'of values is 4, 8, 12, 16,..., 124')),
cfg.StrOpt('ptr_zone_email', default='',
help=_('The email address to be used when creating PTR zones. '
'If not specified, the email address will be '
'admin@<dns_domain>')),
]
DESIGNATE_GROUP = 'designate'
CONF = cfg.CONF CONF = cfg.CONF
CONF.register_opts(designate_opts, DESIGNATE_GROUP) extdns_designate_driver.register_designate_opts()
def get_clients(context): def get_clients(context):

View File

@ -32,6 +32,7 @@ from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc from neutron.common import rpc as n_rpc
from neutron.common import topics from neutron.common import topics
from neutron.common import utils from neutron.common import utils
from neutron.conf.services import metering_agent
from neutron import context from neutron import context
from neutron import manager from neutron import manager
from neutron import service as neutron_service from neutron import service as neutron_service
@ -63,17 +64,6 @@ class MeteringPluginRpc(object):
class MeteringAgent(MeteringPluginRpc, manager.Manager): class MeteringAgent(MeteringPluginRpc, manager.Manager):
Opts = [
cfg.StrOpt('driver',
default='neutron.services.metering.drivers.noop.'
'noop_driver.NoopMeteringDriver',
help=_("Metering driver")),
cfg.IntOpt('measure_interval', default=30,
help=_("Interval between two metering measures")),
cfg.IntOpt('report_interval', default=300,
help=_("Interval between two metering reports")),
]
def __init__(self, host, conf=None): def __init__(self, host, conf=None):
self.conf = conf or cfg.CONF self.conf = conf or cfg.CONF
self._load_drivers() self._load_drivers()
@ -290,7 +280,7 @@ class MeteringAgentWithStateReport(MeteringAgent):
def main(): def main():
conf = cfg.CONF conf = cfg.CONF
conf.register_opts(MeteringAgent.Opts) metering_agent.register_metering_agent_opts()
config.register_agent_state_opts_helper(conf) config.register_agent_state_opts_helper(conf)
common_config.init(sys.argv[1:]) common_config.init(sys.argv[1:])
config.setup_logging() config.setup_logging()

View File

@ -13,10 +13,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import debtcollector
import importlib import importlib
import itertools import itertools
import os import os
from neutron.conf.services import provider_configuration as prov_config
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -29,14 +31,12 @@ LOG = logging.getLogger(__name__)
SERVICE_PROVIDERS = 'neutron.service_providers' SERVICE_PROVIDERS = 'neutron.service_providers'
serviceprovider_opts = [ debtcollector.deprecate(
cfg.MultiStrOpt('service_provider', default=[], 'Moved serviceprovider_opts to %s' % prov_config.__name__,
help=_('Defines providers for advanced services ' version="newton", removal_version="ocata")
'using the format: ' serviceprovider_opts = prov_config.serviceprovider_opts
'<service_type>:<name>:<driver>[:default]'))
]
cfg.CONF.register_opts(serviceprovider_opts, 'service_providers') prov_config.register_service_provider_opts()
class NeutronModule(object): class NeutronModule(object):
@ -66,7 +66,7 @@ class NeutronModule(object):
def ini(self, neutron_dir=None): def ini(self, neutron_dir=None):
if self.repo['ini'] is None: if self.repo['ini'] is None:
ini_file = cfg.ConfigOpts() ini_file = cfg.ConfigOpts()
ini_file.register_opts(serviceprovider_opts, 'service_providers') prov_config.register_service_provider_opts(ini_file)
if neutron_dir is not None: if neutron_dir is not None:
neutron_dirs = [neutron_dir] neutron_dirs = [neutron_dir]

View File

@ -12,17 +12,12 @@
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from neutron.conf.services import qos_driver_manager as qos_mgr
from neutron._i18n import _, _LI from neutron._i18n import _, _LI
from neutron import manager from neutron import manager
QOS_DRIVER_NAMESPACE = 'neutron.qos.notification_drivers' QOS_DRIVER_NAMESPACE = 'neutron.qos.notification_drivers'
QOS_PLUGIN_OPTS = [ qos_mgr.register_qos_plugin_opts()
cfg.ListOpt('notification_drivers',
default=['message_queue'],
help=_('Drivers list to use to send the update notification')),
]
cfg.CONF.register_opts(QOS_PLUGIN_OPTS, "qos")
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -18,6 +18,7 @@ from oslo_utils import fixture as utils_fixture
from oslo_utils import timeutils from oslo_utils import timeutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
from neutron.conf.services import metering_agent as metering_agent_config
from neutron.services.metering.agents import metering_agent from neutron.services.metering.agents import metering_agent
from neutron.tests import base from neutron.tests import base
from neutron.tests import fake_notifier from neutron.tests import fake_notifier
@ -49,7 +50,7 @@ class TestMeteringOperations(base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestMeteringOperations, self).setUp() super(TestMeteringOperations, self).setUp()
cfg.CONF.register_opts(metering_agent.MeteringAgent.Opts) metering_agent_config.register_metering_agent_opts()
self.noop_driver = ('neutron.services.metering.drivers.noop.' self.noop_driver = ('neutron.services.metering.drivers.noop.'
'noop_driver.NoopMeteringDriver') 'noop_driver.NoopMeteringDriver')
@ -228,7 +229,7 @@ class TestMeteringOperations(base.BaseTestCase):
class TestMeteringDriver(base.BaseTestCase): class TestMeteringDriver(base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestMeteringDriver, self).setUp() super(TestMeteringDriver, self).setUp()
cfg.CONF.register_opts(metering_agent.MeteringAgent.Opts) metering_agent_config.register_metering_agent_opts()
self.noop_driver = ('neutron.services.metering.drivers.noop.' self.noop_driver = ('neutron.services.metering.drivers.noop.'
'noop_driver.NoopMeteringDriver') 'noop_driver.NoopMeteringDriver')

View File

@ -15,6 +15,7 @@ from oslo_config import cfg
from oslo_utils import uuidutils from oslo_utils import uuidutils
from neutron.api.rpc.callbacks import events from neutron.api.rpc.callbacks import events
from neutron.conf.services import qos_driver_manager as driver_mgr_config
from neutron import context from neutron import context
from neutron.objects.qos import policy as policy_object from neutron.objects.qos import policy as policy_object
from neutron.services.qos.notification_drivers import manager as driver_mgr from neutron.services.qos.notification_drivers import manager as driver_mgr
@ -39,7 +40,7 @@ class TestQosDriversManagerBase(base.BaseQosTestCase):
self.config_parse() self.config_parse()
self.setup_coreplugin() self.setup_coreplugin()
config = cfg.ConfigOpts() config = cfg.ConfigOpts()
config.register_opts(driver_mgr.QOS_PLUGIN_OPTS, "qos") driver_mgr_config.register_qos_plugin_opts(config)
self.policy_data = {'policy': { self.policy_data = {'policy': {
'id': uuidutils.generate_uuid(), 'id': uuidutils.generate_uuid(),
'tenant_id': uuidutils.generate_uuid(), 'tenant_id': uuidutils.generate_uuid(),