From 3a1175b88a436eecf00b8f04e5cc9f5cbce3ee06 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Sat, 2 May 2015 23:10:52 -0700 Subject: [PATCH] Check for missing network in _bind_devices _bind_devices was making the assumption that the ports it was operating had local VLAN map entries for their network. This wasn't the case when a network was deleted right before _bind_ports was called because the VLAN was reclaimed. This patch just checks to see if the the network ID has an entry in the map. If not, it skips the port. The port will be handled on the next scan_ports iteration when the agent will discover that the port is no longer defined on the plugin and it will be placed in the DEAD vlan. Change-Id: Ica51d727aceb41848fec0f4edbd16916365941ee Closes-Bug: #1452903 --- neutron/plugins/openvswitch/agent/ovs_neutron_agent.py | 6 +++++- .../plugins/openvswitch/agent/test_ovs_neutron_agent.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py index 90f15d515..7e7d37756 100644 --- a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py @@ -733,7 +733,11 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, def _bind_devices(self, need_binding_ports): for port_detail in need_binding_ports: - lvm = self.local_vlan_map[port_detail['network_id']] + lvm = self.local_vlan_map.get(port_detail['network_id']) + if not lvm: + # network for port was deleted. skip this port since it + # will need to be handled as a DEAD port in the next scan + continue port = port_detail['vif_port'] device = port_detail['device'] # Do not bind a port if it's already bound diff --git a/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py index d20157452..0eeaaa11a 100644 --- a/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py @@ -431,6 +431,9 @@ class TestOvsNeutronAgent(base.BaseTestCase): def test_treat_devices_removed_ignores_missing_port(self): self._mock_treat_devices_removed(False) + def test_bind_port_with_missing_network(self): + self.agent._bind_devices([{'network_id': 'non-existent'}]) + def _test_process_network_ports(self, port_info): with contextlib.nested( mock.patch.object(self.agent.sg_agent, "setup_port_filters"), -- 2.45.2