diff --git a/setup.cfg b/setup.cfg index 0084290c9..79fe7d85a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/zaqar/bootstrap.py b/zaqar/bootstrap.py index b62159aa2..bd6909113 100644 --- a/zaqar/bootstrap.py +++ b/zaqar/bootstrap.py @@ -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 _ @@ -31,11 +32,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.'), ) @@ -46,35 +44,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. @@ -85,9 +54,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') diff --git a/zaqar/common/configs.py b/zaqar/common/configs.py new file mode 100644 index 000000000..6eda9cbad --- /dev/null +++ b/zaqar/common/configs.py @@ -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)] diff --git a/zaqar/tests/base.py b/zaqar/tests/base.py index 7aada89e1..e7755e423 100644 --- a/zaqar/tests/base.py +++ b/zaqar/tests/base.py @@ -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): diff --git a/zaqar/tests/unit/common/storage/test_utils.py b/zaqar/tests/unit/common/storage/test_utils.py index d17f16405..f2e608502 100644 --- a/zaqar/tests/unit/common/storage/test_utils.py +++ b/zaqar/tests/unit/common/storage/test_utils.py @@ -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): diff --git a/zaqar/tests/unit/storage/test_impl_mongodb.py b/zaqar/tests/unit/storage/test_impl_mongodb.py index db6088a9d..75da1e57b 100644 --- a/zaqar/tests/unit/storage/test_impl_mongodb.py +++ b/zaqar/tests/unit/storage/test_impl_mongodb.py @@ -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): diff --git a/zaqar/tests/unit/transport/websocket/base.py b/zaqar/tests/unit/transport/websocket/base.py index bcb94f178..c4ac561f1 100644 --- a/zaqar/tests/unit/transport/websocket/base.py +++ b/zaqar/tests/unit/transport/websocket/base.py @@ -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] diff --git a/zaqar/tests/unit/transport/wsgi/base.py b/zaqar/tests/unit/transport/wsgi/base.py index f7ec21bc0..82561531e 100644 --- a/zaqar/tests/unit/transport/wsgi/base.py +++ b/zaqar/tests/unit/transport/wsgi/base.py @@ -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]