Use oslo.config directly instead of common.config

We've been using a wrapper around oslo.config that worked well at the
early stages of the project. Now, as the project grows, we need to user
more features from oslo.config that wouldn't make sense to export
through the wrapper we have.

This patch deprecates marconi.common.config and uses oslo.config
directly where needed.

This is the first patch around the bp remove-global-config, upcoming
patches will completely remove the usage of a global instance.

Partially-implements remove-global-config

Change-Id: Ie14c6bae8cdb72a6ed93a12c34cd8b156e059872
This commit is contained in:
Flavio Percoco 2013-10-03 14:57:32 +02:00
parent 32e2e29e62
commit c9b0f65f18
30 changed files with 214 additions and 374 deletions

View File

@ -20,10 +20,8 @@ import functools
import sys import sys
import termios import termios
from marconi.common import config
from marconi.openstack.common import log as logging from marconi.openstack.common import log as logging
PROJECT_CFG = config.project('marconi')
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -69,7 +67,6 @@ def runnable(func):
try: try:
logging.setup('marconi') logging.setup('marconi')
PROJECT_CFG.load(args=sys.argv[1:])
func() func()
except KeyboardInterrupt: except KeyboardInterrupt:
LOG.info(_(u'Terminating')) LOG.info(_(u'Terminating'))

View File

