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
changes/44/347044/7
Anindita Das 6 years ago
parent ba3b4638d2
commit 86bf29a45f
  1. 0
      neutron/conf/services/__init__.py
  2. 64
      neutron/conf/services/extdns_designate_driver.py
  3. 32
      neutron/conf/services/metering_agent.py
  4. 29
      neutron/conf/services/provider_configuration.py
  5. 24
      neutron/conf/services/qos_driver_manager.py
  6. 9
      neutron/opts.py
  7. 48
      neutron/services/externaldns/drivers/designate/driver.py
  8. 14
      neutron/services/metering/agents/metering_agent.py
  9. 16
      neutron/services/provider_configuration.py
  10. 9
      neutron/services/qos/notification_drivers/manager.py
  11. 5
      neutron/tests/unit/services/metering/agents/test_metering_agent.py
  12. 3
      neutron/tests/unit/services/qos/notification_drivers/test_manager.py

@ -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')

@ -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)

@ -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')

@ -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")

@ -35,6 +35,8 @@ import neutron.conf.common
import neutron.conf.plugins.ml2.drivers.linuxbridge
import neutron.conf.quota
import neutron.conf.service
import neutron.conf.services.metering_agent
import neutron.conf.services.qos_driver_manager
import neutron.conf.wsgi
import neutron.db.agents_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_vlan
import neutron.plugins.ml2.drivers.type_vxlan
import neutron.services.metering.agents.metering_agent
import neutron.services.qos.notification_drivers.manager
import neutron.wsgi
@ -148,7 +148,7 @@ def list_opts():
def list_qos_opts():
return [
('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 [
('DEFAULT',
itertools.chain(
neutron.services.metering.agents.metering_agent.MeteringAgent.
Opts,
neutron.conf.services.metering_agent.metering_agent_opts,
neutron.agent.common.config.INTERFACE_DRIVER_OPTS)
)
]

@ -23,7 +23,7 @@ from keystoneauth1 import token_endpoint
from neutron_lib import constants
from oslo_config import cfg
from neutron._i18n import _
from neutron.conf.services import extdns_designate_driver
from neutron.extensions import dns
from neutron.services.externaldns import driver
@ -34,52 +34,8 @@ IPV6_PTR_ZONE_PREFIX_MAX_SIZE = 124
_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.register_opts(designate_opts, DESIGNATE_GROUP)
extdns_designate_driver.register_designate_opts()
def get_clients(context):

@ -32,6 +32,7 @@ from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.common import utils
from neutron.conf.services import metering_agent
from neutron import context
from neutron import manager
from neutron import service as neutron_service
@ -63,17 +64,6 @@ class MeteringPluginRpc(object):
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):
self.conf = conf or cfg.CONF
self._load_drivers()
@ -290,7 +280,7 @@ class MeteringAgentWithStateReport(MeteringAgent):
def main():
conf = cfg.CONF
conf.register_opts(MeteringAgent.Opts)
metering_agent.register_metering_agent_opts()
config.register_agent_state_opts_helper(conf)
common_config.init(sys.argv[1:])
config.setup_logging()

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

@ -12,17 +12,12 @@
from oslo_config import cfg
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 import manager
QOS_DRIVER_NAMESPACE = 'neutron.qos.notification_drivers'
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")
qos_mgr.register_qos_plugin_opts()
LOG = logging.getLogger(__name__)

@ -18,6 +18,7 @@ from oslo_utils import fixture as utils_fixture
from oslo_utils import timeutils
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.tests import base
from neutron.tests import fake_notifier
@ -49,7 +50,7 @@ class TestMeteringOperations(base.BaseTestCase):
def setUp(self):
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.'
'noop_driver.NoopMeteringDriver')
@ -228,7 +229,7 @@ class TestMeteringOperations(base.BaseTestCase):
class TestMeteringDriver(base.BaseTestCase):
def setUp(self):
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.'
'noop_driver.NoopMeteringDriver')

@ -15,6 +15,7 @@ from oslo_config import cfg
from oslo_utils import uuidutils
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.objects.qos import policy as policy_object
from neutron.services.qos.notification_drivers import manager as driver_mgr
@ -39,7 +40,7 @@ class TestQosDriversManagerBase(base.BaseQosTestCase):
self.config_parse()
self.setup_coreplugin()
config = cfg.ConfigOpts()
config.register_opts(driver_mgr.QOS_PLUGIN_OPTS, "qos")
driver_mgr_config.register_qos_plugin_opts(config)
self.policy_data = {'policy': {
'id': uuidutils.generate_uuid(),
'tenant_id': uuidutils.generate_uuid(),

Loading…
Cancel
Save