From d06613e3e9bc663c933e5eac7f18ac8a3e7b06b9 Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Singh Date: Thu, 27 Oct 2016 14:19:43 +0000 Subject: [PATCH] Move all conf option to centralize conf directory Currently, all config options of Zun were found in separate package/module. This is somehow hard for new developer joining Zun team to use/add new config options. This patch moves all config option to central place. Change-Id: I2940d295b413b9c802f09be8d418c3721e2f423c --- etc/zun/zun-config-generator.conf | 11 +++- setup.cfg | 2 +- tools/zun-config-generator.conf | 2 +- tox.ini | 2 +- zun/api/app.py | 42 ++----------- zun/api/hooks.py | 3 +- zun/api/servicegroup.py | 12 +--- zun/api/utils.py | 4 +- zun/cmd/api.py | 5 +- zun/cmd/compute.py | 11 ++-- zun/common/clients.py | 47 +------------- zun/common/config.py | 11 ++-- zun/common/context.py | 3 - zun/common/exception.py | 4 +- zun/common/keystone.py | 4 +- zun/common/paths.py | 24 ++------ zun/common/policy.py | 5 +- zun/common/rpc.py | 7 +-- zun/common/rpc_service.py | 16 ++--- zun/common/service.py | 18 +----- zun/compute/api.py | 8 +-- zun/conf/__init__.py | 30 +++++---- zun/conf/api.py | 60 ++++++++++++++++++ zun/{compute/config.py => conf/compute.py} | 16 ++++- zun/conf/container_driver.py | 43 +++++++++++++ zun/conf/database.py | 29 +++++++++ zun/conf/docker.py | 54 ++++++++++++++++ zun/conf/glance_client.py | 61 +++++++++++++++++++ zun/conf/path.py | 41 +++++++++++++ zun/conf/services.py | 52 ++++++++++++++++ zun/conf/zun_client.py | 57 +++++++++++++++++ zun/container/docker/driver.py | 2 - zun/container/docker/utils.py | 32 +--------- zun/container/driver.py | 25 +------- zun/db/__init__.py | 14 +---- zun/db/api.py | 6 +- zun/db/migration.py | 8 ++- zun/db/sqlalchemy/api.py | 4 +- zun/db/sqlalchemy/migration.py | 5 +- zun/db/sqlalchemy/models.py | 7 ++- zun/opts.py | 32 ---------- zun/tests/base.py | 5 +- zun/tests/policy_fixture.py | 4 +- zun/tests/unit/api/base.py | 12 ++-- zun/tests/unit/common/test_clients.py | 24 ++++---- .../unit/compute/test_compute_manager.py | 4 +- zun/tests/unit/conf/test_conf.py | 6 +- zun/tests/unit/db/base.py | 4 +- .../unit/servicegroup/test_zun_service.py | 8 +-- 49 files changed, 553 insertions(+), 333 deletions(-) create mode 100644 zun/conf/api.py rename zun/{compute/config.py => conf/compute.py} (80%) create mode 100644 zun/conf/container_driver.py create mode 100644 zun/conf/database.py create mode 100644 zun/conf/docker.py create mode 100644 zun/conf/glance_client.py create mode 100644 zun/conf/path.py create mode 100644 zun/conf/services.py create mode 100644 zun/conf/zun_client.py delete mode 100644 zun/opts.py diff --git a/etc/zun/zun-config-generator.conf b/etc/zun/zun-config-generator.conf index cddde997e..aa08e523e 100644 --- a/etc/zun/zun-config-generator.conf +++ b/etc/zun/zun-config-generator.conf @@ -2,4 +2,13 @@ output_file = etc/zun/zun.conf.sample wrap_width = 79 -namespace=zun.conf +namespace = zun.conf +namespace = keystonemiddleware.auth_token +namespace = oslo.concurrency +namespace = oslo.db +namespace = oslo.log +namespace = oslo.messaging +namespace = oslo.middleware.cors +namespace = oslo.policy +namespace = oslo.service.periodic_task +namespace = oslo.service.service diff --git a/setup.cfg b/setup.cfg index 13fe334eb..def19cb4e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,7 +52,7 @@ console_scripts = oslo.config.opts = zun = zun.opts:list_opts - zun.conf = zun.opts:list_opts + zun.conf = zun.conf.opts:list_opts oslo.config.opts.defaults = zun = zun.common.config:set_cors_middleware_defaults diff --git a/tools/zun-config-generator.conf b/tools/zun-config-generator.conf index b384751a3..aa08e523e 100644 --- a/tools/zun-config-generator.conf +++ b/tools/zun-config-generator.conf @@ -2,7 +2,7 @@ output_file = etc/zun/zun.conf.sample wrap_width = 79 -namespace = zun +namespace = zun.conf namespace = keystonemiddleware.auth_token namespace = oslo.concurrency namespace = oslo.db diff --git a/tox.ini b/tox.ini index f7b94a271..ab1a83864 100644 --- a/tox.ini +++ b/tox.ini @@ -64,4 +64,4 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen [testenv:genconfig] envdir = {toxworkdir}/venv commands = - {toxinidir}/tools/gen-config + oslo-config-generator --config-file etc/zun/zun-config-generator.conf diff --git a/zun/api/app.py b/zun/api/app.py index e96c4f585..9e3d760a4 100644 --- a/zun/api/app.py +++ b/zun/api/app.py @@ -20,44 +20,10 @@ import pecan from zun.api import config as api_config from zun.api import middleware from zun.common import config as common_config -from zun.common.i18n import _ from zun.common.i18n import _LI +import zun.conf - -# Register options for the service -API_SERVICE_OPTS = [ - cfg.PortOpt('port', - default=9512, - help='The port for the zun API server.'), - cfg.IPOpt('host', - default='127.0.0.1', - help='The listen IP for the zun API server.'), - cfg.BoolOpt('enable_ssl_api', - default=False, - help=_("Enable the integrated stand-alone API to service " - "requests via HTTPS instead of HTTP. If there is a " - "front-end service performing HTTPS offloading from " - "the service, this option should be False; note, you " - "will want to change public API endpoint to represent " - "SSL termination URL with 'public_endpoint' option.")), - cfg.IntOpt('workers', - help=_("Number of workers for zun-api service. " - "The default will be the number of CPUs available.")), - cfg.IntOpt('max_limit', - default=1000, - help='The maximum number of items returned in a single ' - 'response from a collection resource.'), - cfg.StrOpt('api_paste_config', - default="api-paste.ini", - help="Configuration file for WSGI definition of API.") -] - -CONF = cfg.CONF -opt_group = cfg.OptGroup(name='api', - title='Options for the zun-api service') -CONF.register_group(opt_group) -CONF.register_opts(API_SERVICE_OPTS, opt_group) - +CONF = zun.conf.CONF LOG = log.getLogger(__name__) @@ -86,14 +52,14 @@ def setup_app(config=None): def load_app(): cfg_file = None - cfg_path = cfg.CONF.api.api_paste_config + cfg_path = CONF.api.api_paste_config if not os.path.isabs(cfg_path): cfg_file = CONF.find_file(cfg_path) elif os.path.exists(cfg_path): cfg_file = cfg_path if not cfg_file: - raise cfg.ConfigFilesNotFoundError([cfg.CONF.api.api_paste_config]) + raise cfg.ConfigFilesNotFoundError([CONF.api.api_paste_config]) LOG.info(_LI("Full WSGI config used: %s"), cfg_file) return deploy.loadapp("config:" + cfg_file) diff --git a/zun/api/hooks.py b/zun/api/hooks.py index 9b87846c0..c291a2886 100644 --- a/zun/api/hooks.py +++ b/zun/api/hooks.py @@ -18,8 +18,9 @@ from pecan import hooks from zun.common import context from zun.compute import api as compute_api +import zun.conf -CONF = cfg.CONF +CONF = zun.conf.CONF CONF.import_opt('auth_uri', 'keystonemiddleware.auth_token', group='keystone_authtoken') diff --git a/zun/api/servicegroup.py b/zun/api/servicegroup.py index 7ce0b76e5..8a799a476 100644 --- a/zun/api/servicegroup.py +++ b/zun/api/servicegroup.py @@ -11,20 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from oslo_config import cfg from oslo_utils import timeutils +import zun.conf from zun import objects -periodic_opts = [ - cfg.IntOpt('service_down_time', - default=180, - help='Max interval size between periodic tasks execution in ' - 'seconds.'), -] - -CONF = cfg.CONF -CONF.register_opts(periodic_opts) +CONF = zun.conf.CONF class ServiceGroup(object): diff --git a/zun/api/utils.py b/zun/api/utils.py index 34ffff2f8..e67a4f92e 100644 --- a/zun/api/utils.py +++ b/zun/api/utils.py @@ -14,16 +14,16 @@ # under the License. import jsonpatch -from oslo_config import cfg from oslo_utils import uuidutils import pecan import wsme from zun.common import exception from zun.common.i18n import _ +import zun.conf from zun import objects -CONF = cfg.CONF +CONF = zun.conf.CONF JSONPATCH_EXCEPTIONS = (jsonpatch.JsonPatchException, diff --git a/zun/cmd/api.py b/zun/cmd/api.py index 78e823eed..fbb8388f2 100644 --- a/zun/cmd/api.py +++ b/zun/cmd/api.py @@ -19,11 +19,10 @@ import sys -from oslo_config import cfg - from zun.common import service as zun_service +import zun.conf -CONF = cfg.CONF +CONF = zun.conf.CONF def main(): diff --git a/zun/cmd/compute.py b/zun/cmd/compute.py index a7931fad4..b7cb74c0e 100644 --- a/zun/cmd/compute.py +++ b/zun/cmd/compute.py @@ -15,7 +15,6 @@ import os import sys -from oslo_config import cfg from oslo_log import log as logging from oslo_service import service @@ -24,7 +23,9 @@ from zun.common import rpc_service from zun.common import service as zun_service from zun.common import short_id from zun.compute import manager as compute_manager +import zun.conf +CONF = zun.conf.CONF LOG = logging.getLogger(__name__) @@ -32,16 +33,16 @@ def main(): zun_service.prepare_service(sys.argv) LOG.info(_LI('Starting server in PID %s'), os.getpid()) - cfg.CONF.log_opt_values(LOG, logging.DEBUG) + CONF.log_opt_values(LOG, logging.DEBUG) - cfg.CONF.import_opt('topic', 'zun.compute.config', group='compute') + CONF.import_opt('topic', 'zun.conf.compute', group='compute') compute_id = short_id.generate_id() endpoints = [ compute_manager.Manager(), ] - server = rpc_service.Service.create(cfg.CONF.compute.topic, compute_id, + server = rpc_service.Service.create(CONF.compute.topic, compute_id, endpoints, binary='zun-compute') - launcher = service.launch(cfg.CONF, server) + launcher = service.launch(CONF, server) launcher.wait() diff --git a/zun/common/clients.py b/zun/common/clients.py index b60752060..08f642e14 100644 --- a/zun/common/clients.py +++ b/zun/common/clients.py @@ -13,54 +13,11 @@ # under the License. from glanceclient import client as glanceclient -from oslo_config import cfg from oslo_log import log as logging from zun.common import exception -from zun.common.i18n import _ from zun.common import keystone - -common_security_opts = [ - cfg.StrOpt('ca_file', - help=_('Optional CA cert file to use in SSL connections.')), - cfg.StrOpt('cert_file', - help=_('Optional PEM-formatted certificate chain file.')), - cfg.StrOpt('key_file', - help=_('Optional PEM-formatted file that contains the ' - 'private key.')), - cfg.BoolOpt('insecure', - default=False, - help=_("If set, then the server's certificate will not " - "be verified."))] - -zun_client_opts = [ - cfg.StrOpt('region_name', - help=_('Region in Identity service catalog to use for ' - 'communication with the OpenStack service.')), - cfg.StrOpt('endpoint_type', - default='publicURL', - help=_( - 'Type of endpoint in Identity service catalog to use ' - 'for communication with the OpenStack service.'))] - - -glance_client_opts = [ - cfg.StrOpt('region_name', - help=_('Region in Identity service catalog to use for ' - 'communication with the OpenStack service.')), - cfg.StrOpt('endpoint_type', - default='publicURL', - help=_( - 'Type of endpoint in Identity service catalog to use ' - 'for communication with the OpenStack service.')), - cfg.StrOpt('api_version', - default='2', - help=_('Version of Glance API to use in glanceclient.'))] - -cfg.CONF.register_opts(zun_client_opts, group='zun_client') -cfg.CONF.register_opts(glance_client_opts, group='glance_client') - -cfg.CONF.register_opts(common_security_opts, group='glance_client') +import zun.conf LOG = logging.getLogger(__name__) @@ -99,7 +56,7 @@ class OpenStackClients(object): return self._keystone def _get_client_option(self, client, option): - return getattr(getattr(cfg.CONF, '%s_client' % client), option) + return getattr(getattr(zun.conf.CONF, '%s_client' % client), option) @exception.wrap_keystone_exception def glance(self): diff --git a/zun/common/config.py b/zun/common/config.py index a55bf4836..836231001 100644 --- a/zun/common/config.py +++ b/zun/common/config.py @@ -19,16 +19,17 @@ from oslo_config import cfg from oslo_middleware import cors from zun.common import rpc +import zun.conf from zun import version def parse_args(argv, default_config_files=None): rpc.set_defaults(control_exchange='zun') - cfg.CONF(argv[1:], - project='zun', - version=version.version_info.release_string(), - default_config_files=default_config_files) - rpc.init(cfg.CONF) + zun.conf.CONF(argv[1:], + project='zun', + version=version.version_info.release_string(), + default_config_files=default_config_files) + rpc.init(zun.conf.CONF) def set_config_defaults(): diff --git a/zun/common/context.py b/zun/common/context.py index c2565be36..190e20454 100644 --- a/zun/common/context.py +++ b/zun/common/context.py @@ -11,11 +11,8 @@ # under the License. from eventlet.green import threading -from oslo_config import cfg from oslo_context import context -CONF = cfg.CONF - class RequestContext(context.RequestContext): """Extends security contexts from the OpenStack common library.""" diff --git a/zun/common/exception.py b/zun/common/exception.py index d1a3a4d0a..71b072681 100644 --- a/zun/common/exception.py +++ b/zun/common/exception.py @@ -33,11 +33,11 @@ import six from zun.common.i18n import _ from zun.common.i18n import _LE - +import zun.conf LOG = logging.getLogger(__name__) -CONF = cfg.CONF +CONF = zun.conf.CONF try: CONF.import_opt('fatal_exception_format_errors', diff --git a/zun/common/keystone.py b/zun/common/keystone.py index 0b3ae9908..c3ee33cc5 100644 --- a/zun/common/keystone.py +++ b/zun/common/keystone.py @@ -15,13 +15,13 @@ from keystoneauth1.identity import access as ka_access_plugin from keystoneauth1.identity import v3 as ka_v3 from keystoneauth1 import loading as ka_loading from keystoneclient.v3 import client as kc_v3 -from oslo_config import cfg from oslo_log import log as logging from zun.common import exception from zun.common.i18n import _LE +import zun.conf -CONF = cfg.CONF +CONF = zun.conf.CONF CFG_GROUP = 'keystone_auth' LOG = logging.getLogger(__name__) diff --git a/zun/common/paths.py b/zun/common/paths.py index 3d8d75f0e..9947d4efd 100644 --- a/zun/common/paths.py +++ b/zun/common/paths.py @@ -12,23 +12,9 @@ import os -from oslo_config import cfg +import zun.conf -PATH_OPTS = [ - cfg.StrOpt('pybasedir', - default=os.path.abspath(os.path.join(os.path.dirname(__file__), - '../')), - help='Directory where the zun python module is installed.'), - cfg.StrOpt('bindir', - default='$pybasedir/bin', - help='Directory where zun binaries are installed.'), - cfg.StrOpt('state_path', - default='$pybasedir', - help="Top-level directory for maintaining zun's state."), -] - -CONF = cfg.CONF -CONF.register_opts(PATH_OPTS) +CONF = zun.conf.CONF def basedir_def(*args): @@ -48,14 +34,14 @@ def state_path_def(*args): def basedir_rel(*args): """Return a path relative to $pybasedir.""" - return os.path.join(CONF.pybasedir, *args) + return os.path.join(CONF.common.pybasedir, *args) def bindir_rel(*args): """Return a path relative to $bindir.""" - return os.path.join(CONF.bindir, *args) + return os.path.join(CONF.common.bindir, *args) def state_path_rel(*args): """Return a path relative to $state_path.""" - return os.path.join(CONF.state_path, *args) + return os.path.join(CONF.common.state_path, *args) diff --git a/zun/common/policy.py b/zun/common/policy.py index 64b919a08..d72fe52ac 100644 --- a/zun/common/policy.py +++ b/zun/common/policy.py @@ -16,16 +16,15 @@ """Policy Engine For zun.""" import decorator -from oslo_config import cfg from oslo_log import log as logging from oslo_policy import policy import pecan from zun.common import exception - +import zun.conf _ENFORCER = None -CONF = cfg.CONF +CONF = zun.conf.CONF LOG = logging.getLogger(__name__) diff --git a/zun/common/rpc.py b/zun/common/rpc.py index da28331e2..9c5371a98 100644 --- a/zun/common/rpc.py +++ b/zun/common/rpc.py @@ -26,15 +26,14 @@ __all__ = [ 'get_notifier', ] -from oslo_config import cfg import oslo_messaging as messaging from oslo_serialization import jsonutils from zun.common import context as zun_context from zun.common import exception +import zun.conf - -CONF = cfg.CONF +CONF = zun.conf.CONF TRANSPORT = None NOTIFIER = None @@ -131,5 +130,5 @@ def get_server(target, endpoints, serializer=None): def get_notifier(service='container', host=None, publisher_id=None): assert NOTIFIER is not None if not publisher_id: - publisher_id = "%s.%s" % (service, host or CONF.host) + publisher_id = "%s.%s" % (service, host or CONF.common.host) return NOTIFIER.prepare(publisher_id=publisher_id) diff --git a/zun/common/rpc_service.py b/zun/common/rpc_service.py index f28b25054..ff96683a4 100644 --- a/zun/common/rpc_service.py +++ b/zun/common/rpc_service.py @@ -15,11 +15,11 @@ """Common RPC service and API tools for Zun.""" import eventlet -from oslo_config import cfg import oslo_messaging as messaging from oslo_service import service from zun.common import rpc +import zun.conf from zun.objects import base as objects_base from zun.servicegroup import zun_service_periodic as servicegroup @@ -30,15 +30,7 @@ from zun.servicegroup import zun_service_periodic as servicegroup # to use libamqp instead. eventlet.monkey_patch() -periodic_opts = [ - cfg.IntOpt('periodic_interval_max', - default=60, - help='Max interval size between periodic tasks execution in ' - 'seconds.'), -] - -CONF = cfg.CONF -CONF.register_opts(periodic_opts) +CONF = zun.conf.CONF class Service(service.Service): @@ -47,7 +39,7 @@ class Service(service.Service): super(Service, self).__init__() serializer = rpc.RequestContextSerializer( objects_base.ZunObjectSerializer()) - transport = messaging.get_transport(cfg.CONF) + transport = messaging.get_transport(CONF) # TODO(asalkeld) add support for version='x.y' target = messaging.Target(topic=topic, server=server) self._server = messaging.get_rpc_server(transport, target, handlers, @@ -77,7 +69,7 @@ class API(object): objects_base.ZunObjectSerializer()) if transport is None: exmods = rpc.get_allowed_exmods() - transport = messaging.get_transport(cfg.CONF, + transport = messaging.get_transport(CONF, allowed_remote_exmods=exmods) self._context = context if topic is None: diff --git a/zun/common/service.py b/zun/common/service.py index 78684d548..2ff5aa82d 100644 --- a/zun/common/service.py +++ b/zun/common/service.py @@ -14,10 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. -import socket from oslo_concurrency import processutils -from oslo_config import cfg from oslo_log import log from oslo_service import service from oslo_service import wsgi @@ -26,23 +24,11 @@ from zun.api import app from zun.common import config from zun.common import exception from zun.common.i18n import _ +import zun.conf - -service_opts = [ - cfg.StrOpt('host', - default=socket.getfqdn(), - help=_('Name of this node. This can be an opaque identifier. ' - 'It is not necessarily a hostname, FQDN, or IP address. ' - 'However, the node name must be valid within ' - 'an AMQP key, and if using ZeroMQ, a valid ' - 'hostname, FQDN, or IP address.')), -] - -CONF = cfg.CONF +CONF = zun.conf.CONF LOG = log.getLogger(__name__) -CONF.register_opts(service_opts) - def prepare_service(argv=None): if argv is None: diff --git a/zun/compute/api.py b/zun/compute/api.py index 3c71267c7..58d269ca6 100644 --- a/zun/compute/api.py +++ b/zun/compute/api.py @@ -12,9 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from zun.common import rpc_service +import zun.conf class API(rpc_service.API): @@ -28,11 +28,11 @@ class API(rpc_service.API): def __init__(self, transport=None, context=None, topic=None): if topic is None: - cfg.CONF.import_opt( - 'topic', 'zun.compute.config', group='compute') + zun.conf.CONF.import_opt( + 'topic', 'zun.conf.compute', group='compute') super(API, self).__init__( - transport, context, topic=cfg.CONF.compute.topic) + transport, context, topic=zun.conf.CONF.compute.topic) def container_create(self, context, container): return self._cast('container_create', container=container) diff --git a/zun/conf/__init__.py b/zun/conf/__init__.py index c59193ffa..6a4edb2aa 100644 --- a/zun/conf/__init__.py +++ b/zun/conf/__init__.py @@ -14,18 +14,24 @@ from oslo_config import cfg -# from zun.conf import api -# from zun.conf import compute -# from zun.conf import database -# from zun.conf import glance_client -# from zun.conf import keystone -# from zun.conf import zun_client +from zun.conf import api +from zun.conf import compute +from zun.conf import container_driver +from zun.conf import database +from zun.conf import docker +from zun.conf import glance_client +from zun.conf import path +from zun.conf import services +from zun.conf import zun_client CONF = cfg.CONF -# api.register_opts(CONF) -# compute.register_opts(CONF) -# database.register_opts(CONF) -# glance_client.register_opts(CONF) -# keystone.register_opts(CONF) -# zun_client.register_opts(CONF) +api.register_opts(CONF) +compute.register_opts(CONF) +container_driver.register_opts(CONF) +database.register_opts(CONF) +docker.register_opts(CONF) +glance_client.register_opts(CONF) +path.register_opts(CONF) +services.register_opts(CONF) +zun_client.register_opts(CONF) diff --git a/zun/conf/api.py b/zun/conf/api.py new file mode 100644 index 000000000..0a8a13763 --- /dev/null +++ b/zun/conf/api.py @@ -0,0 +1,60 @@ +# 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 + +from zun.common.i18n import _ + +api_service_opts = [ + cfg.PortOpt('port', + default=9512, + help='The port for the zun API server.'), + cfg.IPOpt('host', + default='127.0.0.1', + help='The listen IP for the zun API server.'), + cfg.BoolOpt('enable_ssl_api', + default=False, + help=_("Enable the integrated stand-alone API to service " + "requests via HTTPS instead of HTTP. If there is a " + "front-end service performing HTTPS offloading from " + "the service, this option should be False; note, you " + "will want to change public API endpoint to represent " + "SSL termination URL with 'public_endpoint' option.")), + cfg.IntOpt('workers', + help=_("Number of workers for zun-api service. " + "The default will be the number of CPUs available.")), + cfg.IntOpt('max_limit', + default=1000, + help='The maximum number of items returned in a single ' + 'response from a collection resource.'), + cfg.StrOpt('api_paste_config', + default="api-paste.ini", + help="Configuration file for WSGI definition of API.") +] + + +api_group = cfg.OptGroup(name='api', + title='Options for the zun-api service') + + +ALL_OPTS = (api_service_opts) + + +def register_opts(conf): + conf.register_group(api_group) + conf.register_opts(ALL_OPTS, api_group) + + +def list_opts(): + return { + api_group: ALL_OPTS + } diff --git a/zun/compute/config.py b/zun/conf/compute.py similarity index 80% rename from zun/compute/config.py rename to zun/conf/compute.py index 6348d1062..f251e0d00 100644 --- a/zun/compute/config.py +++ b/zun/conf/compute.py @@ -14,7 +14,8 @@ from oslo_config import cfg -SERVICE_OPTS = [ + +service_opts = [ cfg.StrOpt( 'topic', default='zun-compute', @@ -23,5 +24,14 @@ SERVICE_OPTS = [ opt_group = cfg.OptGroup( name='compute', title='Options for the zun-compute service') -cfg.CONF.register_group(opt_group) -cfg.CONF.register_opts(SERVICE_OPTS, opt_group) + +ALL_OPTS = (service_opts) + + +def register_opts(conf): + conf.register_group(opt_group) + conf.register_opts(ALL_OPTS, opt_group) + + +def list_opts(): + return {opt_group: ALL_OPTS} diff --git a/zun/conf/container_driver.py b/zun/conf/container_driver.py new file mode 100644 index 000000000..2b7035847 --- /dev/null +++ b/zun/conf/container_driver.py @@ -0,0 +1,43 @@ +# 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 + +driver_opts = [ + cfg.StrOpt('container_driver', + default='docker.driver.DockerDriver', + help="""Defines which driver to use for controlling container. +Possible values: + +* ``docker.driver.DockerDriver`` + +Services which consume this: + +* ``zun-compute`` + +Interdependencies to other options: + +* None +""") +] + + +ALL_OPTS = (driver_opts) + + +def register_opts(conf): + conf.register_opts(ALL_OPTS) + + +def list_opts(): + return {"DEFAULT": ALL_OPTS} diff --git a/zun/conf/database.py b/zun/conf/database.py new file mode 100644 index 000000000..eb618b800 --- /dev/null +++ b/zun/conf/database.py @@ -0,0 +1,29 @@ +# Copyright 2015 NEC Corporation. All rights reserved. +# +# 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 + +sql_opts = [ + cfg.StrOpt('mysql_engine', + default='InnoDB', + help='MySQL engine to use.') +] + + +def register_opts(conf): + conf.register_opts(sql_opts, 'database') + + +def list_opts(): + return {"DEFAULT": sql_opts} diff --git a/zun/conf/docker.py b/zun/conf/docker.py new file mode 100644 index 000000000..0c388adf5 --- /dev/null +++ b/zun/conf/docker.py @@ -0,0 +1,54 @@ +# 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 + +docker_group = cfg.OptGroup(name='docker', + title='Options for docker') + +docker_opts = [ + cfg.StrOpt('docker_remote_api_version', + default='1.20', + help='Docker remote api version. Override it according to ' + 'specific docker api version in your environment.'), + cfg.IntOpt('default_timeout', + default=60, + help='Default timeout in seconds for docker client ' + 'operations.'), + cfg.StrOpt('api_url', + default='unix:///var/run/docker.sock', + help='API endpoint of docker daemon'), + cfg.BoolOpt('api_insecure', + default=False, + help='If set, ignore any SSL validation issues'), + cfg.StrOpt('ca_file', + help='Location of CA certificates file for ' + 'securing docker api requests (tlscacert).'), + cfg.StrOpt('cert_file', + help='Location of TLS certificate file for ' + 'securing docker api requests (tlscert).'), + cfg.StrOpt('key_file', + help='Location of TLS private key file for ' + 'securing docker api requests (tlskey).'), +] + +ALL_OPTS = (docker_opts) + + +def register_opts(conf): + conf.register_group(docker_group) + conf.register_opts(ALL_OPTS, docker_group) + + +def list_opts(): + return {docker_group: ALL_OPTS} diff --git a/zun/conf/glance_client.py b/zun/conf/glance_client.py new file mode 100644 index 000000000..ceb2e88fd --- /dev/null +++ b/zun/conf/glance_client.py @@ -0,0 +1,61 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2012 eNovance +# +# 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 + +from zun.common.i18n import _ + + +glance_group = cfg.OptGroup(name='glance_client', + title='Options for the Glance client') + +common_security_opts = [ + cfg.StrOpt('ca_file', + help=_('Optional CA cert file to use in SSL connections.')), + cfg.StrOpt('cert_file', + help=_('Optional PEM-formatted certificate chain file.')), + cfg.StrOpt('key_file', + help=_('Optional PEM-formatted file that contains the ' + 'private key.')), + cfg.BoolOpt('insecure', + default=False, + help=_("If set, then the server's certificate will not " + "be verified."))] + +glance_client_opts = [ + cfg.StrOpt('region_name', + help=_('Region in Identity service catalog to use for ' + 'communication with the OpenStack service.')), + cfg.StrOpt('endpoint_type', + default='publicURL', + help=_( + 'Type of endpoint in Identity service catalog to use ' + 'for communication with the OpenStack service.')), + cfg.StrOpt('api_version', + default='2', + help=_('Version of Glance API to use in glanceclient.'))] + + +ALL_OPTS = (glance_client_opts + common_security_opts) + + +def register_opts(conf): + conf.register_group(glance_group) + conf.register_opts(ALL_OPTS, group=glance_group) + + +def list_opts(): + return {glance_group: ALL_OPTS} diff --git a/zun/conf/path.py b/zun/conf/path.py new file mode 100644 index 000000000..7fad097d3 --- /dev/null +++ b/zun/conf/path.py @@ -0,0 +1,41 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2012 eNovance +# +# 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. + +import os + +from oslo_config import cfg + + +path_opts = [ + cfg.StrOpt('pybasedir', + default=os.path.abspath(os.path.join(os.path.dirname(__file__), + '../')), + help='Directory where the zun python module is installed.'), + cfg.StrOpt('bindir', + default='$pybasedir/bin', + help='Directory where zun binaries are installed.'), + cfg.StrOpt('state_path', + default='$pybasedir', + help="Top-level directory for maintaining zun's state."), +] + + +def register_opts(conf): + conf.register_opts(path_opts) + + +def list_opts(): + return {"DEFAULT": path_opts} diff --git a/zun/conf/services.py b/zun/conf/services.py new file mode 100644 index 000000000..f7552b813 --- /dev/null +++ b/zun/conf/services.py @@ -0,0 +1,52 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2012 eNovance +# +# 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. + +import socket + +from oslo_config import cfg + +from zun.common.i18n import _ + +service_opts = [ + cfg.StrOpt('host', + default=socket.getfqdn(), + help=_('Name of this node. This can be an opaque identifier. ' + 'It is not necessarily a hostname, FQDN, or IP address. ' + 'However, the node name must be valid within ' + 'an AMQP key, and if using ZeroMQ, a valid ' + 'hostname, FQDN, or IP address.')), +] + +periodic_opts = [ + cfg.IntOpt('periodic_interval_max', + default=60, + help='Max interval size between periodic tasks execution in ' + 'seconds.'), + cfg.IntOpt('service_down_time', + default=180, + help='Max interval size between periodic tasks execution in ' + 'seconds.'), +] + +ALL_OPTS = (service_opts + periodic_opts) + + +def register_opts(conf): + conf.register_opts(ALL_OPTS) + + +def list_opts(): + return {"DEFAULT": ALL_OPTS} diff --git a/zun/conf/zun_client.py b/zun/conf/zun_client.py new file mode 100644 index 000000000..8243fe0a7 --- /dev/null +++ b/zun/conf/zun_client.py @@ -0,0 +1,57 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2012 eNovance +# +# 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 + +from zun.common.i18n import _ + +zun_group = cfg.OptGroup(name='zun_client', + title='Options for the Zun client') + +zun_client_opts = [ + cfg.StrOpt('region_name', + help=_('Region in Identity service catalog to use for ' + 'communication with the OpenStack service.')), + cfg.StrOpt('endpoint_type', + default='publicURL', + help=_( + 'Type of endpoint in Identity service catalog to use ' + 'for communication with the OpenStack service.'))] + + +common_security_opts = [ + cfg.StrOpt('ca_file', + help=_('Optional CA cert file to use in SSL connections.')), + cfg.StrOpt('cert_file', + help=_('Optional PEM-formatted certificate chain file.')), + cfg.StrOpt('key_file', + help=_('Optional PEM-formatted file that contains the ' + 'private key.')), + cfg.BoolOpt('insecure', + default=False, + help=_("If set, then the server's certificate will not " + "be verified."))] + +ALL_OPTS = (zun_client_opts + common_security_opts) + + +def register_opts(conf): + conf.register_group(zun_group) + conf.register_opts(zun_client_opts, group=zun_group) + + +def list_opts(): + return {zun_group: ALL_OPTS} diff --git a/zun/container/docker/driver.py b/zun/container/docker/driver.py index 3b097ae09..6e5bac049 100644 --- a/zun/container/docker/driver.py +++ b/zun/container/docker/driver.py @@ -14,7 +14,6 @@ from docker import errors import six -from oslo_config import cfg from oslo_log import log as logging from zun.common.utils import check_container_id @@ -24,7 +23,6 @@ from zun.objects import fields LOG = logging.getLogger(__name__) -CONF = cfg.CONF class DockerDriver(driver.ContainerDriver): diff --git a/zun/container/docker/utils.py b/zun/container/docker/utils.py index 0aa0a1237..1d7d48501 100644 --- a/zun/container/docker/utils.py +++ b/zun/container/docker/utils.py @@ -17,40 +17,12 @@ from docker import client from docker import errors from docker import tls from docker.utils import utils -from oslo_config import cfg from zun.common import exception +import zun.conf from zun import objects - -docker_opts = [ - cfg.StrOpt('docker_remote_api_version', - default='1.20', - help='Docker remote api version. Override it according to ' - 'specific docker api version in your environment.'), - cfg.IntOpt('default_timeout', - default=60, - help='Default timeout in seconds for docker client ' - 'operations.'), - cfg.StrOpt('api_url', - default='unix:///var/run/docker.sock', - help='API endpoint of docker daemon'), - cfg.BoolOpt('api_insecure', - default=False, - help='If set, ignore any SSL validation issues'), - cfg.StrOpt('ca_file', - help='Location of CA certificates file for ' - 'securing docker api requests (tlscacert).'), - cfg.StrOpt('cert_file', - help='Location of TLS certificate file for ' - 'securing docker api requests (tlscert).'), - cfg.StrOpt('key_file', - help='Location of TLS private key file for ' - 'securing docker api requests (tlskey).'), -] - -CONF = cfg.CONF -CONF.register_opts(docker_opts, 'docker') +CONF = zun.conf.CONF def parse_docker_image(image): diff --git a/zun/container/driver.py b/zun/container/driver.py index 2ad4f194b..bf7f1833f 100644 --- a/zun/container/driver.py +++ b/zun/container/driver.py @@ -13,36 +13,15 @@ import sys -from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils from zun.common.i18n import _LE from zun.common.i18n import _LI - +import zun.conf LOG = logging.getLogger(__name__) - -driver_opts = [ - cfg.StrOpt('container_driver', - default='docker.driver.DockerDriver', - help="""Defines which driver to use for controlling container. - -Possible values: - -* ``docker.driver.DockerDriver`` - -Services which consume this: - -* ``zun-compute`` - -Interdependencies to other options: - -* None -""") -] -CONF = cfg.CONF -CONF.register_opts(driver_opts) +CONF = zun.conf.CONF def load_container_driver(container_driver=None): diff --git a/zun/db/__init__.py b/zun/db/__init__.py index f8d2c18f5..016da32eb 100644 --- a/zun/db/__init__.py +++ b/zun/db/__init__.py @@ -12,20 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg from oslo_db import options from zun.common import paths - - -sql_opts = [ - cfg.StrOpt('mysql_engine', - default='InnoDB', - help='MySQL engine to use.') -] +import zun.conf _DEFAULT_SQL_CONNECTION = 'sqlite:///' + paths.state_path_def('zun.sqlite') -cfg.CONF.register_opts(sql_opts, 'database') -options.set_defaults(cfg.CONF) -options.set_defaults(cfg.CONF, _DEFAULT_SQL_CONNECTION, 'zun.sqlite') +options.set_defaults(zun.conf.CONF) +options.set_defaults(zun.conf.CONF, _DEFAULT_SQL_CONNECTION, 'zun.sqlite') diff --git a/zun/db/api.py b/zun/db/api.py index f5e0bdb95..2bb6e187a 100644 --- a/zun/db/api.py +++ b/zun/db/api.py @@ -17,14 +17,16 @@ Base API for Database import abc -from oslo_config import cfg from oslo_db import api as db_api import six +import zun.conf + """Add the database backend mapping here""" _BACKEND_MAPPING = {'sqlalchemy': 'zun.db.sqlalchemy.api'} -IMPL = db_api.DBAPI.from_config(cfg.CONF, backend_mapping=_BACKEND_MAPPING, +IMPL = db_api.DBAPI.from_config(zun.conf.CONF, + backend_mapping=_BACKEND_MAPPING, lazy=True) diff --git a/zun/db/migration.py b/zun/db/migration.py index ad0214508..7088ecc74 100644 --- a/zun/db/migration.py +++ b/zun/db/migration.py @@ -13,18 +13,20 @@ """Database setup and migration commands.""" -from oslo_config import cfg from stevedore import driver +import zun.conf + _IMPL = None def get_backend(): global _IMPL if not _IMPL: - cfg.CONF.import_opt('backend', 'oslo_db.options', group='database') + zun.conf.CONF.import_opt('backend', + 'oslo_db.options', group='database') _IMPL = driver.DriverManager("zun.database.migration_backend", - cfg.CONF.database.backend).driver + zun.conf.CONF.database.backend).driver return _IMPL diff --git a/zun/db/sqlalchemy/api.py b/zun/db/sqlalchemy/api.py index 500d6bf6a..653ad3d2f 100644 --- a/zun/db/sqlalchemy/api.py +++ b/zun/db/sqlalchemy/api.py @@ -14,7 +14,6 @@ """SQLAlchemy storage backend.""" -from oslo_config import cfg from oslo_db import exception as db_exc from oslo_db.sqlalchemy import session as db_session from oslo_db.sqlalchemy import utils as db_utils @@ -26,10 +25,11 @@ from sqlalchemy.orm.exc import NoResultFound from zun.common import exception from zun.common.i18n import _ +import zun.conf from zun.db import api from zun.db.sqlalchemy import models -CONF = cfg.CONF +CONF = zun.conf.CONF _FACADE = None diff --git a/zun/db/sqlalchemy/migration.py b/zun/db/sqlalchemy/migration.py index f2c4ca66a..9d78dfb98 100644 --- a/zun/db/sqlalchemy/migration.py +++ b/zun/db/sqlalchemy/migration.py @@ -16,9 +16,10 @@ import os -from oslo_config import cfg from oslo_db.sqlalchemy.migration_cli import manager +import zun.conf + _MANAGER = None @@ -31,7 +32,7 @@ def get_manager(): os.path.join(os.path.dirname(__file__), 'alembic')) migration_config = {'alembic_ini_path': alembic_path, 'alembic_repo_path': migrate_path, - 'db_url': cfg.CONF.database.connection} + 'db_url': zun.conf.CONF.database.connection} _MANAGER = manager.MigrationManager(migration_config) return _MANAGER diff --git a/zun/db/sqlalchemy/models.py b/zun/db/sqlalchemy/models.py index f0b5481db..4fd754293 100644 --- a/zun/db/sqlalchemy/models.py +++ b/zun/db/sqlalchemy/models.py @@ -16,7 +16,6 @@ SQLAlchemy models for container service import json -from oslo_config import cfg from oslo_db.sqlalchemy import models import six.moves.urllib.parse as urlparse from sqlalchemy import Boolean @@ -29,11 +28,13 @@ from sqlalchemy import schema from sqlalchemy import String from sqlalchemy.types import TypeDecorator, TEXT +import zun.conf + def table_args(): - engine_name = urlparse.urlparse(cfg.CONF.database.connection).scheme + engine_name = urlparse.urlparse(zun.conf.CONF.database.connection).scheme if engine_name == 'mysql': - return {'mysql_engine': cfg.CONF.database.mysql_engine, + return {'mysql_engine': zun.conf.CONF.database.mysql_engine, 'mysql_charset': "utf8"} return None diff --git a/zun/opts.py b/zun/opts.py deleted file mode 100644 index 0288e8bf2..000000000 --- a/zun/opts.py +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - -import itertools - -import zun.api.app -import zun.common.keystone -import zun.common.rpc_service -import zun.common.service -import zun.compute.config - - -def list_opts(): - return [ - ('DEFAULT', - itertools.chain( - zun.common.rpc_service.periodic_opts, - zun.common.service.service_opts, - )), - ('api', zun.api.app.API_SERVICE_OPTS), - ('compute', zun.compute.config.SERVICE_OPTS), - ('keystone_auth', zun.common.keystone.keystone_auth_opts), - ] diff --git a/zun/tests/base.py b/zun/tests/base.py index b2524cf58..a8143baf2 100644 --- a/zun/tests/base.py +++ b/zun/tests/base.py @@ -24,13 +24,14 @@ import pecan import testscenarios from zun.common import context as zun_context +import zun.conf from zun.objects import base as objects_base from zun.tests import conf_fixture from zun.tests import policy_fixture -CONF = cfg.CONF +CONF = zun.conf.CONF try: log.register_options(CONF) except cfg.ArgsAlreadyParsedError: @@ -43,7 +44,7 @@ class BaseTestCase(testscenarios.WithScenarios, base.BaseTestCase): def setUp(self): super(BaseTestCase, self).setUp() - self.addCleanup(cfg.CONF.reset) + self.addCleanup(CONF.reset) class TestCase(base.BaseTestCase): diff --git a/zun/tests/policy_fixture.py b/zun/tests/policy_fixture.py index 8aa7a2867..441260f13 100644 --- a/zun/tests/policy_fixture.py +++ b/zun/tests/policy_fixture.py @@ -13,15 +13,15 @@ import os import fixtures -from oslo_config import cfg from oslo_policy import _parser from oslo_policy import opts as policy_opts from zun.common import policy as zun_policy +import zun.conf from zun.tests import fake_policy -CONF = cfg.CONF +CONF = zun.conf.CONF class PolicyFixture(fixtures.Fixture): diff --git a/zun/tests/unit/api/base.py b/zun/tests/unit/api/base.py index 561bcd15f..5f1e21616 100644 --- a/zun/tests/unit/api/base.py +++ b/zun/tests/unit/api/base.py @@ -16,12 +16,12 @@ # NOTE(deva): import auth_token so we can override a config option from keystonemiddleware import auth_token # noqa -from oslo_config import cfg import pecan import pecan.testing from six.moves.urllib import parse as urlparse from zun.api import hooks +import zun.conf from zun.tests.unit.db import base PATH_PREFIX = '/v1' @@ -37,10 +37,12 @@ class FunctionalTest(base.DbTestCase): def setUp(self): super(FunctionalTest, self).setUp() - cfg.CONF.set_override("auth_version", "v2.0", - group='keystone_authtoken', enforce_type=True) - cfg.CONF.set_override("admin_user", "admin", - group='keystone_authtoken', enforce_type=True) + zun.conf.CONF.set_override("auth_version", "v2.0", + group='keystone_authtoken', + enforce_type=True) + zun.conf.CONF.set_override("admin_user", "admin", + group='keystone_authtoken', + enforce_type=True) # Determine where we are so we can set up paths in the config root_dir = self.get_path() diff --git a/zun/tests/unit/common/test_clients.py b/zun/tests/unit/common/test_clients.py index 615b837a9..f1a8a6a75 100644 --- a/zun/tests/unit/common/test_clients.py +++ b/zun/tests/unit/common/test_clients.py @@ -14,10 +14,9 @@ import mock from glanceclient import client as glanceclient -from oslo_config import cfg - from zun.common import clients from zun.common import exception +import zun.conf from zun.tests import base @@ -26,10 +25,10 @@ class ClientsTest(base.BaseTestCase): def setUp(self): super(ClientsTest, self).setUp() - cfg.CONF.set_override('auth_uri', 'http://server.test:5000/v2.0', - group='keystone_authtoken') - cfg.CONF.import_opt('api_version', 'zun.common.clients', - group='glance_client') + zun.conf.CONF.set_override('auth_uri', 'http://server.test:5000/v2.0', + group='keystone_authtoken') + zun.conf.CONF.import_opt('api_version', 'zun.conf.glance_client', + group='glance_client') @mock.patch.object(clients.OpenStackClients, 'keystone') def test_url_for(self, mock_keystone): @@ -44,10 +43,10 @@ class ClientsTest(base.BaseTestCase): def test_zun_url(self, mock_keystone): fake_region = 'fake_region' fake_endpoint = 'fake_endpoint' - cfg.CONF.set_override('region_name', fake_region, - group='zun_client') - cfg.CONF.set_override('endpoint_type', fake_endpoint, - group='zun_client') + zun.conf.CONF.set_override('region_name', fake_region, + group='zun_client') + zun.conf.CONF.set_override('endpoint_type', fake_endpoint, + group='zun_client') obj = clients.OpenStackClients(None) obj.zun_url() @@ -70,7 +69,7 @@ class ClientsTest(base.BaseTestCase): obj._glance = None obj.glance() mock_call.assert_called_once_with( - cfg.CONF.glance_client.api_version, + zun.conf.CONF.glance_client.api_version, endpoint='url_from_keystone', username=None, token='3bcc3d3a03f44e3d8377f9247b0ad155', auth_url='keystone_url', @@ -83,7 +82,8 @@ class ClientsTest(base.BaseTestCase): self._test_clients_glance(None) def test_clients_glance_region(self): - cfg.CONF.set_override('region_name', 'myregion', group='glance_client') + zun.conf.CONF.set_override('region_name', + 'myregion', group='glance_client') self._test_clients_glance('myregion') def test_clients_glance_noauth(self): diff --git a/zun/tests/unit/compute/test_compute_manager.py b/zun/tests/unit/compute/test_compute_manager.py index 9dcd484ad..75e80bc66 100644 --- a/zun/tests/unit/compute/test_compute_manager.py +++ b/zun/tests/unit/compute/test_compute_manager.py @@ -14,10 +14,10 @@ import mock -from oslo_config import cfg from zun.common import exception from zun.compute import manager +import zun.conf from zun.objects.container import Container from zun.objects import fields from zun.tests import base @@ -29,7 +29,7 @@ class TestManager(base.TestCase): def setUp(self): super(TestManager, self).setUp() - cfg.CONF.set_override( + zun.conf.CONF.set_override( 'container_driver', 'zun.tests.unit.container.fake_driver.FakeDriver') self.compute_manager = manager.Manager() diff --git a/zun/tests/unit/conf/test_conf.py b/zun/tests/unit/conf/test_conf.py index 0769cc618..74f6facbc 100644 --- a/zun/tests/unit/conf/test_conf.py +++ b/zun/tests/unit/conf/test_conf.py @@ -13,6 +13,7 @@ import collections import mock from oslo_config import cfg +import six from zun.conf import opts from zun.tests import base @@ -22,7 +23,10 @@ class ConfTestCase(base.TestCase): def test_list_opts(self): for group, opt_list in opts.list_opts(): - self.assertIsInstance(group, cfg.OptGroup) + if isinstance(group, six.string_types): + self.assertEqual(group, 'DEFAULT') + else: + self.assertIsInstance(group, cfg.OptGroup) for opt in opt_list: self.assertIsInstance(opt, cfg.Opt) diff --git a/zun/tests/unit/db/base.py b/zun/tests/unit/db/base.py index 35d8280b5..8a7a323cb 100644 --- a/zun/tests/unit/db/base.py +++ b/zun/tests/unit/db/base.py @@ -13,8 +13,8 @@ """Zun DB test base class.""" import fixtures -from oslo_config import cfg +import zun.conf from zun.db import api as db_api from zun.db.sqlalchemy import api as sqla_api from zun.db.sqlalchemy import migration @@ -22,7 +22,7 @@ from zun.db.sqlalchemy import models from zun.tests import base -CONF = cfg.CONF +CONF = zun.conf.CONF _DB_CACHE = None diff --git a/zun/tests/unit/servicegroup/test_zun_service.py b/zun/tests/unit/servicegroup/test_zun_service.py index 64b8e1780..ca73ad838 100644 --- a/zun/tests/unit/servicegroup/test_zun_service.py +++ b/zun/tests/unit/servicegroup/test_zun_service.py @@ -12,7 +12,7 @@ import mock -from zun.common.rpc_service import CONF +import zun.conf from zun import objects from zun.servicegroup import zun_service_periodic as periodic from zun.tests import base @@ -37,7 +37,7 @@ class ZunServicePeriodicTestCase(base.BaseTestCase): mock_srv_create, mock_srv_get ): - p_task = periodic.ZunServicePeriodicTasks(CONF, + p_task = periodic.ZunServicePeriodicTasks(zun.conf.CONF, 'fake-conductor') mock_srv_get.return_value = None @@ -53,7 +53,7 @@ class ZunServicePeriodicTestCase(base.BaseTestCase): def test_update_zun_service_on_restart(self, mock_srv_create, mock_srv_get): - p_task = periodic.ZunServicePeriodicTasks(CONF, + p_task = periodic.ZunServicePeriodicTasks(zun.conf.CONF, 'fake-conductor') mock_srv_get.return_value = self.fake_srv @@ -64,7 +64,7 @@ class ZunServicePeriodicTestCase(base.BaseTestCase): self.fake_srv_refresh.assert_called_once_with() def test_update_zun_service_regular(self): - p_task = periodic.ZunServicePeriodicTasks(CONF, + p_task = periodic.ZunServicePeriodicTasks(zun.conf.CONF, 'fake-conductor') p_task.zun_service_ref = self.fake_srv