Skip to content

Commit 3867f3c

Browse files
slawqogotostack
authored andcommitted
[L3HA] Don't update HA router's ports if router isn't active on agents
In case when HA router isn't active on any L3 agent, _ensure_host_set_on_port method shouldn't try to update port's host to the host from which there was an rpc message sent, as this can be host on which router is in the "standby" mode. This method should only update port's host to the router's "active_host" if there is such active_host found already. Depends-On: https://review.opendev.org/c/openstack/requirements/+/841489 Closes-Bug: #1973162 Closes-Bug: #1942190 Change-Id: Ib3945d294601b35f9b268c25841cd284b52c4ca3 (cherry picked from commit cd8bf18)
1 parent ad778a6 commit 3867f3c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

neutron/api/rpc/handlers/l3_rpc.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,21 @@ def _ensure_host_set_on_port(self, context, host, port, router_id=None,
224224
active_host = (
225225
self.l3plugin.get_active_host_for_ha_router(
226226
context, router_id))
227-
if active_host:
228-
host = active_host
229-
# If there is currently no active router instance (For
230-
# example it's a new router), the host that requested
231-
# the routers (Essentially a random host) will do. The
232-
# port binding will be corrected when an active is
233-
# elected.
227+
if not active_host:
228+
LOG.debug("Router %(router)s is not active on any "
229+
"host. Port %(port)s will not be updated "
230+
"now.",
231+
{'router': router_id, 'port': port['id']})
232+
return
234233
try:
235234
LOG.debug("Updating router %(router)s port %(port)s "
236235
"binding host %(host)s",
237236
{"router": router_id, "port": port['id'],
238-
"host": host})
237+
"host": active_host})
239238
self.plugin.update_port(
240239
context,
241240
port['id'],
242-
{'port': {portbindings.HOST_ID: host}})
241+
{'port': {portbindings.HOST_ID: active_host}})
243242
except exceptions.PortNotFound:
244243
LOG.debug("Port %(port)s not found while updating "
245244
"agent binding for router %(router)s.",

neutron/tests/unit/db/test_l3_hamode_db.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,9 +1246,19 @@ def test_ensure_host_set_on_ports_binds_correctly(self):
12461246
self.plugin.list_active_sync_routers_on_active_l3_agent(
12471247
self.admin_ctx, self.agent1['host'], [router['id']]))[0]
12481248

1249-
# ensure_host_set_on_ports binds an unbound port
12501249
callback = l3_rpc.L3RpcCallback()
12511250
callback._l3plugin = self.plugin
1251+
# First ensure that port is not bound if router is not active on any
1252+
# agent
1253+
callback._ensure_host_set_on_ports(
1254+
self.admin_ctx, self.agent1['host'], [router])
1255+
port = self._get_first_interface(router['id'])
1256+
self.assertEqual('', port[portbindings.HOST_ID])
1257+
1258+
# Now update router to be active on agent1
1259+
# and ensure_host_set_on_ports binds an unbound port
1260+
self.plugin.update_routers_states(
1261+
self.admin_ctx, {router['id']: 'active'}, self.agent1['host'])
12521262
callback._ensure_host_set_on_ports(
12531263
self.admin_ctx, self.agent1['host'], [router])
12541264
port = self._get_first_interface(router['id'])

0 commit comments

Comments
 (0)