diff options
author | Zuul <zuul@review.opendev.org> | 2022-10-17 14:12:10 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-10-17 14:12:10 +0000 |
commit | a7bc8e16c5d5573147620fbc2fb46977ae1b1704 (patch) | |
tree | c07fa855b5603c47f9d19312b86c86dd5ea81e0a | |
parent | 2adb471f7575ddcd6af146f84f23bb6f916f79b9 (diff) | |
parent | 3e38b1765200b9c385a64f3b1286ccd8eab298fe (diff) | |
download | neutron-a7bc8e16c5d5573147620fbc2fb46977ae1b1704.tar.gz |
Merge "[L3HA] Don't update HA router's ports if router isn't active on agents" into stable/ussuri
-rw-r--r-- | neutron/api/rpc/handlers/l3_rpc.py | 17 | ||||
-rw-r--r-- | neutron/tests/unit/db/test_l3_hamode_db.py | 12 |
2 files changed, 19 insertions, 10 deletions
diff --git a/neutron/api/rpc/handlers/l3_rpc.py b/neutron/api/rpc/handlers/l3_rpc.py index 5ecdb0c0a3..e44a67438a 100644 --- a/neutron/api/rpc/handlers/l3_rpc.py +++ b/neutron/api/rpc/handlers/l3_rpc.py @@ -218,22 +218,21 @@ class L3RpcCallback(object): active_host = ( self.l3plugin.get_active_host_for_ha_router( context, router_id)) - if active_host: - host = active_host - # If there is currently no active router instance (For - # example it's a new router), the host that requested - # the routers (Essentially a random host) will do. The - # port binding will be corrected when an active is - # elected. + if not active_host: + LOG.debug("Router %(router)s is not active on any " + "host. Port %(port)s will not be updated " + "now.", + {'router': router_id, 'port': port['id']}) + return try: LOG.debug("Updating router %(router)s port %(port)s " "binding host %(host)s", {"router": router_id, "port": port['id'], - "host": host}) + "host": active_host}) self.plugin.update_port( context, port['id'], - {'port': {portbindings.HOST_ID: host}}) + {'port': {portbindings.HOST_ID: active_host}}) except exceptions.PortNotFound: LOG.debug("Port %(port)s not found while updating " "agent binding for router %(router)s.", diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index 0c052b7fde..45cebbbb7c 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -1304,9 +1304,19 @@ class L3HAModeDbTestCase(L3HATestFramework): self.plugin.list_active_sync_routers_on_active_l3_agent( self.admin_ctx, self.agent1['host'], [router['id']]))[0] - # ensure_host_set_on_ports binds an unbound port callback = l3_rpc.L3RpcCallback() callback._l3plugin = self.plugin + # First ensure that port is not bound if router is not active on any + # agent + callback._ensure_host_set_on_ports( + self.admin_ctx, self.agent1['host'], [router]) + port = self._get_first_interface(router['id']) + self.assertEqual('', port[portbindings.HOST_ID]) + + # Now update router to be active on agent1 + # and ensure_host_set_on_ports binds an unbound port + self.plugin.update_routers_states( + self.admin_ctx, {router['id']: 'active'}, self.agent1['host']) callback._ensure_host_set_on_ports( self.admin_ctx, self.agent1['host'], [router]) port = self._get_first_interface(router['id']) |