Prepare Marconi to support oslo's config.generator

This patch removes the options_iter function and prepares marconi's code
base to play nice with oslo's config.generator. The replacement of lists
with tuples is necessary to avoid oslo's config.generator to parse the
globally defined options. In Marconi's case, we want it to use the
registered entry_points. (This is a workaround).

Change-Id: I56995fe16cd0b6e092b522dac3c32e4ec75bb269
This commit is contained in:
Flavio Percoco 2014-03-11 14:43:40 +01:00
parent 9cea1741a2
commit c3f6e4f79a
9 changed files with 33 additions and 60 deletions

View File

@ -64,18 +64,3 @@ 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,14 +13,11 @@
# 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 import log
from marconi.queues.storage import pipeline
@ -30,7 +27,7 @@ from marconi.queues import transport # NOQA
LOG = log.getLogger(__name__)
_GENERAL_OPTIONS = [
_GENERAL_OPTIONS = (
cfg.BoolOpt('sharding', default=False,
help=('Enable sharding across multiple storage backends. ',
'If sharding is enabled, the storage driver ',
@ -38,21 +35,21 @@ _GENERAL_OPTIONS = [
'catalogue/control plane data is kept.')),
cfg.BoolOpt('admin_mode', default=False,
help='Activate endpoints to manage shard registry.'),
]
)
_DRIVER_OPTIONS = [
_DRIVER_OPTIONS = (
cfg.StrOpt('transport', default='wsgi',
help='Transport driver to use.'),
cfg.StrOpt('storage', default='sqlite',
help='Storage driver to use.'),
]
)
_DRIVER_GROUP = 'drivers'
def _config_options():
return itertools.chain(utils.options_iter(_GENERAL_OPTIONS),
utils.options_iter(_DRIVER_OPTIONS, _DRIVER_GROUP))
return [(None, _GENERAL_OPTIONS),
(_DRIVER_GROUP, _DRIVER_OPTIONS)]
class Bootstrap(object):

View File

@ -18,10 +18,8 @@
from oslo.config import cfg
from marconi.common import utils
MONGODB_OPTIONS = [
MONGODB_OPTIONS = (
cfg.StrOpt('uri', help='Mongodb Connection URI.'),
# Database name
@ -63,10 +61,10 @@ MONGODB_OPTIONS = [
'after a primary node failover. '
'The actual sleep time increases exponentially (power '
'of 2) each time the operation is retried.')),
]
)
MONGODB_GROUP = 'drivers:storage:mongodb'
def _config_options():
return utils.options_iter(MONGODB_OPTIONS, MONGODB_GROUP)
return [(MONGODB_GROUP, MONGODB_OPTIONS)]

View File

