[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

Related-Bug: #1958501
Change-Id: If065204d7521c480656a22fb078bbe6273b5fc70
This commit is contained in:
Slawek Kaplonski 2022-08-17 14:00:33 +02:00
parent dcf38781a3
commit eda45de839
2 changed files with 13 additions and 6 deletions

View File

@ -998,7 +998,9 @@ class OVNMechanismDriver(api.MechanismDriver):
LOG.error('Validation of binding profile unexpectedly failed '
'while attempting to bind port %s', port['id'])
raise e
agents = n_agent.AgentCache().get_agents({'host': bind_host})
agents = n_agent.AgentCache().get_agents(
{'host': bind_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',

View File

@ -1240,7 +1240,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):
@ -1274,7 +1275,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,
@ -1291,7 +1293,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,
@ -1321,7 +1324,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_smartnic_dpu})
{'host': fake_smartnic_dpu,
'agent_type': ovn_const.OVN_CONTROLLER_TYPES})
fake_port_context.set_binding.assert_called_once_with(
fake_segments[0]['id'],
portbindings.VIF_TYPE_OVS,
@ -1342,7 +1346,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,