From a751604fe049e3df0fbdfef4ff53ba8735dbece4 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Mon, 19 Oct 2015 16:29:09 -0500 Subject: [PATCH] Merge keystone.config into keystone.common.config Having two places for config stuff is confusing. There should only be the one place for config stuff, keystone.common.config. Change-Id: I83cae5d2140639df228025851ceb3f90c21af08a --- keystone/auth/controllers.py | 2 +- keystone/cmd/cli.py | 2 +- keystone/common/config.py | 68 ++++++++++++++++++++++ keystone/config.py | 91 ------------------------------ keystone/identity/core.py | 2 +- keystone/server/common.py | 2 +- keystone/server/eventlet.py | 2 +- keystone/server/wsgi.py | 2 +- keystone/tests/unit/core.py | 7 +-- keystone/tests/unit/test_auth.py | 2 +- keystone/tests/unit/test_config.py | 2 +- 11 files changed, 79 insertions(+), 103 deletions(-) delete mode 100644 keystone/config.py diff --git a/keystone/auth/controllers.py b/keystone/auth/controllers.py index bebf66f839..78b071a6ae 100644 --- a/keystone/auth/controllers.py +++ b/keystone/auth/controllers.py @@ -23,11 +23,11 @@ from oslo_utils import importutils import six import stevedore +from keystone.common import config from keystone.common import controller from keystone.common import dependency from keystone.common import utils from keystone.common import wsgi -from keystone import config from keystone import exception from keystone.i18n import _, _LI, _LW from keystone.resource import controllers as resource_controllers diff --git a/keystone/cmd/cli.py b/keystone/cmd/cli.py index 983f63475d..ee8a583051 100644 --- a/keystone/cmd/cli.py +++ b/keystone/cmd/cli.py @@ -22,12 +22,12 @@ from oslo_log import log from oslo_serialization import jsonutils import pbr.version +from keystone.common import config from keystone.common import driver_hints from keystone.common import openssl from keystone.common import sql from keystone.common.sql import migration_helpers from keystone.common import utils -from keystone import config from keystone import exception from keystone.federation import idp from keystone.federation import utils as mapping_engine diff --git a/keystone/common/config.py b/keystone/common/config.py index 6c2445a1a8..c25223248f 100644 --- a/keystone/common/config.py +++ b/keystone/common/config.py @@ -12,11 +12,17 @@ # License for the specific language governing permissions and limitations # under the License. +import logging +import os + from oslo_cache import core as cache from oslo_config import cfg +from oslo_log import log import oslo_messaging import passlib.utils +from keystone import exception + _DEFAULT_AUTH_METHODS = ['external', 'password', 'token', 'oauth1'] _CERTFILE = '/etc/keystone/ssl/certs/signing_cert.pem' @@ -1126,6 +1132,68 @@ def setup_authentication(conf=None): _register_auth_plugin_opt(conf, option) +def set_default_for_default_log_levels(): + """Set the default for the default_log_levels option for keystone. + + Keystone uses some packages that other OpenStack services don't use that do + logging. This will set the default_log_levels default level for those + packages. + + This function needs to be called before CONF(). + + """ + extra_log_level_defaults = [ + 'dogpile=INFO', + 'routes=INFO', + 'keystone.common._memcache_pool=INFO', + ] + + log.register_options(CONF) + CONF.set_default('default_log_levels', + CONF.default_log_levels + extra_log_level_defaults) + + +def setup_logging(): + """Sets up logging for the keystone package.""" + log.setup(CONF, 'keystone') + logging.captureWarnings(True) + + +def find_paste_config(): + """Find Keystone's paste.deploy configuration file. + + Keystone's paste.deploy configuration file is specified in the + ``[paste_deploy]`` section of the main Keystone configuration file, + ``keystone.conf``. + + For example:: + + [paste_deploy] + config_file = keystone-paste.ini + + :returns: The selected configuration filename + :raises: exception.ConfigFileNotFound + + """ + if CONF.paste_deploy.config_file: + paste_config = CONF.paste_deploy.config_file + paste_config_value = paste_config + if not os.path.isabs(paste_config): + paste_config = CONF.find_file(paste_config) + elif CONF.config_file: + paste_config = CONF.config_file[0] + paste_config_value = paste_config + else: + # this provides backwards compatibility for keystone.conf files that + # still have the entire paste configuration included, rather than just + # a [paste_deploy] configuration section referring to an external file + paste_config = CONF.find_file('keystone.conf') + paste_config_value = 'keystone.conf' + if not paste_config or not os.path.exists(paste_config): + raise exception.ConfigFileNotFound(config_file=paste_config_value) + return paste_config + + def configure(conf=None): if conf is None: conf = CONF diff --git a/keystone/config.py b/keystone/config.py deleted file mode 100644 index 0c909df519..0000000000 --- a/keystone/config.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright 2012 OpenStack Foundation -# -# 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. -"""Wrapper for keystone.common.config that configures itself on import.""" - -import logging -import os - -from oslo_config import cfg -from oslo_log import log - -from keystone.common import config -from keystone import exception - - -CONF = cfg.CONF - -setup_authentication = config.setup_authentication -configure = config.configure - - -def set_default_for_default_log_levels(): - """Set the default for the default_log_levels option for keystone. - - Keystone uses some packages that other OpenStack services don't use that do - logging. This will set the default_log_levels default level for those - packages. - - This function needs to be called before CONF(). - - """ - extra_log_level_defaults = [ - 'dogpile=INFO', - 'routes=INFO', - 'keystone.common._memcache_pool=INFO', - ] - - log.register_options(CONF) - CONF.set_default('default_log_levels', - CONF.default_log_levels + extra_log_level_defaults) - - -def setup_logging(): - """Sets up logging for the keystone package.""" - log.setup(CONF, 'keystone') - logging.captureWarnings(True) - - -def find_paste_config(): - """Find Keystone's paste.deploy configuration file. - - Keystone's paste.deploy configuration file is specified in the - ``[paste_deploy]`` section of the main Keystone configuration file, - ``keystone.conf``. - - For example:: - - [paste_deploy] - config_file = keystone-paste.ini - - :returns: The selected configuration filename - :raises: exception.ConfigFileNotFound - - """ - if CONF.paste_deploy.config_file: - paste_config = CONF.paste_deploy.config_file - paste_config_value = paste_config - if not os.path.isabs(paste_config): - paste_config = CONF.find_file(paste_config) - elif CONF.config_file: - paste_config = CONF.config_file[0] - paste_config_value = paste_config - else: - # this provides backwards compatibility for keystone.conf files that - # still have the entire paste configuration included, rather than just - # a [paste_deploy] configuration section referring to an external file - paste_config = CONF.find_file('keystone.conf') - paste_config_value = 'keystone.conf' - if not paste_config or not os.path.exists(paste_config): - raise exception.ConfigFileNotFound(config_file=paste_config_value) - return paste_config diff --git a/keystone/identity/core.py b/keystone/identity/core.py index 3d996c5374..21506069a0 100644 --- a/keystone/identity/core.py +++ b/keystone/identity/core.py @@ -25,10 +25,10 @@ import six from keystone.common import cache from keystone.common import clean +from keystone.common import config from keystone.common import dependency from keystone.common import driver_hints from keystone.common import manager -from keystone import config from keystone import exception from keystone.i18n import _, _LW from keystone.identity.mapping_backends import mapping diff --git a/keystone/server/common.py b/keystone/server/common.py index 7bc5958ed8..67428631a4 100644 --- a/keystone/server/common.py +++ b/keystone/server/common.py @@ -15,9 +15,9 @@ from oslo_config import cfg from oslo_log import log +from keystone.common import config from keystone.common import dependency from keystone.common import sql -from keystone import config from keystone.i18n import _LW from keystone.server import backends diff --git a/keystone/server/eventlet.py b/keystone/server/eventlet.py index f016b7f9f4..e688baed86 100644 --- a/keystone/server/eventlet.py +++ b/keystone/server/eventlet.py @@ -32,9 +32,9 @@ import pbr.version oslo_i18n.enable_lazy() +from keystone.common import config from keystone.common import environment from keystone.common import utils -from keystone import config from keystone.i18n import _ from keystone.server import common from keystone.version import service as keystone_service diff --git a/keystone/server/wsgi.py b/keystone/server/wsgi.py index 0dfce1fc93..a62a84603a 100644 --- a/keystone/server/wsgi.py +++ b/keystone/server/wsgi.py @@ -25,8 +25,8 @@ import oslo_i18n oslo_i18n.enable_lazy() +from keystone.common import config from keystone.common import environment -from keystone import config from keystone.server import common from keystone.version import service as keystone_service diff --git a/keystone/tests/unit/core.py b/keystone/tests/unit/core.py index 28b532de31..8b4e044068 100644 --- a/keystone/tests/unit/core.py +++ b/keystone/tests/unit/core.py @@ -45,12 +45,11 @@ from keystone.common import environment # noqa environment.use_eventlet() from keystone import auth -from keystone.common import config as common_cfg +from keystone.common import config from keystone.common import dependency from keystone.common import kvs from keystone.common.kvs import core as kvs_core from keystone.common import sql -from keystone import config from keystone import exception from keystone import notifications from keystone.policy.backends import rules @@ -517,7 +516,7 @@ class TestCase(BaseTestCase): def auth_plugin_config_override(self, methods=None, **method_classes): if methods is not None: self.config_fixture.config(group='auth', methods=methods) - common_cfg.setup_authentication() + config.setup_authentication() if method_classes: self.config_fixture.config(group='auth', **method_classes) @@ -538,7 +537,7 @@ class TestCase(BaseTestCase): def mocked_register_auth_plugin_opt(conf, opt): self.config_fixture.register_opt(opt, group='auth') self.useFixture(mockpatch.PatchObject( - common_cfg, '_register_auth_plugin_opt', + config, '_register_auth_plugin_opt', new=mocked_register_auth_plugin_opt)) self.config_overrides() diff --git a/keystone/tests/unit/test_auth.py b/keystone/tests/unit/test_auth.py index d34054a4a8..aa5844f071 100644 --- a/keystone/tests/unit/test_auth.py +++ b/keystone/tests/unit/test_auth.py @@ -26,7 +26,7 @@ from testtools import matchers from keystone import assignment from keystone import auth from keystone.common import authorization -from keystone import config +from keystone.common import config from keystone import exception from keystone.models import token_model from keystone.tests import unit diff --git a/keystone/tests/unit/test_config.py b/keystone/tests/unit/test_config.py index 7984646da1..d7e7809fa6 100644 --- a/keystone/tests/unit/test_config.py +++ b/keystone/tests/unit/test_config.py @@ -16,7 +16,7 @@ import uuid from oslo_config import cfg -from keystone import config +from keystone.common import config from keystone import exception from keystone.tests import unit