@ -19,7 +19,6 @@ 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
@ -28,7 +27,7 @@ LOG = logging.getLogger(__name__)
_PIPELINE_RESOURCES = ('queue', 'message', 'claim')
_PIPELINE_CONFIGS = [
_PIPELINE_CONFIGS = tuple((
cfg.ListOpt(resource + '_pipeline', default=[],
help=_('Pipeline to use for processing {0} operations. '
'This pipeline will be consumed before calling '
@ -36,13 +35,13 @@ _PIPELINE_CONFIGS = [
'which will always be appended to this '
'pipeline.').format(resource))
for resource in _PIPELINE_RESOURCES
]
))
_PIPELINE_GROUP = 'storage'
def _config_options():
return utils.options_iter(_PIPELINE_CONFIGS, _PIPELINE_GROUP)
return [(_PIPELINE_GROUP, _PIPELINE_CONFIGS)]
def _get_storage_pipeline(resource_name, conf):

View File

@ -21,7 +21,6 @@ from oslo.config import cfg
from marconi.common import decorators
from marconi.common.storage import select
from marconi.common import utils as common_utils
from marconi.openstack.common import log
from marconi.queues import storage
from marconi.queues.storage import errors
@ -29,10 +28,10 @@ from marconi.queues.storage import utils
LOG = log.getLogger(__name__)
_CATALOG_OPTIONS = [
_CATALOG_OPTIONS = (
cfg.IntOpt('storage', default='sqlite',
help='Catalog storage driver.'),
]
)
_CATALOG_GROUP = 'sharding:catalog'
@ -49,7 +48,7 @@ _SHARD_CACHE_TTL = 10
def _config_options():
return common_utils.options_iter(_CATALOG_OPTIONS, _CATALOG_GROUP)
return [(_CATALOG_GROUP, _CATALOG_OPTIONS)]
def _shard_cache_key(queue, project=None):

View File

@ -18,15 +18,14 @@ import six
from oslo.config import cfg
from marconi.common import utils
_TRANSPORT_OPTIONS = [
cfg.StrOpt('auth_strategy', default='')
]
_TRANSPORT_OPTIONS = (
cfg.StrOpt('auth_strategy', default=''),
)
def _config_options():
return utils.options_iter(_TRANSPORT_OPTIONS)
return [(None, _TRANSPORT_OPTIONS)]
@six.add_metaclass(abc.ABCMeta)

View File

@ -17,7 +17,6 @@ import re
from oslo.config import cfg
from marconi.common import utils
from marconi.openstack.common.gettextutils import _
MIN_MESSAGE_TTL = 60
@ -25,7 +24,7 @@ MIN_CLAIM_TTL = 60
MIN_CLAIM_GRACE = 60
_TRANSPORT_LIMITS_OPTIONS = [
_TRANSPORT_LIMITS_OPTIONS = (
cfg.IntOpt('max_queues_per_page', default=20,
deprecated_name='queue_paging_uplimit',
deprecated_group='limits:transport'),
@ -51,7 +50,7 @@ _TRANSPORT_LIMITS_OPTIONS = [
cfg.IntOpt('max_claim_grace', default=43200,
deprecated_name='claim_grace_max',
deprecated_group='limits:transport'),
]
)
_TRANSPORT_LIMITS_GROUP = 'transport'
@ -63,8 +62,7 @@ PROJECT_ID_MAX_LEN = 256
def _config_options():
return utils.options_iter(_TRANSPORT_LIMITS_OPTIONS,
_TRANSPORT_LIMITS_GROUP)
return [(_TRANSPORT_LIMITS_GROUP, _TRANSPORT_LIMITS_OPTIONS)]
class ValidationFailed(ValueError):

View File

@ -14,7 +14,6 @@
# limitations under the License.
import functools
import itertools
from wsgiref import simple_server
import falcon
@ -22,7 +21,6 @@ from oslo.config import cfg
from marconi.common import decorators
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
@ -31,13 +29,13 @@ from marconi.queues.transport import validation
from marconi.queues.transport.wsgi import v1_0
from marconi.queues.transport.wsgi import v1_1
_WSGI_OPTIONS = [
_WSGI_OPTIONS = (
cfg.StrOpt('bind', default='127.0.0.1',
help='Address on which the self-hosting server will listen.'),
cfg.IntOpt('port', default=8888,
help='Port on which the self-hosting server will listen.'),
]
)
_WSGI_GROUP = 'drivers:transport:wsgi'
@ -45,7 +43,7 @@ LOG = logging.getLogger(__name__)
def _config_options():
return itertools.chain(utils.options_iter(_WSGI_OPTIONS, _WSGI_GROUP))
return [(_WSGI_GROUP, _WSGI_OPTIONS)]
class Driver(transport.DriverBase):

View File

@ -18,31 +18,31 @@ import os
from oslo.config import cfg
_DEFAULT = [
_DEFAULT = (
cfg.BoolOpt("run_tests", default=True),
]
)
_AUTH_OPTIONS = [
_AUTH_OPTIONS = (
cfg.BoolOpt("auth_on", default=False),
cfg.StrOpt("url", default="https://127.0.0.1:5000/v2.0/tokens"),
cfg.StrOpt("username", default=None),
cfg.StrOpt("password", default=None),
]
)
_MARCONI_OPTIONS = [
_MARCONI_OPTIONS = (
cfg.BoolOpt("run_server", default=True),
cfg.StrOpt("url", default="http://127.0.0.1:8888"),
cfg.StrOpt("version", default="v1"),
cfg.StrOpt("config", default="functional-marconi.conf"),
]
)
_HEADERS_OPTIONS = [
_HEADERS_OPTIONS = (
cfg.StrOpt("host", default="example.com"),
cfg.StrOpt("user_agent", default="FunctionalTests"),
cfg.StrOpt("project_id", default="123456"),
]
)
def load_config():