From 0f118fee787415a477f9d9915be65478d6e18a76 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 25 Dec 2016 12:01:41 -0600 Subject: [PATCH] Avoid hard-coding of 'neutron' config group The name of neutron config group is specified in file kuryr/lib/config.py. If we want to retrieve the name of this config group, we should read it from that file instead of hard-coding it. Change-Id: Id6ebc4fc8433a802edc04b941a591e03d23c489e --- kuryr/lib/utils.py | 11 ++++++----- kuryr/tests/unit/test_config.py | 8 +++++--- kuryr/tests/unit/test_utils.py | 4 +++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/kuryr/lib/utils.py b/kuryr/lib/utils.py index 508c2e71..8bd0c01e 100644 --- a/kuryr/lib/utils.py +++ b/kuryr/lib/utils.py @@ -25,14 +25,15 @@ PORT_POSTFIX = 'port' def get_neutron_client(*args, **kwargs): - auth_plugin = ks_loading.load_auth_from_conf_options( - cfg.CONF, kuryr_config.neutron_group.name) - session = ks_loading.load_session_from_conf_options(cfg.CONF, - 'neutron', + conf_group = kuryr_config.neutron_group.name + auth_plugin = ks_loading.load_auth_from_conf_options(cfg.CONF, conf_group) + session = ks_loading.load_session_from_conf_options(cfg.CONF, conf_group, auth=auth_plugin) + endpoint_type = getattr(getattr(cfg.CONF, conf_group), 'endpoint_type') + return client.Client(session=session, auth=auth_plugin, - endpoint_type=cfg.CONF.neutron.endpoint_type) + endpoint_type=endpoint_type) def get_hostname(): diff --git a/kuryr/tests/unit/test_config.py b/kuryr/tests/unit/test_config.py index adf91997..90cf118a 100644 --- a/kuryr/tests/unit/test_config.py +++ b/kuryr/tests/unit/test_config.py @@ -12,19 +12,21 @@ from oslo_config import cfg +from kuryr.lib import config as kuryr_config from kuryr.tests.unit import base class ConfigurationTest(base.TestCase): def test_defaults(self): + neutron_group = getattr(cfg.CONF, kuryr_config.neutron_group.name) self.assertEqual('kuryr', - cfg.CONF.neutron.default_subnetpool_v4) + neutron_group.default_subnetpool_v4) self.assertEqual('kuryr6', - cfg.CONF.neutron.default_subnetpool_v6) + neutron_group.default_subnetpool_v6) self.assertEqual('public', - cfg.CONF.neutron.endpoint_type) + neutron_group.endpoint_type) self.assertEqual('baremetal', cfg.CONF.deployment_type) self.assertEqual('kuryr.lib.binding.drivers.veth', diff --git a/kuryr/tests/unit/test_utils.py b/kuryr/tests/unit/test_utils.py index 06186e39..cd1141f3 100644 --- a/kuryr/tests/unit/test_utils.py +++ b/kuryr/tests/unit/test_utils.py @@ -16,6 +16,7 @@ import socket from oslo_config import cfg +from kuryr.lib import config as kuryr_config from kuryr.lib import utils from kuryr.tests.unit import base @@ -46,10 +47,11 @@ class TestKuryrUtils(base.TestCase): mock_auth_loader.return_value = fake_auth mock_session_loader.return_value = fake_session utils.get_neutron_client() + neutron_group = getattr(cfg.CONF, kuryr_config.neutron_group.name) mock_client.assert_called_once_with( auth=fake_auth, session=fake_session, - endpoint_type=cfg.CONF.neutron.endpoint_type) + endpoint_type=neutron_group.endpoint_type) @mock.patch.object(socket, 'gethostname', return_value='fake_hostname') def test_get_hostname(self, mock_get_hostname):