@ -1,200 +0,0 @@
# 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.
"""Decentralized configuration module.
A config variable `foo` is a read-only property accessible through
CFG.foo
, where `CFG` is either a global configuration accessible through
CFG = config.project('marconi').from_options(
foo=('bar', 'usage'),
...)
, or a local configuration associated with a namespace
CFG = config.namespace('drivers:transport:wsgi').from_options(
port=80,
...)
The `from_options` call accepts a list of option definition, where each
option is represented as a keyword argument, in the form of either
`name=default` or `name=(default, description)`, where `name` is the
name of the option in a valid Python identifier, and `default` is the
default value of that option.
Configurations can be read from an INI file, where the global options
are under the `[DEFAULT]` section, and the local options are under the
sections named by their associated namespaces.
To load the configurations from a file:
PROJECT_CFG = config.project('marconi')
PROJECT_CFG.load(filename='/path/to/example.conf')
A call to `.load` without a filename looks up for the default ones:
~/.marconi/marconi.conf
/etc/marconi/marconi.conf
Global config variables, if any, can also be read from the command line
arguments:
PROJECT_CFG.load(filename='example.conf', args=sys.argv[1:])
"""
from oslo.config import cfg
def _init():
"""Enclose an API specific config object."""
class ConfigProxy(object):
"""Prototype of the opaque config variable accessors."""
pass
class Obj(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
conf = cfg.CONF
def namespace(name, title=None):
"""Create a config namespace.
:param name: the section name appears in the .ini file
:param title: an optional description
:returns: the option object for the namespace
"""
grp = cfg.OptGroup(name, title)
conf.register_group(grp)
def from_options(**opts):
"""Define options under the associated namespace.
:returns: ConfigProxy of the associated namespace
"""
for k, v in opts.items():
conf.register_opt(_make_opt(k, v), group=grp)
def from_class(cls):
grant_access_to_class(conf[grp.name], cls)
return cls
return from_class(opaque_type_of(ConfigProxy, grp.name))()
return Obj(from_options=from_options)
def project(name=None, prog=None):
"""Access the global namespace.
:param name: the name of the project
:returns: a global option object
"""
def from_options(**opts):
"""Define options under the global namespace.
:returns: ConfigProxy of the global namespace
"""
for k, v in opts.items():
conf.register_cli_opt(_make_opt(k, v))
def from_class(cls):
grant_access_to_class(conf, cls)
return cls
return from_class(opaque_type_of(ConfigProxy, name))()
def load(filename=None, args=None):
"""Load the configurations from a config file.
If the file name is not supplied, look for
~/.%project/%project.conf
and
/etc/%project/%project.conf
:param filename: the name of an alternative config file
:param args: command line arguments
"""
args = [] if args is None else args
if filename is None:
conf(args=args, project=name, prog=prog)
else:
conf(args=args, default_config_files=[filename])
return Obj(from_options=from_options, load=load, conf=conf)
def opaque_type_of(base, postfix):
return type('%s of %s' % (base.__name__, postfix), (base,), {})
def grant_access_to_class(pairs, cls):
for k in pairs:
# A closure is needed for each %k to let
# different properties access different %k.
def let(k=k):
setattr(cls, k, property(lambda obj: pairs[k]))
let()
return namespace, project
namespace, project = _init()
def _make_opt(name, default):
"""Create an oslo.config option with type deduction
The type for the option is deduced from the %default value given
for that option. A default value of None is deduced to Opt.
Note: MultiStrOpt is not supported.
:param name: the name of the option in a valid Python identifier
:param default: the default value of the option, or (default, description)
:raises: cfg.Error if the type can not be deduced.
"""
deduction = {
str: cfg.StrOpt,
bool: cfg.BoolOpt,
int: cfg.IntOpt,
long: cfg.IntOpt,
float: cfg.FloatOpt,
list: cfg.ListOpt,
}
if type(default) is tuple:
default, help = default
else:
help = None
if default is None:
return cfg.Opt(name, help=help)
try:
return deduction[type(default)](name, help=help, default=default)
except KeyError:
raise cfg.Error(u'unrecognized option type')

View File

@ -18,17 +18,21 @@ from stevedore import driver
from marconi.common import access from marconi.common import access
from marconi.common.cache import cache as oslo_cache from marconi.common.cache import cache as oslo_cache
from marconi.common import config
from marconi.common import decorators from marconi.common import decorators
from marconi.common import exceptions from marconi.common import exceptions
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.proxy import transport # NOQA from marconi.proxy import transport # NOQA
PROJECT_CFG = config.project('marconi', 'marconi-proxy') _bootstrap_options = [
CFG = config.namespace('proxy:drivers').from_options( cfg.StrOpt('transport', default='wsgi',
transport='wsgi', help='Transport driver to use'),
storage='memory') cfg.StrOpt('storage', default='memory',
help='Storage driver to use'),
]
CFG = cfg.CONF
CFG.register_opts(_bootstrap_options, group="proxy:drivers")
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -41,7 +45,13 @@ class Bootstrap(object):
""" """
def __init__(self, access_mode, config_file=None, cli_args=None): def __init__(self, access_mode, config_file=None, cli_args=None):
PROJECT_CFG.load(filename=config_file, args=cli_args) default_file = None
if config_file is not None:
default_file = [config_file]
CFG(project='marconi', args=cli_args or [],
default_config_files=default_file)
log.setup('marconi_proxy') log.setup('marconi_proxy')
form = 'marconi.proxy.{0}.transport' form = 'marconi.proxy.{0}.transport'
lookup = {access.Access.public: 'public', lookup = {access.Access.public: 'public',
@ -53,7 +63,7 @@ class Bootstrap(object):
LOG.debug(_(u'Loading Proxy Storage Driver')) LOG.debug(_(u'Loading Proxy Storage Driver'))
try: try:
mgr = driver.DriverManager('marconi.proxy.storage', mgr = driver.DriverManager('marconi.proxy.storage',
CFG.storage, CFG['proxy:drivers'].storage,
invoke_on_load=True) invoke_on_load=True)
return mgr.driver return mgr.driver
except RuntimeError as exc: except RuntimeError as exc:
@ -64,7 +74,7 @@ class Bootstrap(object):
def cache(self): def cache(self):
LOG.debug(_(u'Loading Proxy Cache Driver')) LOG.debug(_(u'Loading Proxy Cache Driver'))
try: try:
mgr = oslo_cache.get_cache(cfg.CONF) mgr = oslo_cache.get_cache(CFG)
return mgr return mgr
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
@ -75,7 +85,7 @@ class Bootstrap(object):
LOG.debug(_(u'Loading Proxy Transport Driver')) LOG.debug(_(u'Loading Proxy Transport Driver'))
try: try:
mgr = driver.DriverManager(self._transport_type, mgr = driver.DriverManager(self._transport_type,
CFG.transport, CFG['proxy:drivers'].transport,
invoke_on_load=True, invoke_on_load=True,
invoke_args=[self.storage, invoke_args=[self.storage,
self.cache]) self.cache])

View File

@ -15,16 +15,18 @@
"""MongoDB driver configuration options.""" """MongoDB driver configuration options."""
from marconi.common import config from oslo.config import cfg
OPTIONS = {
# Connection string _MONGODB_OPTIONS = [
'uri': None, cfg.StrOpt('uri', help='Mongodb Connection URI'),
# Database name # Database name
'database': 'marconi_proxy' # TODO(kgriffs): Consider local sharding across DBs to mitigate
} # per-DB locking latency.
cfg.StrOpt('database', default='marconi_proxy', help='Database name'),
]
CFG = config.namespace('proxy:drivers:storage:mongodb').from_options( _GROUP = 'proxy:drivers:storage:mongodb'
**OPTIONS cfg.CONF.register_opts(_MONGODB_OPTIONS, group=_GROUP)
) CFG = cfg.CONF[_GROUP]

View File

@ -1,9 +1,12 @@
"""Marconi Proxy Transport Drivers""" """Marconi Proxy Transport Drivers"""
from marconi.common import config from oslo.config import cfg
from marconi.proxy.transport import base from marconi.proxy.transport import base
CFG = config.project('marconi').from_options() # NOTE(flaper87): Not sure
# what this is for.
CFG = cfg.CONF
# Hoist into package namespace # Hoist into package namespace
DriverBase = base.DriverBase DriverBase = base.DriverBase

View File

@ -17,9 +17,9 @@ import abc
from wsgiref import simple_server from wsgiref import simple_server
import falcon import falcon
from oslo.config import cfg
import six import six
from marconi.common import config
from marconi.common.transport.wsgi import helpers from marconi.common.transport.wsgi import helpers
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.proxy import transport from marconi.proxy import transport
@ -28,16 +28,20 @@ from marconi.proxy.utils import round_robin
from marconi.queues.transport import auth from marconi.queues.transport import auth
OPTIONS = { _WSGI_OPTIONS = [
'bind': '0.0.0.0', cfg.StrOpt('bind', default='0.0.0.0',
'port': 8889 help='Address to bind this server to'),
}
PROJECT_CFG = config.project('marconi', 'marconi-proxy') cfg.IntOpt('port', default=8888,
GLOBAL_CFG = PROJECT_CFG.from_options() help='Port to bind this server to'),
WSGI_CFG = config.namespace('proxy:drivers:transport:wsgi').from_options(
**OPTIONS ]
)
cfg.CONF.register_opts(_WSGI_OPTIONS,
group='proxy:drivers:transport:wsgi')
GLOBAL_CFG = cfg.CONF
WSGI_CFG = cfg.CONF['proxy:drivers:transport:wsgi']
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -74,7 +78,7 @@ class DriverBase(transport.DriverBase):
# NOTE(flaper87): Install Auth # NOTE(flaper87): Install Auth
if GLOBAL_CFG.auth_strategy: if GLOBAL_CFG.auth_strategy:
strategy = auth.strategy(GLOBAL_CFG.auth_strategy) strategy = auth.strategy(GLOBAL_CFG.auth_strategy)
self.app = strategy.install(self.app, PROJECT_CFG.conf) self.app = strategy.install(self.app, GLOBAL_CFG)
@abc.abstractproperty @abc.abstractproperty
def bridge(self): def bridge(self):

View File

@ -13,19 +13,24 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from oslo.config import cfg
from stevedore import driver from stevedore import driver
from marconi.common import config
from marconi.common import decorators from marconi.common import decorators
from marconi.common import exceptions from marconi.common import exceptions
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.queues import transport # NOQA from marconi.queues import transport # NOQA
PROJECT_CFG = config.project('marconi', 'marconi-queues') _bootstrap_options = [
CFG = config.namespace('queues:drivers').from_options( cfg.StrOpt('transport', default='wsgi',
transport='wsgi', help='Transport driver to use'),
storage='sqlite') cfg.StrOpt('storage', default='sqlite',
help='Storage driver to use'),
]
CFG = cfg.CONF
CFG.register_opts(_bootstrap_options, group="queues:drivers")
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -38,7 +43,12 @@ class Bootstrap(object):
""" """
def __init__(self, config_file=None, cli_args=None): def __init__(self, config_file=None, cli_args=None):
PROJECT_CFG.load(filename=config_file, args=cli_args) default_file = None
if config_file is not None:
default_file = [config_file]
CFG(project='marconi', prog='marconi-queues', args=cli_args or [],
default_config_files=default_file)
log.setup('marconi') log.setup('marconi')
@decorators.lazy_property(write=False) @decorators.lazy_property(write=False)
@ -46,7 +56,7 @@ class Bootstrap(object):
LOG.debug(_(u'Loading Storage Driver')) LOG.debug(_(u'Loading Storage Driver'))
try: try:
mgr = driver.DriverManager('marconi.queues.storage', mgr = driver.DriverManager('marconi.queues.storage',
CFG.storage, CFG['queues:drivers'].storage,
invoke_on_load=True) invoke_on_load=True)
return mgr.driver return mgr.driver
except RuntimeError as exc: except RuntimeError as exc:
@ -58,7 +68,7 @@ class Bootstrap(object):
LOG.debug(_(u'Loading Transport Driver')) LOG.debug(_(u'Loading Transport Driver'))
try: try:
mgr = driver.DriverManager('marconi.queues.transport', mgr = driver.DriverManager('marconi.queues.transport',
CFG.transport, CFG['queues:drivers'].transport,
invoke_on_load=True, invoke_on_load=True,
invoke_args=[self.storage]) invoke_args=[self.storage])
return mgr.driver return mgr.driver

View File

@ -1,8 +1,19 @@
"""Marconi Storage Drivers""" """Marconi Storage Drivers"""
from oslo.config import cfg
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions # NOQA from marconi.queues.storage import exceptions # NOQA
_STORAGE_LIMITS_OPTIONS = [
cfg.IntOpt('default_queue_paging', default=10,
help='Default queue pagination size'),
cfg.IntOpt('default_message_paging', default=10,
help='Default message pagination size')
]
cfg.CONF.register_opts(_STORAGE_LIMITS_OPTIONS, group='queues:limits:storage')
# Hoist classes into package namespace # Hoist classes into package namespace
ClaimBase = base.ClaimBase ClaimBase = base.ClaimBase

View File

@ -24,8 +24,8 @@ Field Mappings:
import datetime import datetime
from bson import objectid from bson import objectid
from oslo.config import cfg
from marconi.common import config
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
@ -33,9 +33,7 @@ from marconi.queues.storage import exceptions
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CFG = config.namespace('queues:limits:storage').from_options( STORAGE_LIMITS = cfg.CONF['queues:limits:storage']
default_message_paging=10,
)
class ClaimController(storage.ClaimBase): class ClaimController(storage.ClaimBase):
@ -122,7 +120,7 @@ class ClaimController(storage.ClaimBase):
msg_ctrl = self.driver.message_controller msg_ctrl = self.driver.message_controller
if limit is None: if limit is None:
limit = CFG.default_message_paging limit = STORAGE_LIMITS.default_message_paging
ttl = metadata['ttl'] ttl = metadata['ttl']
grace = metadata['grace'] grace = metadata['grace']

View File

@ -24,10 +24,10 @@ Field Mappings:
import datetime import datetime
import time import time
from oslo.config import cfg
import pymongo.errors import pymongo.errors
import pymongo.read_preferences import pymongo.read_preferences
from marconi.common import config
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
@ -36,9 +36,7 @@ from marconi.queues.storage.mongodb import options
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CFG = config.namespace('queues:limits:storage').from_options( STORAGE_LIMITS = cfg.CONF['queues:limits:storage']
default_message_paging=10,
)
# NOTE(kgriffs): This value, in seconds, should be at least less than the # NOTE(kgriffs): This value, in seconds, should be at least less than the
# minimum allowed TTL for messages (60 seconds). Make it 45 to allow for # minimum allowed TTL for messages (60 seconds). Make it 45 to allow for
@ -354,7 +352,7 @@ class MessageController(storage.MessageBase):
echo=False, client_uuid=None, include_claimed=False): echo=False, client_uuid=None, include_claimed=False):
if limit is None: if limit is None:
limit = CFG.default_message_paging limit = STORAGE_LIMITS.default_message_paging
if marker is not None: if marker is not None:
try: try:

