Add a _config_options function to Marconi

This function is necessary for options discoverability and manual
options registration. This first patch adds a config function to every
module defining options in marconi. Those functions were registered as
entrypoints that will then be loaded by the configuration sample
generator.

Change-Id: I2c351c14c7e1b104926162336ed3567696c62dfb
This commit is contained in:
Flavio Percoco 2014-01-22 17:12:23 +01:00
parent dcd341d5b8
commit 436557d5f6
12 changed files with 110 additions and 14 deletions

View File

@ -63,3 +63,18 @@ def dict_to_conf(options):
opts.append(opt_type(name=k, default=v))
return opts
def options_iter(options, group=None):
"""Returns an options iterable
This function returns an iterable of
(option, config) pairs.
:param options: Iterable of options
:type options: iter
:param group: Group `options` belong to
:type group: six.text_type
"""
for opt in options:
yield (opt, group)

View File

@ -13,11 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import itertools
from oslo.config import cfg
from stevedore import driver
from marconi.common import decorators
from marconi.common import errors
from marconi.common import utils
from marconi.openstack.common.cache import cache as oslo_cache
from marconi.openstack.common.gettextutils import _
from marconi.openstack.common import log
@ -48,6 +51,11 @@ _DRIVER_OPTIONS = [
_DRIVER_GROUP = 'drivers'
def _config_options():
return itertools.chain(utils.options_iter(_GENERAL_OPTIONS),
utils.options_iter(_DRIVER_OPTIONS, _DRIVER_GROUP))
class Bootstrap(object):
"""Defines the Marconi bootstrapper.

View File

@ -20,6 +20,9 @@ import six
from oslo.config import cfg
from marconi.common import utils
_LIMITS_OPTIONS = [
cfg.IntOpt('default_queue_paging', default=10,
help='Default queue pagination size'),
@ -31,6 +34,10 @@ _LIMITS_OPTIONS = [
_LIMITS_GROUP = 'limits:storage'
def _config_options():
return utils.options_iter(_LIMITS_OPTIONS, _LIMITS_GROUP)
@six.add_metaclass(abc.ABCMeta)
class DriverBase(object):
"""Base class for both data and control plane drivers

View File

@ -18,6 +18,8 @@
from oslo.config import cfg
from marconi.common import utils
MONGODB_OPTIONS = [
cfg.StrOpt('uri', help='Mongodb Connection URI'),
@ -54,3 +56,7 @@ MONGODB_OPTIONS = [
]
MONGODB_GROUP = 'drivers:storage:mongodb'
def _config_options():
return utils.options_iter(MONGODB_OPTIONS, MONGODB_GROUP)

View File

@ -19,6 +19,7 @@ from stevedore import driver
from marconi import common
from marconi.common import decorators
from marconi.common import utils
from marconi.openstack.common.gettextutils import _
from marconi.openstack.common import log as logging
from marconi.queues.storage import base
@ -40,6 +41,10 @@ _PIPELINE_CONFIGS = [
_PIPELINE_GROUP = 'storage'
def _config_options():
return utils.options_iter(_PIPELINE_CONFIGS, _PIPELINE_GROUP)
def _get_storage_pipeline(resource_name, conf):
"""Constructs and returns a storage resource pipeline.

View File

@ -49,6 +49,10 @@ _SHARD_CACHE_PREFIX = 'sharding:'
_SHARD_CACHE_TTL = 10
def _config_options():
return common_utils.options_iter(_CATALOG_OPTIONS, _CATALOG_GROUP)
def _shard_cache_key(queue, project=None):
# NOTE(kgriffs): Use string concatenation for performance,
# also put project first since it is guaranteed to be

View File

@ -18,29 +18,21 @@ import json
import sqlite3
import uuid
from oslo.config import cfg
from marconi.common import decorators
from marconi.queues import storage
from marconi.queues.storage.sqlite import controllers
from marconi.queues.storage.sqlite import options
from marconi.queues.storage.sqlite import utils
_SQLITE_OPTIONS = [
cfg.StrOpt('database', default=':memory:',
help='Sqlite database to use.')
]
_SQLITE_GROUP = 'drivers:storage:sqlite'
class DataDriver(storage.DataDriverBase):
def __init__(self, conf, cache):
super(DataDriver, self).__init__(conf, cache)
self.conf.register_opts(_SQLITE_OPTIONS, group=_SQLITE_GROUP)
self.sqlite_conf = self.conf[_SQLITE_GROUP]
self.conf.register_opts(options.SQLITE_OPTIONS,
group=options.SQLITE_GROUP)
self.sqlite_conf = self.conf[options.SQLITE_GROUP]
self.__path = self.sqlite_conf.database
@ -214,8 +206,9 @@ class ControlDriver(storage.ControlDriverBase):
def __init__(self, conf, cache):
super(ControlDriver, self).__init__(conf, cache)
self.conf.register_opts(_SQLITE_OPTIONS, group=_SQLITE_GROUP)
self.sqlite_conf = self.conf[_SQLITE_GROUP]
self.conf.register_opts(options.SQLITE_OPTIONS,
group=options.SQLITE_GROUP)
self.sqlite_conf = self.conf[options.SQLITE_GROUP]
self.__path = self.sqlite_conf.database

View File

@ -0,0 +1,29 @@
# Copyright (c) 2013 Rackspace, 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.
from oslo.config import cfg
from marconi.common import utils
SQLITE_OPTIONS = [
cfg.StrOpt('database', default=':memory:',
help='Sqlite database to use.')
]
SQLITE_GROUP = 'drivers:storage:sqlite'
def _config_options():
return utils.options_iter(SQLITE_OPTIONS, SQLITE_GROUP)

View File

@ -18,11 +18,17 @@ import six
from oslo.config import cfg
from marconi.common import utils
_TRANSPORT_OPTIONS = [
cfg.StrOpt('auth_strategy', default='')
]
def _config_options():
return utils.options_iter(_TRANSPORT_OPTIONS)
@six.add_metaclass(abc.ABCMeta)
class DriverBase(object):
"""Base class for Transport Drivers to document the expected interface.

View File

@ -17,6 +17,7 @@ import re
from oslo.config import cfg
from marconi.common import utils
from marconi.openstack.common.gettextutils import _
@ -39,6 +40,11 @@ QUEUE_NAME_MAX_LEN = 64
PROJECT_ID_MAX_LEN = 256
def _config_options():
return utils.options_iter(_TRANSPORT_LIMITS_OPTIONS,
_TRANSPORT_LIMITS_GROUP)
class ValidationFailed(ValueError):
"""User input did not follow API restrictions."""

View File

@ -15,6 +15,7 @@
import abc
import functools
import itertools
from wsgiref import simple_server
import falcon
@ -24,6 +25,7 @@ import six
from marconi.common import decorators
from marconi.common.transport import version
from marconi.common.transport.wsgi import helpers
from marconi.common import utils
from marconi.openstack.common.gettextutils import _
import marconi.openstack.common.log as logging
from marconi.queues import transport
@ -46,6 +48,10 @@ _WSGI_GROUP = 'drivers:transport:wsgi'
LOG = logging.getLogger(__name__)
def _config_options():
return itertools.chain(utils.options_iter(_WSGI_OPTIONS, _WSGI_GROUP))
@six.add_metaclass(abc.ABCMeta)
class DriverBase(transport.DriverBase):

View File

@ -48,6 +48,17 @@ marconi.queues.admin.transport =
marconi.openstack.common.cache.backends =
memory = marconi.openstack.common.cache._backends.memory:MemoryBackend
oslo.config.opts =
marconi.bootstrap = marconi.queues.bootstrap._config_options
marconi.storage.base = marconi.queues.storage.base._config_options
marconi.storage.pipeline = marconi.queues.storage.pipeline._config_options
marconi.storage.sharding = marconi.queues.storage.sharding._config_options
marconi.storage.mongodb = marconi.queues.storage.mongodb.options._config_options
marconi.storage.sqlite = marconi.queues.storage.sqlite.options._config_options
marconi.transport.wsgi = marconi.queues.transport.wsgi.driver._config_options
marconi.transport.base = marconi.queues.transport.base._config_options
marconi.transport.validation = marconi.queues.transport.validation._config_options
[nosetests]
where=tests
verbosity=2