From a27081636bae4dc8e279b2a0520f7929888c9817 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Mon, 2 Mar 2020 22:08:05 +0100 Subject: [PATCH] Fix _notify_l3_agent_port_update when there is no binding host When _notify_l3_agent_port_update is called, there may be the case that portbindings.HOST_ID key is not in new_port or original_port dict. It is like that e.g. in some unit tests of api extensions. So lets use get() method to get it. The case when host_id is None is already handled properly in this method so that is fine to do. Change-Id: I490506cc6c9b18a3ca12e474f9ee9f8f3712ce7b --- neutron/db/l3_dvrscheduler_db.py | 12 ++++++------ neutron/db/l3_hascheduler_db.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/neutron/db/l3_dvrscheduler_db.py b/neutron/db/l3_dvrscheduler_db.py index af9854d5be7..b8e3e234aaa 100644 --- a/neutron/db/l3_dvrscheduler_db.py +++ b/neutron/db/l3_dvrscheduler_db.py @@ -549,14 +549,14 @@ def _notify_l3_agent_port_update(resource, event, trigger, **kwargs): if new_port and original_port: l3plugin = directory.get_plugin(plugin_constants.L3) context = kwargs['context'] + new_port_host = new_port.get(portbindings.HOST_ID) + original_port_host = original_port.get(portbindings.HOST_ID) is_new_port_binding_changed = ( - new_port[portbindings.HOST_ID] and - new_port[portbindings.HOST_ID] != - original_port[portbindings.HOST_ID]) + new_port_host and + new_port_host != original_port_host) is_bound_port_moved = ( - original_port[portbindings.HOST_ID] and - original_port[portbindings.HOST_ID] != - new_port[portbindings.HOST_ID]) + original_port_host and + original_port_host != new_port_host) fip_router_id = None dest_host = None new_port_profile = new_port.get(portbindings.PROFILE) diff --git a/neutron/db/l3_hascheduler_db.py b/neutron/db/l3_hascheduler_db.py index 864191da091..b7b6d5fe688 100644 --- a/neutron/db/l3_hascheduler_db.py +++ b/neutron/db/l3_hascheduler_db.py @@ -58,7 +58,7 @@ def _notify_l3_agent_ha_port_update(resource, event, trigger, **kwargs): new_port = kwargs.get('port') original_port = kwargs.get('original_port') context = kwargs.get('context') - host = new_port[portbindings.HOST_ID] + host = new_port.get(portbindings.HOST_ID) if new_port and original_port and host: new_device_owner = new_port.get('device_owner', '')