View File

@ -16,38 +16,43 @@
"""MongoDB storage driver configuration options.""" """MongoDB storage driver configuration options."""
from marconi.common import config from oslo.config import cfg
# TODO(kgriffs): Expose documentation to oslo.config _MONGODB_OPTIONS = [
OPTIONS = { cfg.StrOpt('uri', help='Mongodb Connection URI'),
# Connection string
'uri': None,
# Database name. Will be postfixed with partition identifiers. # Database name
'database': 'marconi', # TODO(kgriffs): Consider local sharding across DBs to mitigate
# per-DB locking latency.
cfg.StrOpt('database', default='marconi', help='Database name'),
# Number of databases across which to partition message data, cfg.IntOpt('partitions', default=2,
# in order to reduce writer lock %. DO NOT change this setting help=('Number of databases across which to '
# after initial deployment. It MUST remain static. Also, 'partition message data, in order to '
# you should not need a large number of partitions to improve 'reduce writer lock %. DO NOT change '
# performance, esp. if deploying MongoDB on SSD storage. 'this setting after initial deployment. '
'partitions': 2, 'It MUST remain static. Also, you '
'should not need a large number of partitions '
'to improve performance, esp. if deploying '
'MongoDB on SSD storage.')),
# Maximum number of times to retry a failed operation. Currently cfg.IntOpt('max_attempts', default=1000,
# only used for retrying a message post. help=('Maximum number of times to retry a failed operation.'
'max_attempts': 1000, 'Currently only used for retrying a message post.')),
# Maximum sleep interval between retries (actual sleep time cfg.FloatOpt('max_retry_sleep', default=0.1,
# increases linearly according to number of attempts performed). help=('Maximum sleep interval between retries '
'max_retry_sleep': 0.1, '(actual sleep time increases linearly '
'according to number of attempts performed).')),
# Maximum jitter interval, to be added to the sleep interval, in cfg.FloatOpt('max_retry_jitter', default=0.005,
# order to decrease probability that parallel requests will retry help=('Maximum jitter interval, to be added to the '
# at the same instant. 'sleep interval, in order to decrease probability '
'max_retry_jitter': 0.005, 'that parallel requests will retry at the '
} 'same instant.')),
]
CFG = config.namespace('queues:drivers:storage:mongodb').from_options( cfg.CONF.register_opts(_MONGODB_OPTIONS,
**OPTIONS group='queues:drivers:storage:mongodb')
) CFG = cfg.CONF['queues:drivers:storage:mongodb']

