Move common configs under common.configs

We've some options in bootstrap and other places that should probably go
to a common place so that we can guarantee they are always registered
when the Zaqar starts.

This patch adds a new zaqar.common.config module that holds all the
common configs but doesn't register them. This step is still performed
when it is required.

Change-Id: I9941095ed56835093d56b5ad2bf85b53bdda0c8b
Partially-Implements: pre-signed-url
This commit is contained in:
Flavio Percoco 2015-07-01 13:38:03 +02:00
parent a29166ebb8
commit 3f3e99f587
8 changed files with 71 additions and 47 deletions

View File

@ -53,7 +53,7 @@ zaqar.openstack.common.cache.backends =
memory = zaqar.openstack.common.cache._backends.memory:MemoryBackend
oslo.config.opts =
zaqar.bootstrap = zaqar.bootstrap:_config_options
zaqar.common.configs = zaqar.common.configs:_config_options
zaqar.storage.pipeline = zaqar.storage.pipeline:_config_options
zaqar.storage.pooling = zaqar.storage.pooling:_config_options
zaqar.storage.mongodb = zaqar.storage.mongodb.options:_config_options

View File

@ -18,6 +18,7 @@ from oslo_log import log
from stevedore import driver
from zaqar.api import handler
from zaqar.common import configs
from zaqar.common import decorators
from zaqar.common import errors
from zaqar.i18n import _
@ -30,11 +31,8 @@ from zaqar.transport import validation
LOG = log.getLogger(__name__)
ADMIN_MODE_OPT = cfg.BoolOpt('admin_mode', default=False,
help='Activate privileged endpoints.')
_CLI_OPTIONS = (
ADMIN_MODE_OPT,
configs._ADMIN_MODE_OPT,
cfg.BoolOpt('daemon', default=False,
help='Run Zaqar server in the background.'),
)
@ -45,35 +43,6 @@ CONF = cfg.CONF
CONF.register_cli_opts(_CLI_OPTIONS)
log.register_options(CONF)
_GENERAL_OPTIONS = (
ADMIN_MODE_OPT,
cfg.BoolOpt('pooling', default=False,
help=('Enable pooling across multiple storage backends. '
'If pooling is enabled, the storage driver '
'configuration is used to determine where the '
'catalogue/control plane data is kept.'),
deprecated_opts=[cfg.DeprecatedOpt('sharding')]),
cfg.BoolOpt('unreliable', default=None,
help='Disable all reliability constrains.'),
)
_DRIVER_OPTIONS = (
cfg.StrOpt('transport', default='wsgi',
help='Transport driver to use.'),
cfg.StrOpt('message_store', default='mongodb',
deprecated_opts=[cfg.DeprecatedOpt('storage')],
help='Storage driver to use as the messaging store.'),
cfg.StrOpt('management_store', default='mongodb',
help='Storage driver to use as the management store.'),
)
_DRIVER_GROUP = 'drivers'
def _config_options():
return [(None, _GENERAL_OPTIONS),
(_DRIVER_GROUP, _DRIVER_OPTIONS)]
class Bootstrap(object):
"""Defines the Zaqar bootstrapper.
@ -84,9 +53,11 @@ class Bootstrap(object):
def __init__(self, conf):
self.conf = conf
self.conf.register_opts(_GENERAL_OPTIONS)
self.conf.register_opts(_DRIVER_OPTIONS, group=_DRIVER_GROUP)
self.driver_conf = self.conf[_DRIVER_GROUP]
for group, opts in configs._config_options():
self.conf.register_opts(opts, group=group)
self.driver_conf = self.conf[configs._DRIVER_GROUP]
log.setup(conf, 'zaqar')

51
zaqar/common/configs.py Normal file
View File

@ -0,0 +1,51 @@
# Copyright (c) 2015 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
_ADMIN_MODE_OPT = cfg.BoolOpt('admin_mode', default=False,
help='Activate privileged endpoints.')
_GENERAL_OPTIONS = (
_ADMIN_MODE_OPT,
cfg.BoolOpt('pooling', default=False,
help=('Enable pooling across multiple storage backends. '
'If pooling is enabled, the storage driver '
'configuration is used to determine where the '
'catalogue/control plane data is kept.'),
deprecated_opts=[cfg.DeprecatedOpt('sharding')]),
cfg.BoolOpt('unreliable', default=None,
help='Disable all reliability constrains.'),
)
_DRIVER_OPTIONS = (
cfg.StrOpt('transport', default='wsgi',
help='Transport driver to use.'),
cfg.StrOpt('message_store', default='mongodb',
deprecated_opts=[cfg.DeprecatedOpt('storage')],
help='Storage driver to use as the messaging store.'),
cfg.StrOpt('management_store', default='mongodb',
help='Storage driver to use as the management store.'),
)
_DRIVER_GROUP = 'drivers'
def _config_options():
return [(None, _GENERAL_OPTIONS),
(_DRIVER_GROUP, _DRIVER_OPTIONS)]

View File

@ -21,7 +21,7 @@ from oslo_log import log
import six
import testtools
from zaqar import bootstrap
from zaqar.common import configs
class TestBase(testtools.TestCase):
@ -51,9 +51,9 @@ class TestBase(testtools.TestCase):
else:
self.conf = cfg.ConfigOpts()
self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
self.conf.register_opts(bootstrap._DRIVER_OPTIONS,
group=bootstrap._DRIVER_GROUP)
self.conf.register_opts(configs._GENERAL_OPTIONS)
self.conf.register_opts(configs._DRIVER_OPTIONS,
group=configs._DRIVER_GROUP)
@classmethod
def conf_path(cls, filename):

View File

@ -15,7 +15,7 @@
import ddt
from zaqar import bootstrap
from zaqar.common import configs
from zaqar.storage import utils
from zaqar import tests as testing
@ -25,7 +25,7 @@ class TestUtils(testing.TestBase):
def setUp(self):
super(TestUtils, self).setUp()
self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
self.conf.register_opts(configs._GENERAL_OPTIONS)
@testing.requires_mongodb
def test_can_connect_suceeds_if_good_uri_mongo(self):

View File

@ -25,7 +25,7 @@ import pymongo.errors
import six
from testtools import matchers
from zaqar import bootstrap
from zaqar.common import configs
from zaqar.openstack.common.cache import cache as oslo_cache
from zaqar import storage
from zaqar.storage import errors
@ -154,7 +154,7 @@ class MongodbDriverTest(MongodbSetupMixin, testing.TestBase):
def setUp(self):
super(MongodbDriverTest, self).setUp()
self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
self.conf.register_opts(configs._GENERAL_OPTIONS)
self.config(unreliable=False)
def test_db_instance(self):

View File

@ -15,6 +15,7 @@
from oslo_serialization import jsonutils
from zaqar import bootstrap
from zaqar.common import configs
from zaqar import tests as testing
from zaqar.transport import validation
from zaqar.transport.websocket import driver
@ -30,7 +31,7 @@ class TestBase(testing.TestBase):
if not self.config_file:
self.skipTest("No config specified")
self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
self.conf.register_opts(configs._GENERAL_OPTIONS)
self.conf.register_opts(validation._TRANSPORT_LIMITS_OPTIONS,
group=validation._TRANSPORT_LIMITS_GROUP)
self.transport_cfg = self.conf[validation._TRANSPORT_LIMITS_GROUP]

View File

@ -18,6 +18,7 @@ from falcon import testing as ftest
from oslo_serialization import jsonutils
from zaqar import bootstrap
from zaqar.common import configs
from zaqar import tests as testing
from zaqar.transport import validation
from zaqar.transport.wsgi import driver
@ -33,7 +34,7 @@ class TestBase(testing.TestBase):
if not self.config_file:
self.skipTest("No config specified")
self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
self.conf.register_opts(configs._GENERAL_OPTIONS)
self.conf.register_opts(validation._TRANSPORT_LIMITS_OPTIONS,
group=validation._TRANSPORT_LIMITS_GROUP)
self.transport_cfg = self.conf[validation._TRANSPORT_LIMITS_GROUP]