From e4627ab6dd378c748aac100b19a17e0a9820fc29 Mon Sep 17 00:00:00 2001 From: Hieu LE Date: Thu, 18 Aug 2016 17:29:56 +0700 Subject: [PATCH] Centralize config option: paths section Centralize config option of Paths section. Replace oslo_conf cfg to magnum.conf. Modify test_conf test case for covering DEFAULT section Change-Id: I45775016cdfd7e762c9faa5aa18fc020a07c8134 Implements: blueprint centralize-config-magnum --- magnum/conf/__init__.py | 2 ++ magnum/{common => conf}/paths.py | 22 +++++++-------------- magnum/db/__init__.py | 2 +- magnum/opts.py | 3 +-- magnum/tests/unit/conf/test_conf.py | 6 +++++- magnum/tests/unit/template/test_template.py | 4 +--- 6 files changed, 17 insertions(+), 22 deletions(-) rename magnum/{common => conf}/paths.py (80%) diff --git a/magnum/conf/__init__.py b/magnum/conf/__init__.py index 19bf4fccac..7eaedf5c31 100644 --- a/magnum/conf/__init__.py +++ b/magnum/conf/__init__.py @@ -31,6 +31,7 @@ from magnum.conf import heat from magnum.conf import magnum_client from magnum.conf import neutron from magnum.conf import nova +from magnum.conf import paths # from magnum.conf import x509 CONF = cfg.CONF @@ -51,4 +52,5 @@ heat.register_opts(CONF) magnum_client.register_opts(CONF) neutron.register_opts(CONF) nova.register_opts(CONF) +paths.register_opts(CONF) # x509.register_opts(CONF) diff --git a/magnum/common/paths.py b/magnum/conf/paths.py similarity index 80% rename from magnum/common/paths.py rename to magnum/conf/paths.py index fdd2a95d71..e9b6dc94d3 100644 --- a/magnum/common/paths.py +++ b/magnum/conf/paths.py @@ -19,7 +19,7 @@ import os from oslo_config import cfg -PATH_OPTS = [ +path_opts = [ cfg.StrOpt('pybasedir', default=os.path.abspath(os.path.join(os.path.dirname(__file__), '../')), @@ -32,9 +32,6 @@ PATH_OPTS = [ help="Top-level directory for maintaining magnum's state."), ] -CONF = cfg.CONF -CONF.register_opts(PATH_OPTS) - def basedir_def(*args): """Return an uninterpolated path relative to $pybasedir.""" @@ -51,16 +48,11 @@ def state_path_def(*args): return os.path.join('$state_path', *args) -def basedir_rel(*args): - """Return a path relative to $pybasedir.""" - return os.path.join(CONF.pybasedir, *args) +def register_opts(conf): + conf.register_opts(path_opts) -def bindir_rel(*args): - """Return a path relative to $bindir.""" - return os.path.join(CONF.bindir, *args) - - -def state_path_rel(*args): - """Return a path relative to $state_path.""" - return os.path.join(CONF.state_path, *args) +def list_opts(): + return { + "DEFAULT": path_opts + } diff --git a/magnum/db/__init__.py b/magnum/db/__init__.py index d7b1758df8..1e5b8a1370 100644 --- a/magnum/db/__init__.py +++ b/magnum/db/__init__.py @@ -15,7 +15,7 @@ from oslo_config import cfg from oslo_db import options -from magnum.common import paths +from magnum.conf import paths sql_opts = [ diff --git a/magnum/opts.py b/magnum/opts.py index cc53e0c172..15e48038bf 100644 --- a/magnum/opts.py +++ b/magnum/opts.py @@ -29,8 +29,7 @@ import magnum.drivers.common.template_def def list_opts(): return [ ('DEFAULT', - itertools.chain(magnum.common.paths.PATH_OPTS, - magnum.common.utils.UTILS_OPTS, + itertools.chain(magnum.common.utils.UTILS_OPTS, magnum.common.rpc_service.periodic_opts, magnum.common.service.service_opts, )), diff --git a/magnum/tests/unit/conf/test_conf.py b/magnum/tests/unit/conf/test_conf.py index bfe64e518c..0ee33a8472 100644 --- a/magnum/tests/unit/conf/test_conf.py +++ b/magnum/tests/unit/conf/test_conf.py @@ -15,6 +15,7 @@ import collections import mock from oslo_config import cfg +import six from magnum.conf import opts from magnum.tests import base @@ -24,7 +25,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/magnum/tests/unit/template/test_template.py b/magnum/tests/unit/template/test_template.py index 546a5b9a24..f7ed985c15 100644 --- a/magnum/tests/unit/template/test_template.py +++ b/magnum/tests/unit/template/test_template.py @@ -18,11 +18,9 @@ from glob import glob from oslo_config import cfg from yaml import load - -from magnum.common import paths +from magnum.conf import paths from magnum.tests import base - cfg.CONF.register_opts([cfg.StrOpt('template_path', default=paths.basedir_def('templates'), help='Heat template path')])