add region_name in get neutron client to support multi-region scene

kuryr should support neutron client in multi-region scene as follows:

https://bugs.launchpad.net/kuryr/+bug/1831684

Closes-Bug: 1831684

Change-Id: I91315885a56c5cfb313b73b1eddc3935bc200c6c
This commit is contained in:
zhangchi 2019-08-27 09:25:54 +08:00 committed by Zhang Chi
parent b10acd57ea
commit 50da6c1b30
3 changed files with 8 additions and 2 deletions

View File

@ -55,6 +55,9 @@ neutron_opts = [
cfg.IntOpt('vif_plugging_timeout',
default=0,
help=_("Seconds to wait for port to become active")),
cfg.StrOpt('region_name',
default='RegionOne',
help=_('Region name of the neturon endpoint to use.')),
cfg.StrOpt('endpoint_type',
default='public',
choices=['public', 'admin', 'internal'],

View File

@ -40,10 +40,12 @@ def get_neutron_client(*args, **kwargs):
auth_plugin = get_auth_plugin(conf_group)
session = get_keystone_session(conf_group, auth_plugin)
endpoint_type = getattr(getattr(cfg.CONF, conf_group), 'endpoint_type')
region_name = getattr(getattr(cfg.CONF, conf_group), 'region_name')
return client.Client(session=session,
auth=auth_plugin,
endpoint_type=endpoint_type)
endpoint_type=endpoint_type,
region_name=region_name)
def get_hostname():

View File

@ -73,7 +73,8 @@ class TestKuryrUtils(base.TestCase):
mock_client.assert_called_once_with(
auth=fake_auth,
session=fake_session,
endpoint_type=neutron_group.endpoint_type)
endpoint_type=neutron_group.endpoint_type,
region_name=neutron_group.region_name)
@mock.patch.object(socket, 'gethostname', return_value='fake_hostname')
def test_get_hostname(self, mock_get_hostname):