Browse Source

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
changes/77/357077/6
Hieu LE 6 years ago
parent
commit
e4627ab6dd
  1. 2
      magnum/conf/__init__.py
  2. 22
      magnum/conf/paths.py
  3. 2
      magnum/db/__init__.py
  4. 3
      magnum/opts.py
  5. 6
      magnum/tests/unit/conf/test_conf.py
  6. 4
      magnum/tests/unit/template/test_template.py

2
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)

22
magnum/common/paths.py → 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 bindir_rel(*args):
"""Return a path relative to $bindir."""
return os.path.join(CONF.bindir, *args)
def register_opts(conf):
conf.register_opts(path_opts)
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
}

2
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 = [

3
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,
)),

6
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)

4
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')])

Loading…
Cancel
Save