diff --git a/ovn_octavia_provider/common/clients.py b/ovn_octavia_provider/common/clients.py index ed463d7b..c03b932b 100644 --- a/ovn_octavia_provider/common/clients.py +++ b/ovn_octavia_provider/common/clients.py @@ -118,11 +118,19 @@ class NeutronAuth(metaclass=Singleton): try: ksession = KeystoneSession('neutron') - kwargs = {} + kwargs = {'region_name': CONF.neutron.region_name} + try: + interface = CONF.neutron.valid_interfaces[0] + except (TypeError, LookupError): + interface = CONF.neutron.valid_interfaces + if interface: + kwargs['interface'] = interface if CONF.neutron.endpoint_override: kwargs['network_endpoint_override'] = ( CONF.neutron.endpoint_override) - + if CONF.neutron.endpoint_override.startswith("https"): + kwargs['insecure'] = CONF.neutron.insecure + kwargs['cacert'] = CONF.neutron.cafile self.network_proxy = openstack.connection.Connection( session=ksession.session, **kwargs).network except Exception: diff --git a/ovn_octavia_provider/tests/unit/common/test_clients.py b/ovn_octavia_provider/tests/unit/common/test_clients.py index e9ad4935..704ed027 100644 --- a/ovn_octavia_provider/tests/unit/common/test_clients.py +++ b/ovn_octavia_provider/tests/unit/common/test_clients.py @@ -99,6 +99,9 @@ class TestNeutronAuth(base.BaseTestCase): def setUp(self): super().setUp() config.register_opts() + self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF)) + self.conf.config(group='neutron', region_name='RegionOne', + valid_interfaces='internal') self.mock_client = mock.patch( 'openstack.connection.Connection').start() clients.Singleton._instances = {} @@ -107,7 +110,8 @@ class TestNeutronAuth(base.BaseTestCase): def test_init(self, mock_ks): clients.NeutronAuth() self.mock_client.assert_called_once_with( - session=mock_ks().session) + session=mock_ks().session, interface='internal', + region_name='RegionOne') def test_singleton(self): c1 = clients.NeutronAuth() @@ -133,7 +137,8 @@ class TestNeutronAuth(base.BaseTestCase): def test_get_client(self, mock_ks): clients.get_neutron_client() self.mock_client.assert_called_once_with( - session=mock_ks().session) + session=mock_ks().session, interface='internal', + region_name='RegionOne') @mock.patch.object(clients, 'NeutronAuth', side_effect=[RuntimeError]) def test_get_client_error(self, mock_ks): diff --git a/releasenotes/notes/add-neutron-client-interface-info-6a018cad49b5d240.yaml b/releasenotes/notes/add-neutron-client-interface-info-6a018cad49b5d240.yaml new file mode 100644 index 00000000..433de76f --- /dev/null +++ b/releasenotes/notes/add-neutron-client-interface-info-6a018cad49b5d240.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + [`bug 2110488 `_] + Fixed wrong endpoint information in Neutron client configuration.