View File

@ -21,9 +21,9 @@ Field Mappings:
letter of their long name. letter of their long name.
""" """
from oslo.config import cfg
import pymongo.errors import pymongo.errors
from marconi.common import config
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
@ -31,9 +31,7 @@ from marconi.queues.storage import exceptions
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CFG = config.namespace('queues:limits:storage').from_options( STORAGE_LIMITS = cfg.CONF['queues:limits:storage']
default_queue_paging=10,
)
class QueueController(storage.QueueBase): class QueueController(storage.QueueBase):
@ -174,7 +172,7 @@ class QueueController(storage.QueueBase):
limit=None, detailed=False): limit=None, detailed=False):
if limit is None: if limit is None:
limit = CFG.default_queue_paging limit = STORAGE_LIMITS.default_queue_paging
query = {} query = {}
scoped_name = utils.scope_queue_name(marker, project) scoped_name = utils.scope_queue_name(marker, project)

View File

@ -13,14 +13,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from marconi.common import config from oslo.config import cfg
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions from marconi.queues.storage import exceptions
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
CFG = config.namespace('queues:limits:storage').from_options( STORAGE_LIMITS = cfg.CONF['queues:limits:storage']
default_message_paging=10,
)
class ClaimController(base.ClaimBase): class ClaimController(base.ClaimBase):
@ -84,7 +83,7 @@ class ClaimController(base.ClaimBase):
project = '' project = ''
if limit is None: if limit is None:
limit = CFG.default_message_paging limit = STORAGE_LIMITS.default_message_paging
with self.driver('immediate'): with self.driver('immediate'):
try: try:

View File

@ -18,14 +18,19 @@ import sqlite3
import uuid import uuid
import msgpack import msgpack
from oslo.config import cfg
from marconi.common import config
from marconi.queues import storage from marconi.queues import storage
from marconi.queues.storage.sqlite import controllers from marconi.queues.storage.sqlite import controllers
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
CFG = config.namespace('queues:drivers:storage:sqlite').from_options( _SQLITE_OPTIONS = [
database=':memory:') cfg.StrOpt('database', default=':memory:',
help='Sqlite database to use.')
]
cfg.CONF.register_opts(_SQLITE_OPTIONS, group='queues:drivers:storage:sqlite')
CFG = cfg.CONF['queues:drivers:storage:sqlite']
class Driver(storage.DriverBase): class Driver(storage.DriverBase):

View File

@ -13,15 +13,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from marconi.common import config from oslo.config import cfg
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions from marconi.queues.storage import exceptions
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
CFG = config.namespace('queues:limits:storage').from_options( STORAGE_LIMITS = cfg.CONF['queues:limits:storage']
default_message_paging=10,
)
class MessageController(base.MessageBase): class MessageController(base.MessageBase):
@ -139,7 +138,7 @@ class MessageController(base.MessageBase):
echo=False, client_uuid=None, include_claimed=False): echo=False, client_uuid=None, include_claimed=False):
if limit is None: if limit is None:
limit = CFG.default_message_paging limit = STORAGE_LIMITS.default_message_paging
if project is None: if project is None:
project = '' project = ''

View File

