From c51d6d117af4c739106903f5a525b82434893cff Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Wed, 17 Aug 2022 14:00:33 +0200 Subject: [PATCH] [OVN] Try to bind ports only to the ovn-controller agents Patch [1] added getting ovn agents from the agents cache and check if agent is alive to bound port to it. Small issue with it was that it could check e.g. ovn metadata agent from the host as it was only filtering agents by the host on which they are. This patch adds filter on the agent_type so only ovn-controller agents are taken from the cache. [1] https://review.opendev.org/c/openstack/neutron/+/825428 Conflicts: neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py Related-Bug: #1958501 Change-Id: If065204d7521c480656a22fb078bbe6273b5fc70 (cherry picked from commit eda45de8391597b6f29d76715996755cb1777dd0) (cherry picked from commit 601b01f82b6fcaa699eda556c8094208fd20f10b) --- .../ml2/drivers/ovn/mech_driver/mech_driver.py | 4 +++- .../ml2/drivers/ovn/mech_driver/test_mech_driver.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py index fca0a532dd0..70345931f17 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py @@ -951,7 +951,9 @@ class OVNMechanismDriver(api.MechanismDriver): # OVN chassis information is needed to ensure a valid port bind. # Collect port binding data and refuse binding if the OVN chassis # cannot be found or is dead. - agents = n_agent.AgentCache().get_agents({'host': context.host}) + agents = n_agent.AgentCache().get_agents( + {'host': context.host, + 'agent_type': ovn_const.OVN_CONTROLLER_TYPES}) if not agents: LOG.warning('Refusing to bind port %(port_id)s due to ' 'no OVN chassis for host: %(host)s', diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py index c409dac33fa..6d04ce5453d 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py @@ -1194,7 +1194,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): fake_port, fake_host, fake_segments) self.mech_driver.bind_port(fake_port_context) neutron_agent.AgentCache().get_agents.assert_called_once_with( - {'host': fake_host}) + {'host': fake_host, + 'agent_type': ovn_const.OVN_CONTROLLER_TYPES}) fake_port_context.set_binding.assert_not_called() def test_bind_port_host_not_found(self): @@ -1224,7 +1225,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): fake_port, fake_host, fake_segments) self.mech_driver.bind_port(fake_port_context) neutron_agent.AgentCache().get_agents.assert_called_once_with( - {'host': fake_host}) + {'host': fake_host, + 'agent_type': ovn_const.OVN_CONTROLLER_TYPES}) fake_port_context.set_binding.assert_called_once_with( fake_segments[0]['id'], portbindings.VIF_TYPE_OVS, @@ -1239,7 +1241,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): fake_port, fake_host, fake_segments) self.mech_driver.bind_port(fake_port_context) neutron_agent.AgentCache().get_agents.assert_called_once_with( - {'host': fake_host}) + {'host': fake_host, + 'agent_type': ovn_const.OVN_CONTROLLER_TYPES}) fake_port_context.set_binding.assert_called_once_with( fake_segments[0]['id'], portbindings.VIF_TYPE_OVS, @@ -1260,7 +1263,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): fake_port, fake_host, fake_segments) self.mech_driver.bind_port(fake_port_context) neutron_agent.AgentCache().get_agents.assert_called_once_with( - {'host': fake_host}) + {'host': fake_host, + 'agent_type': ovn_const.OVN_CONTROLLER_TYPES}) fake_port_context.set_binding.assert_called_once_with( fake_segments[0]['id'], portbindings.VIF_TYPE_OVS,