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
This commit is contained in:
Hongbin Lu 2016-12-25 12:01:41 -06:00
parent 4c860226c7
commit 0f118fee78
3 changed files with 14 additions and 9 deletions

View File

@ -25,14 +25,15 @@ PORT_POSTFIX = 'port'
def get_neutron_client(*args, **kwargs): def get_neutron_client(*args, **kwargs):
auth_plugin = ks_loading.load_auth_from_conf_options( conf_group = kuryr_config.neutron_group.name
cfg.CONF, 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, session = ks_loading.load_session_from_conf_options(cfg.CONF, conf_group,
'neutron',
auth=auth_plugin) auth=auth_plugin)
endpoint_type = getattr(getattr(cfg.CONF, conf_group), 'endpoint_type')
return client.Client(session=session, return client.Client(session=session,
auth=auth_plugin, auth=auth_plugin,
endpoint_type=cfg.CONF.neutron.endpoint_type) endpoint_type=endpoint_type)
def get_hostname(): def get_hostname():

View File

@ -12,19 +12,21 @@
from oslo_config import cfg from oslo_config import cfg
from kuryr.lib import config as kuryr_config
from kuryr.tests.unit import base from kuryr.tests.unit import base
class ConfigurationTest(base.TestCase): class ConfigurationTest(base.TestCase):
def test_defaults(self): def test_defaults(self):
neutron_group = getattr(cfg.CONF, kuryr_config.neutron_group.name)
self.assertEqual('kuryr', self.assertEqual('kuryr',
cfg.CONF.neutron.default_subnetpool_v4) neutron_group.default_subnetpool_v4)
self.assertEqual('kuryr6', self.assertEqual('kuryr6',
cfg.CONF.neutron.default_subnetpool_v6) neutron_group.default_subnetpool_v6)
self.assertEqual('public', self.assertEqual('public',
cfg.CONF.neutron.endpoint_type) neutron_group.endpoint_type)
self.assertEqual('baremetal', self.assertEqual('baremetal',
cfg.CONF.deployment_type) cfg.CONF.deployment_type)
self.assertEqual('kuryr.lib.binding.drivers.veth', self.assertEqual('kuryr.lib.binding.drivers.veth',

View File

@ -16,6 +16,7 @@ import socket
from oslo_config import cfg from oslo_config import cfg
from kuryr.lib import config as kuryr_config
from kuryr.lib import utils from kuryr.lib import utils
from kuryr.tests.unit import base from kuryr.tests.unit import base
@ -46,10 +47,11 @@ class TestKuryrUtils(base.TestCase):
mock_auth_loader.return_value = fake_auth mock_auth_loader.return_value = fake_auth
mock_session_loader.return_value = fake_session mock_session_loader.return_value = fake_session
utils.get_neutron_client() utils.get_neutron_client()
neutron_group = getattr(cfg.CONF, kuryr_config.neutron_group.name)
mock_client.assert_called_once_with( mock_client.assert_called_once_with(
auth=fake_auth, auth=fake_auth,
session=fake_session, 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') @mock.patch.object(socket, 'gethostname', return_value='fake_hostname')
def test_get_hostname(self, mock_get_hostname): def test_get_hostname(self, mock_get_hostname):