@ -14,14 +14,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from marconi.common import config from oslo.config import cfg
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions from marconi.queues.storage import exceptions
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
CFG = config.namespace('queues:limits:storage').from_options( STORAGE_LIMITS = cfg.CONF['queues:limits:storage']
default_queue_paging=10,
)
class QueueController(base.QueueBase): class QueueController(base.QueueBase):
@ -47,7 +46,7 @@ class QueueController(base.QueueBase):
project = '' project = ''
if limit is None: if limit is None:
limit = CFG.default_queue_paging limit = STORAGE_LIMITS.default_queue_paging
sql = ((''' sql = (('''
select name from Queues''' if not detailed select name from Queues''' if not detailed

View File

@ -1,13 +1,14 @@
"""Marconi Transport Drivers""" """Marconi Transport Drivers"""
from marconi.common import config from oslo.config import cfg
from marconi.queues.transport import base from marconi.queues.transport import base
OPTIONS = { _TRANSPORT_OPTIONS = [
'auth_strategy': "" cfg.StrOpt('auth_strategy', default='')
} ]
CFG = config.project('marconi').from_options(**OPTIONS) cfg.CONF.register_opts(_TRANSPORT_OPTIONS)
# Hoist into package namespace # Hoist into package namespace
DriverBase = base.DriverBase DriverBase = base.DriverBase

View File

@ -15,21 +15,23 @@
import re import re
from oslo.config import cfg
import simplejson as json import simplejson as json
from marconi.common import config
OPTIONS = { _TRANSPORT_LIMITS_OPTIONS = [
'queue_paging_uplimit': 20, cfg.IntOpt('queue_paging_uplimit', default=20),
'metadata_size_uplimit': 64 * 1024, cfg.IntOpt('metadata_size_uplimit', default=64 * 1024),
'message_paging_uplimit': 20, cfg.IntOpt('message_paging_uplimit', default=20),
'message_size_uplimit': 256 * 1024, cfg.IntOpt('message_size_uplimit', default=256 * 1024),
'message_ttl_max': 1209600, cfg.IntOpt('message_ttl_max', default=1209600),
'claim_ttl_max': 43200, cfg.IntOpt('claim_ttl_max', default=43200),
'claim_grace_max': 43200, cfg.IntOpt('claim_grace_max', default=43200),
} ]
CFG = config.namespace('queues:limits:transport').from_options(**OPTIONS) cfg.CONF.register_opts(_TRANSPORT_LIMITS_OPTIONS,
group='queues:limits:transport')
CFG = cfg.CONF['queues:limits:transport']
# NOTE(kgriffs): Don't use \w because it isn't guaranteed to match # NOTE(kgriffs): Don't use \w because it isn't guaranteed to match
# only ASCII characters. # only ASCII characters.

View File

@ -1,11 +1,7 @@
"""WSGI Transport Driver""" """WSGI Transport Driver"""
from marconi.queues.transport.wsgi import claims # NOQA from marconi.queues.transport.wsgi import configs # NOQA
from marconi.queues.transport.wsgi import driver from marconi.queues.transport.wsgi import driver
from marconi.queues.transport.wsgi import messages # NOQA
from marconi.queues.transport.wsgi import queues # NOQA
from marconi.queues.transport.wsgi import stats # NOQA
# Hoist into package namespace # Hoist into package namespace
Driver = driver.Driver Driver = driver.Driver

View File

@ -14,9 +14,9 @@
# limitations under the License. # limitations under the License.
import falcon import falcon
from oslo.config import cfg
import six import six
from marconi.common import config
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import exceptions as storage_exceptions
from marconi.queues.transport import utils from marconi.queues.transport import utils
@ -26,9 +26,7 @@ from marconi.queues.transport.wsgi import utils as wsgi_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CFG = config.namespace('queues:drivers:transport:wsgi').from_options( CFG = cfg.CONF['queues:drivers:transport:wsgi']
metadata_max_length=64 * 1024
)
CLAIM_POST_SPEC = (('ttl', int), ('grace', int)) CLAIM_POST_SPEC = (('ttl', int), ('grace', int))
CLAIM_PATCH_SPEC = (('ttl', int),) CLAIM_PATCH_SPEC = (('ttl', int),)

View File

@ -0,0 +1,29 @@
# Copyright (c) 2013 Red Hat, 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
_WSGI_OPTIONS = [
cfg.StrOpt('bind', default='0.0.0.0',
help='Address to bind this server to'),
cfg.IntOpt('port', default=8888,
help='Port to bind this server to'),
cfg.IntOpt('content_max_length', default=256 * 1024),
cfg.IntOpt('metadata_max_length', default=64 * 1024)
]
cfg.CONF.register_opts(_WSGI_OPTIONS, group='queues:drivers:transport:wsgi')

View File

@ -14,9 +14,9 @@
# limitations under the License. # limitations under the License.
import falcon import falcon
from oslo.config import cfg
from wsgiref import simple_server from wsgiref import simple_server
from marconi.common import config
from marconi.common.transport.wsgi import helpers from marconi.common.transport.wsgi import helpers
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues import transport from marconi.queues import transport
@ -30,16 +30,8 @@ from marconi.queues.transport.wsgi import stats
from marconi.queues.transport.wsgi import v1 from marconi.queues.transport.wsgi import v1
OPTIONS = { GLOBAL_CFG = cfg.CONF
'bind': '0.0.0.0', WSGI_CFG = cfg.CONF['queues:drivers:transport:wsgi']
'port': 8888
}
PROJECT_CFG = config.project('marconi', 'marconi-queues')
GLOBAL_CFG = PROJECT_CFG.from_options()
WSGI_CFG = config.namespace('queues:drivers:transport:wsgi').from_options(
**OPTIONS
)
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -114,7 +106,7 @@ class Driver(transport.DriverBase):
# NOTE(flaper87): Install Auth # NOTE(flaper87): Install Auth
if GLOBAL_CFG.auth_strategy: if GLOBAL_CFG.auth_strategy:
strategy = auth.strategy(GLOBAL_CFG.auth_strategy) strategy = auth.strategy(GLOBAL_CFG.auth_strategy)
self.app = strategy.install(self.app, PROJECT_CFG.conf) self.app = strategy.install(self.app, GLOBAL_CFG)
def listen(self): def listen(self):
"""Self-host using 'bind' and 'port' from the WSGI config group.""" """Self-host using 'bind' and 'port' from the WSGI config group."""

View File

@ -14,9 +14,9 @@
# limitations under the License. # limitations under the License.
import falcon import falcon
from oslo.config import cfg
import six import six
from marconi.common import config
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import exceptions as storage_exceptions
from marconi.queues.transport import utils from marconi.queues.transport import utils
@ -26,9 +26,7 @@ from marconi.queues.transport.wsgi import utils as wsgi_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CFG = config.namespace('queues:drivers:transport:wsgi').from_options( CFG = cfg.CONF['queues:drivers:transport:wsgi']
content_max_length=256 * 1024
)
MESSAGE_POST_SPEC = (('ttl', int), ('body', '*')) MESSAGE_POST_SPEC = (('ttl', int), ('body', '*'))

View File

@ -14,9 +14,9 @@
# limitations under the License. # limitations under the License.
import falcon import falcon
from oslo.config import cfg
import six import six
from marconi.common import config
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import exceptions as storage_exceptions
from marconi.queues.transport import utils from marconi.queues.transport import utils
@ -25,9 +25,7 @@ from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions
from marconi.queues.transport.wsgi import utils as wsgi_utils from marconi.queues.transport.wsgi import utils as wsgi_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CFG = config.namespace('queues:drivers:transport:wsgi').from_options( CFG = cfg.CONF['queues:drivers:transport:wsgi']
metadata_max_length=64 * 1024
)
class Resource(object): class Resource(object):

View File

@ -17,9 +17,7 @@ import fixtures
import os import os
import testtools import testtools
from marconi.common import config from oslo.config import cfg
CFG = config.project()
class TestBase(testtools.TestCase): class TestBase(testtools.TestCase):
@ -65,8 +63,8 @@ class TestBase(testtools.TestCase):
:returns: Project's config object. :returns: Project's config object.
""" """
CFG.load(filename=cls.conf_path(filename)) cfg.CONF(args=[], default_config_files=[cls.conf_path(filename)])
return CFG return cfg.CONF
def config(self, group=None, **kw): def config(self, group=None, **kw):
"""Override some configuration values. """Override some configuration values.

View File

@ -51,7 +51,7 @@ class FunctionalTestBase(testing.TestBase):
self.server = self.server_class() self.server = self.server_class()
self.server.start(self.conf_path(self.cfg.marconi.config)) self.server.start(self.conf_path(self.cfg.marconi.config))
self.mconf = self.load_conf(self.cfg.marconi.config).conf self.mconf = self.load_conf(self.cfg.marconi.config)
self.limits = self.mconf['queues:limits:transport'] self.limits = self.mconf['queues:limits:transport']
# NOTE(flaper87): Create client # NOTE(flaper87): Create client

View File

@ -16,7 +16,6 @@
from oslo.config import cfg from oslo.config import cfg
from marconi.common import config
from marconi.queues.transport import auth from marconi.queues.transport import auth
from marconi import tests as testing from marconi import tests as testing
@ -25,13 +24,11 @@ class TestTransportAuth(testing.TestBase):
def setUp(self): def setUp(self):
super(TestTransportAuth, self).setUp() super(TestTransportAuth, self).setUp()
self.cfg = config.project('marconi') self.cfg = cfg.ConfigOpts()
def tearDown(self): def tearDown(self):
super(TestTransportAuth, self).tearDown() super(TestTransportAuth, self).tearDown()
self.cfg.conf = cfg.ConfigOpts()
def test_configs(self): def test_configs(self):
auth.strategy('keystone')._register_opts(self.cfg.conf) auth.strategy('keystone')._register_opts(self.cfg)
self.assertIn('keystone_authtoken', self.cfg.conf) self.assertIn('keystone_authtoken', self.cfg)
self.assertIn('keystone_authtoken', dir(self.cfg.from_options()))

View File

@ -18,10 +18,10 @@ import uuid
import ddt import ddt
import falcon import falcon
from oslo.config import cfg
from testtools import matchers from testtools import matchers
import base # noqa import base # noqa
from marconi.common import config
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi import tests as testing from marconi import tests as testing
@ -32,8 +32,7 @@ class ClaimsBaseTest(base.TestBase):
def setUp(self): def setUp(self):
super(ClaimsBaseTest, self).setUp() super(ClaimsBaseTest, self).setUp()
self.wsgi_cfg = config.namespace( self.wsgi_cfg = cfg.CONF['queues:drivers:transport:wsgi']
'queues:drivers:transport:wsgi').from_options()
self.project_id = '480924' self.project_id = '480924'
self.queue_path = '/v1/queues/fizbit' self.queue_path = '/v1/queues/fizbit'
@ -240,9 +239,7 @@ class ClaimsMongoDBTests(ClaimsBaseTest):
def setUp(self): def setUp(self):
super(ClaimsMongoDBTests, self).setUp() super(ClaimsMongoDBTests, self).setUp()
self.cfg = config.namespace( self.cfg = cfg.CONF['queues:drivers:storage:mongodb']
'queues:drivers:storage:mongodb'
).from_options()
def tearDown(self): def tearDown(self):
storage = self.boot.storage storage = self.boot.storage

View File

@ -18,11 +18,11 @@ import uuid
import ddt import ddt
import falcon import falcon
from oslo.config import cfg
import six import six
from testtools import matchers from testtools import matchers
import base # noqa import base # noqa
from marconi.common import config
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues.transport import validation from marconi.queues.transport import validation
from marconi import tests as testing from marconi import tests as testing
@ -34,8 +34,7 @@ class MessagesBaseTest(base.TestBase):
def setUp(self): def setUp(self):
super(MessagesBaseTest, self).setUp() super(MessagesBaseTest, self).setUp()
self.wsgi_cfg = config.namespace( self.wsgi_cfg = cfg.CONF['queues:drivers:transport:wsgi']
'queues:drivers:transport:wsgi').from_options()
self.project_id = '7e55e1a7e' self.project_id = '7e55e1a7e'
self.queue_path = '/v1/queues/fizbit' self.queue_path = '/v1/queues/fizbit'

View File

@ -18,10 +18,10 @@ import json
import ddt import ddt
import falcon import falcon
from oslo.config import cfg
import six import six
import base # noqa import base # noqa
from marconi.common import config
from marconi import tests as testing from marconi import tests as testing
@ -33,8 +33,7 @@ class QueueLifecycleBaseTest(base.TestBase):
def setUp(self): def setUp(self):
super(QueueLifecycleBaseTest, self).setUp() super(QueueLifecycleBaseTest, self).setUp()
self.wsgi_cfg = config.namespace( self.wsgi_cfg = cfg.CONF['queues:drivers:transport:wsgi']
'queues:drivers:transport:wsgi').from_options()
def test_empty_project_id(self): def test_empty_project_id(self):
path = '/v1/queues/gumshoe' path = '/v1/queues/gumshoe'
@ -317,9 +316,7 @@ class QueueLifecycleMongoDBTests(QueueLifecycleBaseTest):
def setUp(self): def setUp(self):
super(QueueLifecycleMongoDBTests, self).setUp() super(QueueLifecycleMongoDBTests, self).setUp()
self.cfg = config.namespace( self.cfg = cfg.CONF['queues:drivers:storage:mongodb']
'queues:drivers:storage:mongodb'
).from_options()
def tearDown(self): def tearDown(self):
storage = self.boot.storage storage = self.boot.storage